Java Code Examples for org.bukkit.block.Chest#getInventory()
The following examples show how to use
org.bukkit.block.Chest#getInventory() .
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: BukkitWorld.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
/** * Gets the single block inventory for a potentially double chest. * Handles people who have an old version of Bukkit. * This should be replaced with {@link org.bukkit.block.Chest#getBlockInventory()} * in a few months (now = March 2012) // note from future dev - lol * * @param chest The chest to get a single block inventory for * @return The chest's inventory */ private Inventory getBlockInventory(Chest chest) { try { return chest.getBlockInventory(); } catch (Throwable t) { if (chest.getInventory() instanceof DoubleChestInventory) { DoubleChestInventory inven = (DoubleChestInventory) chest.getInventory(); if (inven.getLeftSide().getHolder().equals(chest)) { return inven.getLeftSide(); } else if (inven.getRightSide().getHolder().equals(chest)) { return inven.getRightSide(); } else { return inven; } } else { return chest.getInventory(); } } }
Example 2
Source File: IslandGenerator.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
/** * Fill the {@link Inventory} of the given chest {@link Location} with the starter and {@link Perk} based items. * @param chestLocation Location of the chest block. * @param perk Perk containing extra perk-based items to add. * @return True if the chest is found and filled, false otherwise. */ public boolean setChest(@Nullable Location chestLocation, @NotNull Perk perk) { if (chestLocation == null || chestLocation.getWorld() == null) { return false; } final Block block = chestLocation.getWorld().getBlockAt(chestLocation); if (block.getType() == Material.CHEST) { final Chest chest = (Chest) block.getState(); final Inventory inventory = chest.getInventory(); inventory.addItem(Settings.island_chestItems); if (Settings.island_addExtraItems) { inventory.addItem(ItemStackUtil.createItemArray(perk.getExtraItems())); } return true; } return false; }
Example 3
Source File: TimebombListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
private void spawnChest(){ spawned = true; block1 = loc.getBlock(); loc.add(-1, 0, 0); block2 = loc.getBlock(); block1.setType(Material.CHEST); block2.setType(Material.CHEST); Chest chest1 = (Chest) block1.getState(); Chest chest2 = (Chest) block2.getState(); String chestName = Lang.SCENARIO_TIMEBOMB_CHEST.replace("%player%", name); VersionUtils.getVersionUtils().setChestName(chest1, chestName); VersionUtils.getVersionUtils().setChestName(chest2, chestName); // Make double chest for 1.13 and up VersionUtils.getVersionUtils().setChestSide(chest1, false); VersionUtils.getVersionUtils().setChestSide(chest2, true); Inventory inv = chest1.getInventory(); for (ItemStack drop : drops){ inv.addItem(drop); } loc.add(1,-1,.5); armorStand = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND); armorStand.setCustomNameVisible(true); armorStand.setGravity(false); armorStand.setVisible(false); armorStand.setCustomName(""); }
Example 4
Source File: CVInventory.java From Civs with GNU General Public License v3.0 | 5 votes |
public void setInventory() { Block block = this.location.getBlock(); if (block.getType() != Material.CHEST) { this.valid = false; return; } try { Chest chest = (Chest) block.getState(); this.inventory = chest.getInventory(); this.size = this.inventory.getSize(); } catch (Exception e) { this.valid = false; } }