Java Code Examples for org.bukkit.inventory.Inventory#getViewers()
The following examples show how to use
org.bukkit.inventory.Inventory#getViewers() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InventoryGui.java From InventoryGui with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onInventoryClose(InventoryCloseEvent event) { Inventory inventory = getInventory(event.getPlayer()); if (event.getInventory().equals(inventory)) { // go back. that checks if the player is in gui and has history if (gui.equals(getOpen(event.getPlayer()))) { if (closeAction == null || closeAction.onClose(new Close(event.getPlayer(), gui, event))) { goBack(event.getPlayer()); } else { clearHistory(event.getPlayer()); } } if (inventories.size() <= 1) { destroy(false); } else { inventory.clear(); for (HumanEntity viewer : inventory.getViewers()) { if (viewer != event.getPlayer()) { viewer.closeInventory(); } } inventories.remove(event.getPlayer().getUniqueId()); } } }
Example 2
Source File: InventoryGui.java From InventoryGui with MIT License | 5 votes |
/** * Close the GUI for everyone viewing it * @param clearHistory Whether or not to close the GUI completely (by clearing the history) */ public void close(boolean clearHistory) { for (Inventory inventory : inventories.values()) { for (HumanEntity viewer : new ArrayList<>(inventory.getViewers())) { if (clearHistory) { clearHistory(viewer); } viewer.closeInventory(); } } }
Example 3
Source File: InventoryGui.java From InventoryGui with MIT License | 5 votes |
/** * Play a click sound e.g. when an element acts as a button */ public void playClickSound() { if (isSilent()) return; for (Inventory inventory : inventories.values()) { for (HumanEntity humanEntity : inventory.getViewers()) { if (humanEntity instanceof Player) { ((Player) humanEntity).playSound(humanEntity.getEyeLocation(), CLICK_SOUND, 1, 1); } } } }