Search in sources :

Example 1 with InventoryCloseEvent

use of org.bukkit.event.inventory.InventoryCloseEvent in project Denizen-For-Bukkit by DenizenScript.

the class InventoryMenu method closeMenu.

public void closeMenu(Player player) {
    if (getInventory().getViewers().contains(player)) {
        InventoryCloseEvent event = new InventoryCloseEvent(player.getOpenInventory());
        Bukkit.getPluginManager().callEvent(event);
        player.closeInventory();
    }
}
Also used : InventoryCloseEvent(org.bukkit.event.inventory.InventoryCloseEvent)

Example 2 with InventoryCloseEvent

use of org.bukkit.event.inventory.InventoryCloseEvent 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)

Example 3 with InventoryCloseEvent

use of org.bukkit.event.inventory.InventoryCloseEvent in project Karus-Commons by Pante.

the class ResettableComponentTest method reset.

@ParameterizedTest
@CsvSource({ "true, 1", "false, 0" })
void reset(boolean reset, int times) {
    Window window = mock(Window.class);
    InventoryCloseEvent event = mock(InventoryCloseEvent.class);
    component.reset(reset);
    component.reset(window, event);
    assertEquals(reset, component.reset());
    verify(component, times(times)).onReset(window, event);
}
Also used : Window(com.karuslabs.commons.graphics.windows.Window) InventoryCloseEvent(org.bukkit.event.inventory.InventoryCloseEvent) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with InventoryCloseEvent

use of org.bukkit.event.inventory.InventoryCloseEvent in project Karus-Commons by Pante.

the class CheckBoxTest method reset.

@ParameterizedTest
@CsvSource({ "true, 1, false", "false, 0, true" })
void reset(boolean reset, int times, boolean expected) {
    checkbox.checked = true;
    checkbox.reset(reset);
    Window window = mock(Window.class);
    InventoryCloseEvent event = mock(InventoryCloseEvent.class);
    checkbox.reset(window, event);
    verify(event, times(times)).getInventory();
    assertEquals(expected, checkbox.checked);
}
Also used : Window(com.karuslabs.commons.graphics.windows.Window) InventoryCloseEvent(org.bukkit.event.inventory.InventoryCloseEvent) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with InventoryCloseEvent

use of org.bukkit.event.inventory.InventoryCloseEvent in project Karus-Commons by Pante.

the class CyclicButtonTest method reset.

@ParameterizedTest
@CsvSource({ "true, 1, 0", "false, 0, 3" })
void reset(boolean reset, int times, int index) {
    button.reset(reset);
    button.index = 3;
    InventoryCloseEvent event = mock(InventoryCloseEvent.class);
    button.reset(mock(Window.class), event);
    verify(event, times(times)).getInventory();
    assertEquals(index, button.index());
}
Also used : Window(com.karuslabs.commons.graphics.windows.Window) InventoryCloseEvent(org.bukkit.event.inventory.InventoryCloseEvent) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

InventoryCloseEvent (org.bukkit.event.inventory.InventoryCloseEvent)6 Window (com.karuslabs.commons.graphics.windows.Window)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 CsvSource (org.junit.jupiter.params.provider.CsvSource)3 InventoryClickType (be.pyrrh4.core.gui.GUI.InventoryClickType)1 Player (org.bukkit.entity.Player)1 InventoryClickEvent (org.bukkit.event.inventory.InventoryClickEvent)1 Inventory (org.bukkit.inventory.Inventory)1 ItemStack (org.bukkit.inventory.ItemStack)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1