Java Code Examples for org.bukkit.inventory.Inventory#clear()
The following examples show how to use
org.bukkit.inventory.Inventory#clear() .
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 |
/** * Draw the elements in the inventory. This can be used to manually refresh the gui. * @param who For who to draw the GUI */ public void draw(HumanEntity who) { Inventory inventory = getInventory(who); if (inventory == null) { build(); if (slots.length != inventoryType.getDefaultSize()) { inventory = plugin.getServer().createInventory(new Holder(this), slots.length, replaceVars(title)); } else { inventory = plugin.getServer().createInventory(new Holder(this), inventoryType, replaceVars(title)); } inventories.put(who != null ? who.getUniqueId() : null, inventory); } else { inventory.clear(); } for (int i = 0; i < inventory.getSize(); i++) { GuiElement element = getElement(i); if (element == null) { element = getFiller(); } if (element != null) { inventory.setItem(i, element.getItem(who, i)); } } }
Example 2
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 3
Source File: BukkitWorld.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Override public boolean clearContainerBlockContents(Vector pt) { Block block = getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (block == null) { return false; } BlockState state = block.getState(); if (!(state instanceof org.bukkit.inventory.InventoryHolder)) { return false; } org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state; Inventory inven = chest.getInventory(); if (chest instanceof Chest) { inven = getBlockInventory((Chest) chest); } inven.clear(); return true; }
Example 4
Source File: ChestManager.java From SkyWarsReloaded with GNU General Public License v3.0 | 6 votes |
public void fillCrate(Inventory inventory, int max) { if (inventory != null) { inventory.clear(); int added = 0; Collections.shuffle(randomLoc); for (int chance: crateItemList.keySet()) { for (ItemStack item : crateItemList.get(chance)) { if (item != null && !item.getType().equals(Material.AIR)) { if (random.nextInt(100) + 1 <= chance) { inventory.setItem(randomLoc.get(added), item); added++; if (added >= inventory.getSize() - 1 || added >= max) { break; } } } } } } }
Example 5
Source File: ItemKeep.java From CardinalPGM with MIT License | 6 votes |
@EventHandler public void onPlayerDeath(CardinalDeathEvent event) { Player player = event.getPlayer(); Inventory inventory = player.getInventory(); Map<Integer, ItemStack> itemsToKeep = new HashMap<>(); if (inventory.getContents() != null) { for (int i = 0; i < inventory.getSize(); i++) { if (inventory.getItem(i) != null) { ItemStack item = inventory.getItem(i); if (item.getType().equals(type) && item.getDurability() == damageValue) { itemsToKeep.put(i, item); inventory.clear(i); } } } } items.put(player, itemsToKeep); }
Example 6
Source File: SubCommand_SilentEmpty.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
@Override public void onCommand( @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) { if (cmdArg.length < 4) { Util.debugLog("Exception on command, cancel."); return; } final Shop shop = plugin .getShopManager() .getShop( new Location( plugin.getServer().getWorld(cmdArg[0]), Integer.parseInt(cmdArg[1]), Integer.parseInt(cmdArg[2]), Integer.parseInt(cmdArg[3]))); if (!(shop instanceof ContainerShop)) { MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender)); return; } final ContainerShop cs = (ContainerShop) shop; final Inventory inventory = cs.getInventory(); if (inventory == null) { Util.debugLog("Inventory is empty! " + cs.toString()); return; } inventory.clear(); MsgUtil.sendControlPanelInfo(sender, shop); MsgUtil.sendMessage(sender, MsgUtil.getMessage("empty-success", sender)); }
Example 7
Source File: InventoryGui.java From InventoryGui with MIT License | 5 votes |
private void destroy(boolean closeInventories) { if (closeInventories) { close(); } for (Inventory inventory : inventories.values()) { inventory.clear(); } inventories.clear(); unregisterListeners(); removeFromMap(); }
Example 8
Source File: HumanEntityCache.java From IF with The Unlicense | 5 votes |
/** * Stores this player's inventory in the cache. If the player was already stored, their cache will be overwritten. * Clears the player's inventory afterwards. * * @param humanEntity the human entity to keep in the cache */ public void storeAndClear(@NotNull HumanEntity humanEntity) { store(humanEntity); Inventory inventory = humanEntity.getInventory(); for (int i = 0; i < 36; i++) { inventory.clear(i); } }
Example 9
Source File: Recipes.java From ProRecipes with GNU General Public License v2.0 | 5 votes |
public void updateInventory(Player p, Inventory i){ ItemStack[] contents = i.getContents(); i.clear(); //p.closeInventory(); i.setContents(contents); //p.openInventory(i); }
Example 10
Source File: ChestManager.java From SkyWarsReloaded with GNU General Public License v3.0 | 5 votes |
public void populateChest(Object chest, Vote cVote, boolean center) { if (cVote == Vote.CHESTOP) { if (center) { fillChest(chest, opCenterChestItemList); } else { fillChest(chest, opChestItemList); } } else if (cVote == Vote.CHESTBASIC) { if (center) { fillChest(chest, basicCenterChestItemList); } else { fillChest(chest, basicChestItemList); } } else if (cVote == Vote.CHESTNORMAL) { if (center) { fillChest(chest, centerChestItemList); } else { fillChest(chest, chestItemList); } } else { Inventory inventory = null; if (chest instanceof DoubleChest) { inventory = ((DoubleChest) chest).getInventory(); } else if (chest instanceof Chest) { inventory = ((Chest)chest).getInventory(); } if (inventory != null) { inventory.clear(); } } }
Example 11
Source File: ChestManager.java From SkyWarsReloaded with GNU General Public License v3.0 | 5 votes |
private void fillChest(Object chest, Map<Integer, Inventory> fill) { Inventory inventory = null; if (chest instanceof Chest) { inventory = ((Chest) chest).getInventory(); } else if (chest instanceof DoubleChest) { inventory = ((DoubleChest) chest).getInventory(); } if (inventory != null) { inventory.clear(); int added = 0; Collections.shuffle(randomLoc); Collections.shuffle(randomDLoc); for (int chance: fill.keySet()) { for (ItemStack item: fill.get(chance)) { if (item != null && !item.getType().equals(Material.AIR)) { if (chest instanceof Chest) { if (random.nextInt(100) + 1 <= chance) { inventory.setItem(randomLoc.get(added), item); added++; if (added >= inventory.getSize() - 1 || added >= SkyWarsReloaded.getCfg().getMaxChest()) { break; } } } if (chest instanceof DoubleChest) { if (random.nextInt(100) + 1 <= chance) { inventory.setItem(randomDLoc.get(added), item); added++; if (added >= inventory.getSize() - 1 || added >= SkyWarsReloaded.getCfg().getMaxDoubleChest()) { break; } } } } } } } }
Example 12
Source File: ContainerVariable.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
public void toInventoryItems(Inventory inventory) { inventory.clear(); NBTTagCompound data = data(); if (data.hasKey(_key)) { NBTTagList items = data.getList(_key); int l = Math.min(items.size(), Math.min(inventory.getSize(), size)); for (int i = 0; i < l; ++i) { NBTTagCompound itemNBT = (NBTTagCompound) items.get(i); inventory.setItem(itemNBT.getByte("Slot"), NBTUtils.itemStackFromNBTData(itemNBT)); } } }
Example 13
Source File: GameOption.java From SkyWarsReloaded with GNU General Public License v3.0 | 4 votes |
void createMenu(String key, String name) { this.key = key; ArrayList<Inventory> invs = new ArrayList<>(); Inventory inv = Bukkit.createInventory(null, 36, new Messaging.MessageFormatter().format(name)); inv.clear(); inv.setItem(9, SkyWarsReloaded.getIM().getItem(itemList.get(0))); inv.setItem(11, SkyWarsReloaded.getIM().getItem(itemList.get(1))); inv.setItem(13, SkyWarsReloaded.getIM().getItem(itemList.get(2))); inv.setItem(15, SkyWarsReloaded.getIM().getItem(itemList.get(3))); if (!(this instanceof ChestOption) || (this instanceof ChestOption && gameMap.allowScanvenger())) { inv.setItem(17, SkyWarsReloaded.getIM().getItem(itemList.get(4))); } invs.add(inv); SkyWarsReloaded.getIC().create(key, invs, event -> { String itemName = event.getName(); if (itemName.equalsIgnoreCase(SkyWarsReloaded.getNMS().getItemName(SkyWarsReloaded.getIM().getItem("exitMenuItem")))) { new VotingMenu(event.getPlayer()); return; } final GameMap gMap = MatchManager.get().getPlayerMap(event.getPlayer()); if (!gMap.equals(gameMap)) { return; } if (gameMap.getMatchState() == MatchState.WAITINGSTART) { int slot = event.getSlot(); if (slot == 9) { doSlotNine(event.getPlayer()); } else if (slot == 11) { doSlotEleven(event.getPlayer()); } else if (slot == 13) { doSlotThriteen(event.getPlayer()); } else if (slot == 15) { doSlotFifteen(event.getPlayer()); } else if (slot == 17) { if (!(this instanceof ChestOption) || (this instanceof ChestOption && gameMap.allowScanvenger())) { doSlotSeventeen(event.getPlayer()); } } } }); iconMenu = SkyWarsReloaded.getIC().getMenu(key); }
Example 14
Source File: SchematicsPanel.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Handles when the schematics panel is actually clicked * @param event */ @EventHandler(priority = EventPriority.LOWEST) public void onInventoryClick(InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); // The player that // clicked the item Inventory inventory = event.getInventory(); // The inventory that was clicked in if (inventory.getName() == null) { return; } int slot = event.getRawSlot(); // Check this is the right panel if (!inventory.getName().equals(plugin.myLocale(player.getUniqueId()).schematicsTitle)) { return; } if (slot == -999) { player.closeInventory(); inventory.clear(); schematicItems.remove(player.getUniqueId()); event.setCancelled(true); return; } if (event.getClick().equals(ClickType.SHIFT_RIGHT)) { event.setCancelled(true); player.closeInventory(); inventory.clear(); schematicItems.remove(player.getUniqueId()); player.updateInventory(); return; } // Get the list of items for this player List<SPItem> thisPanel = schematicItems.get(player.getUniqueId()); if (thisPanel == null) { player.closeInventory(); inventory.clear(); schematicItems.remove(player.getUniqueId()); event.setCancelled(true); return; } if (slot >= 0 && slot < thisPanel.size()) { event.setCancelled(true); // plugin.getLogger().info("DEBUG: slot is " + slot); player.closeInventory(); // Closes the inventory inventory.clear(); // Get the item clicked SPItem item = thisPanel.get(slot); // Check cost if (item.getCost() > 0) { if (Settings.useEconomy && VaultHelper.setupEconomy() && !VaultHelper.econ.has(player, item.getCost())) { // Too expensive Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).minishopYouCannotAfford.replace("[description]", item.getName())); } else { // Do something if (Settings.useEconomy && VaultHelper.setupEconomy()) { VaultHelper.econ.withdrawPlayer(player, item.getCost()); } Util.runCommand(player, Settings.ISLANDCOMMAND + " make " + item.getHeading()); } } else { Util.runCommand(player, Settings.ISLANDCOMMAND + " make " + item.getHeading()); } schematicItems.remove(player.getUniqueId()); thisPanel.clear(); } return; }
Example 15
Source File: BiomesPanel.java From askyblock with GNU General Public License v2.0 | 4 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onInventoryClick(InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); // The player that // clicked the item UUID playerUUID = player.getUniqueId(); Inventory inventory = event.getInventory(); // The inventory that was // clicked in int slot = event.getRawSlot(); // Check this is the right panel if (inventory.getName() == null || !inventory.getName().equals(plugin.myLocale().biomePanelTitle)) { return; } if (slot == -999) { inventory.clear(); player.closeInventory(); event.setCancelled(true); return; } if (event.getClick().equals(ClickType.SHIFT_RIGHT)) { event.setCancelled(true); inventory.clear(); player.closeInventory(); player.updateInventory(); return; } // Get the list of items for this player List<BiomeItem> thisPanel = biomeItems.get(player.getUniqueId()); if (thisPanel == null) { inventory.clear(); player.closeInventory(); event.setCancelled(true); return; } if (slot >= 0 && slot < thisPanel.size()) { event.setCancelled(true); // plugin.getLogger().info("DEBUG: slot is " + slot); // Do something // Check this player has an island Island island = plugin.getGrid().getIsland(playerUUID); if (island == null) { Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland); return; } // Check ownership if (!island.getOwner().equals(playerUUID)) { Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).levelerrornotYourIsland); return; } if (!plugin.getGrid().playerIsOnIsland(player)) { Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).challengeserrorNotOnIsland); return; } Biome biome = thisPanel.get(slot).getBiome(); if (biome != null) { event.setCancelled(true); if (Settings.useEconomy) { // Check cost double cost = thisPanel.get(slot).getPrice(); if (cost > 0D) { if (!VaultHelper.econ.has(player, Settings.worldName, cost)) { Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).minishopYouCannotAfford.replace("[description]", VaultHelper.econ.format(cost))); return; } else { VaultHelper.econ.withdrawPlayer(player, Settings.worldName, cost); Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).biomeYouBought.replace("[cost]", VaultHelper.econ.format(cost))); } } } } inventory.clear(); player.closeInventory(); // Closes the inventory // Actually set the biome Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).biomePleaseWait); new SetBiome(plugin, island, biome, player); } return; }