@EventHandler public void on(InventoryCloseEvent event) { if (!(event.getPlayer() instanceof Player)) { return; } Player player = (Player) event.getPlayer(); if (!this.nameSwitch && this.hasOpen(player)) { this.components .keySet() .forEach( component -> { try { component.onClose(player); } catch (Throwable t) { getHolder() .getLogger() .log(Level.WARNING, "An exception was caught whilst handling a component", t); } }); this.onClose(player); Menu.closeMenu(player, this); } }
public static Position toPosition(Menu menu, int slot) { return new Position(slot % menu.getWidth(), slot / menu.getWidth()); }
public static int toSlot(Menu menu, int x, int y) { return y * menu.getWidth() + x; }