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();
}
}
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;
}
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);
}
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);
}
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());
}
Aggregations