org.bukkit.block.Hopper Java Examples
The following examples show how to use
org.bukkit.block.Hopper.
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: WarRegen.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static void destroyThisBlock(Block blk, Town town) { WarRegen.saveBlock(blk, town.getName(), false); switch (blk.getType()) { case TRAPPED_CHEST: ((Chest)blk.getState()).getBlockInventory().clear(); break; case CHEST: ((Chest)blk.getState()).getBlockInventory().clear(); break; case DISPENSER: ((Dispenser)blk.getState()).getInventory().clear(); break; case BURNING_FURNACE: case FURNACE: ((Furnace)blk.getState()).getInventory().clear(); break; case DROPPER: ((Dropper)blk.getState()).getInventory().clear(); break; case HOPPER: ((Hopper)blk.getState()).getInventory().clear(); break; default: break; } ItemManager.setTypeId(blk, CivData.AIR); ItemManager.setData(blk, 0x0, true); }
Example #2
Source File: Island.java From askyblock with GNU General Public License v2.0 | 5 votes |
/** * @return number of hoppers on the island */ public int getHopperCount() { tileEntityCount.clear(); int result = 0; for (int x = getMinProtectedX() /16; x <= (getMinProtectedX() + getProtectionSize() - 1)/16; x++) { for (int z = getMinProtectedZ() /16; z <= (getMinProtectedZ() + getProtectionSize() - 1)/16; z++) { for (BlockState holder : world.getChunkAt(x, z).getTileEntities()) { if (holder instanceof Hopper && onIsland(holder.getLocation())) { result++; } } } } return result; }
Example #3
Source File: WarRegen.java From civcraft with GNU General Public License v2.0 | 4 votes |
private static String blockToString(Block blk, boolean save_as_air) { if (save_as_air) { return blockAsAir(blk); } else { String str = blockBasicString(blk); Inventory inv = null; switch (blk.getType()) { case TRAPPED_CHEST: case CHEST: inv = ((Chest)blk.getState()).getBlockInventory(); str += blockInventoryString(inv); break; case DISPENSER: inv = ((Dispenser)blk.getState()).getInventory(); str += blockInventoryString(inv); break; case BURNING_FURNACE: case FURNACE: inv = ((Furnace)blk.getState()).getInventory(); str += blockInventoryString(inv); break; case DROPPER: inv = ((Dropper)blk.getState()).getInventory(); str += blockInventoryString(inv); break; case HOPPER: inv = ((Hopper)blk.getState()).getInventory(); str += blockInventoryString(inv); break; case SIGN: case SIGN_POST: case WALL_SIGN: Sign sign = (Sign)blk.getState(); str += blockSignString(sign); break; default: break; } return str; } }
Example #4
Source File: WarRegen.java From civcraft with GNU General Public License v2.0 | 4 votes |
private static void restoreBlockFromString(String line) { String[] split = line.split(":"); int type = Integer.valueOf(split[0]); byte data = Byte.valueOf(split[1]); int x = Integer.valueOf(split[2]); int y = Integer.valueOf(split[3]); int z = Integer.valueOf(split[4]); String world = split[5]; Block block = BukkitObjects.getWorld(world).getBlockAt(x,y,z); ItemManager.setTypeId(block, type); ItemManager.setData(block, data, false); // End of basic block info, try to get more now. Inventory inv = null; switch (block.getType()) { case TRAPPED_CHEST: inv = ((Chest)block.getState()).getBlockInventory(); InventorySerializer.StringToInventory(inv, split[6]); break; case CHEST: inv = ((Chest)block.getState()).getBlockInventory(); InventorySerializer.StringToInventory(inv, split[6]); break; case DISPENSER: inv = ((Dispenser)block.getState()).getInventory(); InventorySerializer.StringToInventory(inv, split[6]); break; case BURNING_FURNACE: case FURNACE: inv = ((Furnace)block.getState()).getInventory(); InventorySerializer.StringToInventory(inv, split[6]); break; case DROPPER: inv = ((Dropper)block.getState()).getInventory(); InventorySerializer.StringToInventory(inv, split[6]); break; case HOPPER: inv = ((Hopper)block.getState()).getInventory(); InventorySerializer.StringToInventory(inv, split[6]); break; case SIGN: case SIGN_POST: case WALL_SIGN: Sign sign = (Sign)block.getState(); String[] messages = split[6].split(","); for (int i = 0; i < 4; i++) { if (messages[i] != null) { sign.setLine(i, messages[i]); } } sign.update(); break; default: break; } }
Example #5
Source File: ObserverModule.java From CardinalPGM with MIT License | 4 votes |
@EventHandler public void onInteraction(PlayerInteractEvent event) { if (testObserver(event.getPlayer())) { event.setCancelled(true); if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && (event.getPlayer().getInventory().getItemInMainHand() != null && event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.WRITTEN_BOOK))){ event.setUseInteractedBlock(Event.Result.DENY); event.setUseItemInHand(Event.Result.ALLOW); } if (event.getClickedBlock() != null && !event.getPlayer().isSneaking() && event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getClickedBlock().getType().equals(Material.CHEST) || event.getClickedBlock().getType().equals(Material.TRAPPED_CHEST)) { Inventory chest = Bukkit.createInventory(null, ((Chest) event.getClickedBlock().getState()).getInventory().getSize()); for (int i = 0; i < ((Chest) event.getClickedBlock().getState()).getInventory().getSize(); i++) { chest.setItem(i, ((Chest) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(chest); } if (event.getClickedBlock().getType().equals(Material.FURNACE) || event.getClickedBlock().getType().equals(Material.BURNING_FURNACE)) { Inventory furnace = Bukkit.createInventory(null, InventoryType.FURNACE); for (int i = 0; i < ((Furnace) event.getClickedBlock().getState()).getInventory().getSize(); i++) { furnace.setItem(i, ((Furnace) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(furnace); } if (event.getClickedBlock().getType().equals(Material.DISPENSER)) { Inventory dispenser = Bukkit.createInventory(null, InventoryType.DISPENSER); for (int i = 0; i < ((Dispenser) event.getClickedBlock().getState()).getInventory().getSize(); i++) { dispenser.setItem(i, ((Dispenser) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(dispenser); } if (event.getClickedBlock().getType().equals(Material.DROPPER)) { Inventory dropper = Bukkit.createInventory(null, InventoryType.DROPPER); for (int i = 0; i < ((Dropper) event.getClickedBlock().getState()).getInventory().getSize(); i++) { dropper.setItem(i, ((Dropper) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(dropper); } if (event.getClickedBlock().getType().equals(Material.HOPPER)) { Inventory hopper = Bukkit.createInventory(null, InventoryType.HOPPER); for (int i = 0; i < ((Hopper) event.getClickedBlock().getState()).getInventory().getSize(); i++) { hopper.setItem(i, ((Hopper) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(hopper); } if (event.getClickedBlock().getType().equals(Material.BREWING_STAND)) { Inventory brewingStand = Bukkit.createInventory(null, InventoryType.BREWING); for (int i = 0; i < ((BrewingStand) event.getClickedBlock().getState()).getInventory().getSize(); i++) { brewingStand.setItem(i, ((BrewingStand) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(brewingStand); } if (event.getClickedBlock().getType().equals(Material.BEACON)) { Inventory beacon = Bukkit.createInventory(null, InventoryType.BEACON); for (int i = 0; i < ((Beacon) event.getClickedBlock().getState()).getInventory().getSize(); i++) { beacon.setItem(i, ((Beacon) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(beacon); } } } }