/** * 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.LOW, ignoreCancelled = true) public void onPistonExtend(BlockPistonExtendEvent e) { // Only process if flag is active if (Flags.PISTON_PUSH.isSetForWorld(e.getBlock().getWorld())) { getIslands().getProtectedIslandAt(e.getBlock().getLocation()).ifPresent(i -> e.setCancelled( // Run through the location of all the relative blocks and see if they are outside the island !e.getBlocks().stream() .map(b -> b.getRelative(e.getDirection()).getLocation()) // All blocks must be on the island, otherwise the event is cancelled .allMatch(i::onIsland))); } } }
private void onPistonExtend(final BlockPistonExtendEvent event) { final BlockFace direction = event.getDirection(); tracker.addPistonBlocks(event.getBlock().getRelative(direction), direction, event.getBlocks()); }
@EventHandler(ignoreCancelled = true) public void onHarvestPistonExtend(BlockPistonExtendEvent event) { if (plugin.getConfig().getBoolean("preferences.nerf_pistons.only_tardis_worlds") && !event.getBlock().getWorld().getName().contains("TARDIS")) { return; } for (Block b : event.getBlocks()) { String block = b.getLocation().toString(); if (plugin.getGeneralKeeper().getProtectBlockMap().containsKey(block)) { event.setCancelled(true); return; } } }
@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 */ }
@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"); } } };
@EventHandler public void onPistonExtend(BlockPistonExtendEvent e) { for (Block b : e.getBlocks()) { if (BlockStorage.hasBlockInfo(b)) { e.setCancelled(true); return; } else if(b.getRelative(e.getDirection()) == null && BlockStorage.hasBlockInfo(b.getRelative(e.getDirection()))) { e.setCancelled(true); return; } } }
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 public void onPistonExtend(BlockPistonExtendEvent event) { Block piston = event.getBlock(); Block block = piston.getRelative(event.getDirection()); UndoList undoList = controller.getPendingUndo(block.getLocation()); if (undoList != null) { undoList.add(block); undoList.add(piston); } }
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onBlockPistonExtend(BlockPistonExtendEvent e) { if (cm.disablePMM && VersionUtils.isAtLeast(VersionUtils.V1_8)) { // 使用typeid是为了兼容1.8以下的服务端 for (Block b : e.getBlocks()) { if (b.getTypeId() == 165) { // 165 - SLIME_BLOCK e.setCancelled(true); return; } } } } }
@EventHandler(ignoreCancelled = true) public void onPistonExtend(BlockPistonExtendEvent event) { Block b = event.getBlock(); if (plugin.getGeneralKeeper().getDoorPistons().contains(b)) { event.setCancelled(true); plugin.getGeneralKeeper().getDoorPistons().remove(b); } } }
@Override public List<MCBlock> getPushedBlocks() { List<MCBlock> blocks = new ArrayList<>(); for(Block b : event.getBlocks()) { blocks.add(new BukkitMCBlock(b)); } return blocks; } }
@EventHandler(ignoreCancelled = true) public static void onBlockPistonExtend(BlockPistonExtendEvent event) { for (Block block : getExtendBlocks(event)) { if (!canBlockBeBroken(block, null)) { event.setCancelled(true); return; } } }
@EventHandler(ignoreCancelled = true) public void onBlockPistonExtend(BlockPistonExtendEvent event) { EventDebounce.Entry entry = pistonExtendDebounce.getIfNotPresent(new BlockPistonExtendKey(event), event); if (entry != null) { List<Block> blocks = new ArrayList<>(event.getBlocks()); int originalLength = blocks.size(); BlockFace dir = event.getDirection(); for (int i = 0; i < blocks.size(); i++) { blocks.set(i, blocks.get(i).getRelative(dir)); } Events.fireBulkEventToCancel(event, new PlaceBlockEvent(event, create(event.getBlock()), event.getBlock().getWorld(), blocks, Material.STONE)); if (blocks.size() != originalLength) { event.setCancelled(true); } entry.setCancelled(event.isCancelled()); if (event.isCancelled()) { playDenyEffect(event.getBlock().getLocation().add(0.5, 1, 0.5)); } } }
/** * Monitor BlockPistonExtend events. * * @param event The event to monitor */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPistonExtend(BlockPistonExtendEvent event) { /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) return; BlockFace direction = event.getDirection(); Block movedBlock = event.getBlock(); movedBlock = movedBlock.getRelative(direction, 2); for (Block b : event.getBlocks()) { if (BlockUtils.shouldBeWatched(b.getState()) && mcMMO.getPlaceStore().isTrue(b)) { movedBlock = b.getRelative(direction); mcMMO.getPlaceStore().setTrue(movedBlock); } } }
Block piston = event.getBlock(); List<Block> blocks = event.getBlocks(); event.setCancelled(true); PreciousStones.debug("Cancelling field sign move"); return; event.setCancelled(true); return; event.setCancelled(true); PreciousStones.debug("Cancelling unbreakable move"); return; event.setCancelled(true); PreciousStones.debug("Cancelling field conflict move"); return;
@EventHandler(priority = EventPriority.HIGH) public void onPistonExtend(BlockPistonExtendEvent e) { // If the piston would only move itself Block airAfterPiston = e.getBlock().getRelative(e.getDirection()); Block belowAir = airAfterPiston.getRelative(BlockFace.DOWN); if (shopUtils.isShop(belowAir.getLocation())) { e.setCancelled(true); return; } for (Block b : e.getBlocks()) { Block newBlock = b.getRelative(e.getDirection()); Block belowNewBlock = newBlock.getRelative(BlockFace.DOWN); if (shopUtils.isShop(belowNewBlock.getLocation())) e.setCancelled(true); } }
/** * 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 void onPistonExtends(BlockPistonExtendEvent event) { Block piston = event.getBlock(); List<Block> blocks = event.getBlocks(); BlockFace direction = event.getDirection(); if (event.getBlock().getLocation().getWorld().getName().equals("world")) { tempchunk = "chunk"; else if (event.getBlock().getLocation().getWorld().getName().equals("world_nether")) { tempchunk = "netherchunk"; .get(tempchunk + "" + pistonChunk.getX() + "," + pistonChunk.getZ() + "owner")) != null) { if (!owner1.equals(owner2)) { event.setCancelled(true); event.setCancelled(true);