Search in sources :

Example 1 with InventoryData

use of com.bgsoftware.wildchests.api.objects.data.InventoryData in project WildChests by BG-Software-LLC.

the class InventoryListener method handleUpgrade.

private void handleUpgrade(Player player, boolean confirm) {
    try {
        Chest chest = WChest.viewers.get(player.getUniqueId());
        ChestData chestData = chest.getData();
        InventoryData inventoryData = buyNewPage.get(player.getUniqueId());
        int pageIndex = chest.getPagesAmount() - 1;
        if (!chestData.getPagesData().containsKey(pageIndex + 2)) {
            Locale.EXPAND_FAILED.send(player);
        } else {
            if (confirm) {
                if (plugin.getProviders().withdrawPlayer(player, inventoryData.getPrice())) {
                    Locale.EXPAND_PURCHASED.send(player);
                    chest.setPage(++pageIndex, chestData.getDefaultSize(), inventoryData.getTitle());
                } else {
                    Locale.EXPAND_FAILED.send(player);
                }
            } else {
                Locale.EXPAND_FAILED.send(player);
            }
        }
        final int PAGE = pageIndex;
        Executor.sync(() -> chest.openPage(player, PAGE));
    } catch (Exception ex) {
        Locale.EXPAND_FAILED_CHEST_BROKEN.send(player);
    }
    buyNewPage.remove(player.getUniqueId());
}
Also used : WChest(com.bgsoftware.wildchests.objects.chests.WChest) Chest(com.bgsoftware.wildchests.api.objects.chests.Chest) ChestData(com.bgsoftware.wildchests.api.objects.data.ChestData) InventoryData(com.bgsoftware.wildchests.api.objects.data.InventoryData)

Example 2 with InventoryData

use of com.bgsoftware.wildchests.api.objects.data.InventoryData in project WildChests by BG-Software-LLC.

the class WChest method onInteract.

@Override
public boolean onInteract(InventoryClickEvent event) {
    if (event.getSlotType() != InventoryType.SlotType.OUTSIDE)
        return false;
    ChestData chestData = getData();
    int index = getPageIndex(event.getWhoClicked().getOpenInventory().getTopInventory());
    if (event.getClick() == ClickType.LEFT) {
        // Making sure he's not in the first page
        if (index != 0) {
            // movingBetweenPages.add(event.getWhoClicked().getUniqueId());
            openPage((Player) event.getWhoClicked(), index - 1);
        // movingBetweenPages.remove(event.getWhoClicked().getUniqueId());
        }
    } else if (event.getClick() == ClickType.RIGHT) {
        // Making sure it's not the last page
        if (index + 1 < getPagesAmount()) {
            // movingBetweenPages.add(event.getWhoClicked().getUniqueId());
            openPage((Player) event.getWhoClicked(), index + 1);
        } else // Making sure next page is purchasble
        if (chestData.getPagesData().containsKey(++index + 1)) {
            InventoryData inventoryData = chestData.getPagesData().get(index + 1);
            InventoryListener.buyNewPage.put(event.getWhoClicked().getUniqueId(), inventoryData);
            if (plugin.getSettings().confirmGUI) {
                event.getWhoClicked().openInventory(guiConfirm);
            } else {
                Locale.EXPAND_CHEST.send(event.getWhoClicked(), inventoryData.getPrice());
                event.getWhoClicked().closeInventory();
            }
        }
    }
    return true;
}
Also used : ChestData(com.bgsoftware.wildchests.api.objects.data.ChestData) Player(org.bukkit.entity.Player) InventoryData(com.bgsoftware.wildchests.api.objects.data.InventoryData)

Aggregations

ChestData (com.bgsoftware.wildchests.api.objects.data.ChestData)2 InventoryData (com.bgsoftware.wildchests.api.objects.data.InventoryData)2 Chest (com.bgsoftware.wildchests.api.objects.chests.Chest)1 WChest (com.bgsoftware.wildchests.objects.chests.WChest)1 Player (org.bukkit.entity.Player)1