Search in sources :

Example 1 with InventoryClickType

use of be.pyrrh4.core.gui.GUI.InventoryClickType in project PyrCore by PYRRH4.

the class MultipleGUI method createNewPage.

// Create new page
public GUI createNewPage() {
    final int pageNumber = pages.size() + 1;
    final GUI page = new GUI(plugin, name + (pageNumber == 1 ? "" : " - p" + pageNumber), size, addItemMaxSlot, allowBottomInventoryClick, false, duplicateTolerance) {

        @Override
        public void preload() {
        }

        @Override
        public void onClick(InventoryClickEvent event, Player player, InventoryClickType clickType, ItemStack clickedStack, ItemData clickedData, ItemStack cursorStack, ItemData cursorData) {
            // Page selectors
            if (clickedData != null && clickedData.getId().equals(MultipleGUI.this.itemPreviousPage.getId())) {
                GUI page = getPage(pageNumber - 1);
                if (page != null) {
                    page.open(player, isWatcher(player));
                }
            } else if (clickedData != null && clickedData.getId().equals(MultipleGUI.this.itemNextPage.getId())) {
                GUI page = getPage(pageNumber + 1);
                if (page != null) {
                    page.open(player, isWatcher(player));
                }
            } else // Other
            {
                MultipleGUI.this.onClick(event, this, pageNumber, player, clickType, clickedStack, clickedData, cursorStack, cursorData);
            }
        }

        @Override
        protected void onClose(InventoryCloseEvent event, final Player player) {
            MultipleGUI.this.onClose(event, this, pageNumber, player);
            // unregister
            if (unregisterOnClose) {
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        for (GUI page : getPages()) {
                            if (!page.getTotalViewers().isEmpty()) {
                                return;
                            }
                        }
                        MultipleGUI.this.unregister(false);
                    }
                }.runTaskLater(plugin, 20L);
            }
        }

        @Override
        protected void onCloseDisable(Inventory inventory, Player player) {
            MultipleGUI.this.onCloseDisable(inventory, this, pageNumber, player);
        }
    };
    pages.add(page);
    preload(page, pageNumber);
    updatePageSelectors();
    return page;
}
Also used : InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) InventoryClickType(be.pyrrh4.core.gui.GUI.InventoryClickType) Player(org.bukkit.entity.Player) InventoryCloseEvent(org.bukkit.event.inventory.InventoryCloseEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory)

Aggregations

InventoryClickType (be.pyrrh4.core.gui.GUI.InventoryClickType)1 Player (org.bukkit.entity.Player)1 InventoryClickEvent (org.bukkit.event.inventory.InventoryClickEvent)1 InventoryCloseEvent (org.bukkit.event.inventory.InventoryCloseEvent)1 Inventory (org.bukkit.inventory.Inventory)1 ItemStack (org.bukkit.inventory.ItemStack)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1