/** * Get an immutable list of the blocks which will be moved by the * extending. * * @return Immutable list of the moved blocks. */ public List<Block> getBlocks() { if (blocks == null) { ArrayList<Block> tmp = new ArrayList<Block>(); for (int i = 0; i < this.getLength(); i++) { tmp.add(block.getRelative(getDirection(), i + 1)); } blocks = Collections.unmodifiableList(tmp); } return blocks; }
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onBlockPistonExtend(BlockPistonExtendEvent event) { Block b = event.getBlock(); Location loc = b.getLocation(); BlockFace dir; try { /* Workaround Bukkit bug = http://leaky.bukkit.org/issues/1227 */ dir = event.getDirection(); } catch (ClassCastException ccx) { dir = BlockFace.NORTH; } String wn = getWorld(loc.getWorld()).getName(); int x = loc.getBlockX(), y = loc.getBlockY(), z = loc.getBlockZ(); sscache.invalidateSnapshot(wn, x, y, z); if(onpiston) mapManager.touch(wn, x, y, z, "pistonretract"); for(int i = 0; i < 1+event.getLength(); i++) { x += dir.getModX(); y += dir.getModY(); z += dir.getModZ(); sscache.invalidateSnapshot(wn, x, y, z); mapManager.touch(wn, x, y, z, "pistonretract"); } } };
/** * Get an immutable list of the blocks which will be moved by the * extending. * * @return Immutable list of the moved blocks. */ public List<Block> getBlocks() { if (blocks == null) { ArrayList<Block> tmp = new ArrayList<Block>(); for (int i = 0; i < this.getLength(); i++) { tmp.add(block.getRelative(getDirection(), i + 1)); } blocks = Collections.unmodifiableList(tmp); } return blocks; }
private static List<Block> getExtendBlocks(BlockPistonExtendEvent event) { try { return event.getBlocks(); } catch (NoSuchMethodError outdated) { // backwards compatiblity BlockFace pistonDirection = getPistonDirection(event.getBlock()); if (pistonDirection == null) { return new ArrayList<>(); } Block piston = event.getBlock(); List<Block> pushedBlocks = new ArrayList<>(); for (int currentBlock = 1; currentBlock < event.getLength() + 1; currentBlock++) { Block block = piston.getRelative(pistonDirection, currentBlock); Material blockType = block.getType(); if (blockType == Material.AIR) { break; } pushedBlocks.add(block); } return pushedBlocks; } } }
@EventHandler (priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockPistonExtend(BlockPistonExtendEvent event) { if (!Conf.pistonProtectionThroughDenyBuild) { return; } Faction pistonFaction = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); // target end-of-the-line empty (air) block which is being pushed into, including if piston itself would extend into air Block targetBlock = event.getBlock().getRelative(event.getDirection(), event.getLength() + 1); // if potentially pushing into air/water/lava in another territory, we need to check it out if ((targetBlock.isEmpty() || targetBlock.isLiquid()) && !canPistonMoveBlock(pistonFaction, targetBlock.getLocation())) { event.setCancelled(true); } /* * note that I originally was testing the territory of each affected block, but since I found that pistons can only push * up to 12 blocks and the width of any territory is 16 blocks, it should be safe (and much more lightweight) to test * only the final target block as done above */ }