/** * Gets the location where the possible moving block might be if the * retracting piston is sticky. * * @return The possible location of the possibly moving block. */ public Location getRetractLocation() { return getBlock().getRelative(getDirection(), 2).getLocation(); }
@SuppressWarnings("deprecation") @EventHandler(ignoreCancelled = true) public void onBlockPistonRetract(BlockPistonRetractEvent event) { if (event.isSticky()) { EventDebounce.Entry entry = pistonRetractDebounce.getIfNotPresent(new BlockPistonRetractKey(event), event); if (entry != null) { Block piston = event.getBlock(); Cause cause = create(piston); BlockFace direction = event.getDirection(); blocks = new ArrayList<>(event.getBlocks()); } catch (NoSuchMethodError e) { blocks = Lists.newArrayList(event.getRetractLocation().getBlock()); if (piston.getType() == Material.MOVING_PISTON) { direction = new PistonExtensionMaterial(Material.STICKY_PISTON, piston.getData()).getFacing(); Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, cause, event.getBlock().getWorld(), blocks, Material.AIR)); if (originalSize != blocks.size()) { event.setCancelled(true); entry.setCancelled(event.isCancelled()); if (event.isCancelled()) { playDenyEffect(piston.getLocation().add(0.5, 1, 0.5));
@EventHandler(ignoreCancelled = true) public void onHarvestPistonRetract(BlockPistonRetractEvent event) { if (!event.isSticky()) { return; } if (plugin.getConfig().getBoolean("preferences.nerf_pistons.only_tardis_worlds") && !event.getBlock().getWorld().getName().contains("TARDIS")) { return; } String block = event.getBlock().getRelative(getOppositeDirection(event.getDirection()), 2).getLocation().toString(); if (plugin.getGeneralKeeper().getProtectBlockMap().containsKey(block)) { event.setCancelled(true); } }
if(event.getDirection() == BlockFace.UP) return; if(!GriefPrevention.instance.claimsEnabledForWorld(event.getBlock().getWorld())) return; Claim pistonClaim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, null); if(pistonClaim == null && !event.getBlocks().isEmpty()) event.setCancelled(true); return; for(Block movedBlock : event.getBlocks()) event.setCancelled(true); return; Block block = event.getBlock(); Location pistonLocation = block.getLocation(); Claim pistonClaim = this.dataStore.getClaimAt(pistonLocation, false, null); for(Block movedBlock : event.getBlocks()) event.setCancelled(true); block.getWorld().createExplosion(block.getLocation(), 0); block.getWorld().dropItem(block.getLocation(), new ItemStack(Material.PISTON_STICKY_BASE));
@EventHandler public void onPistonRetract(BlockPistonRetractEvent e) { if (e.isSticky()) { 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 void onPistonRetract(final BlockPistonRetractEvent event) { final List<Block> blocks; if (retractHasBlocks) { blocks = event.getBlocks(); } else { @SuppressWarnings("deprecation") final Location retLoc = event.getRetractLocation(); if (retLoc == null) { blocks = null; } else { final Block retBlock = retLoc.getBlock(); final long flags = BlockProperties.getBlockFlags(retBlock.getType()); if ((flags & F_MOVABLE_IGNORE) == 0L && (flags & F_MOVABLE) != 0L) { blocks = new ArrayList<Block>(1); blocks.add(retBlock); } else { blocks = null; } } } // TODO: Special cases (don't push upwards on retract, with the resulting location being a solid block). final Block pistonBlock = event.getBlock(); final BlockFace direction = getRetractDirection(pistonBlock, event.getDirection()); tracker.addPistonBlocks(pistonBlock.getRelative(direction.getOppositeFace()), direction, blocks); }
/** * Monitor BlockPistonRetract events. * * @param event The event to watch */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPistonRetract(BlockPistonRetractEvent event) { /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) return; // Get opposite direction so we get correct block BlockFace direction = event.getDirection(); Block movedBlock = event.getBlock().getRelative(direction); mcMMO.getPlaceStore().setTrue(movedBlock); for (Block block : event.getBlocks()) { movedBlock = block.getRelative(direction); mcMMO.getPlaceStore().setTrue(movedBlock); } }
@EventHandler (priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockPistonRetract(BlockPistonRetractEvent event) { // if not a sticky piston, retraction should be fine if (!event.isSticky() || !Conf.pistonProtectionThroughDenyBuild) { return; } Location targetLoc = event.getRetractLocation(); Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(targetLoc)); // Check if the piston is moving in a faction's territory. This disables pistons entirely in faction territory. if (otherFaction.isNormal() && SavageFactions.plugin.getConfig().getBoolean("disable-pistons-in-territory", false)) { event.setCancelled(true); return; } // if potentially retracted block is just air/water/lava, no worries if (targetLoc.getBlock().isEmpty() || targetLoc.getBlock().isLiquid()) { return; } Faction pistonFaction = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); if (!canPistonMoveBlock(pistonFaction, targetLoc)) { event.setCancelled(true); } }
@EventHandler(priority = EventPriority.HIGH) public void onPistonRetract(BlockPistonRetractEvent e) { 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); for (Player p : Bukkit.getOnlinePlayers()) { Shop shop = shopUtils.getShop(belowNewBlock.getLocation()); if (shop.getItem() != null) { shop.getItem().resetForPlayer(p); } } } } }
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(ignoreCancelled = true) public void onPistonRetract(BlockPistonRetractEvent event) { String block = event.getBlock().getLocation().toString(); if (plugin.getGeneralKeeper().getSonicPistons().contains(block)) { event.setCancelled(true); plugin.getGeneralKeeper().getSonicListener().setExtension(event.getBlock()); } } }
public BlockPistonRetractKey(BlockPistonRetractEvent event) { piston = event.getBlock(); retract = event.getRetractLocation().getBlock(); }
@EventHandler(ignoreCancelled = true) public static void onBlockPistonRetract(BlockPistonRetractEvent event) { for (Block block : getRetractBlocks(event)) { if (!canBlockBeBroken(block, null)) { event.setCancelled(true); return; } } }
private static List<Block> getRetractBlocks(BlockPistonRetractEvent event) { try { return event.getBlocks(); } catch (NoSuchMethodError outdated) { // backwards compatiblity List<Block> blocks = new ArrayList<>(); Block block = getRetractLocationBlock(event); if (block != null && !BlockUtil.isSign(block)) { blocks.add(block); } return blocks; } }
@Override public MCLocation getRetractedLocation() { return new BukkitMCLocation(event.getRetractLocation()); } }
@EventHandler void onPistonRetract(BlockPistonRetractEvent event) { Block piston = event.getBlock(); BlockFace direction = event.getDirection(); Block nextBlock = piston.getRelative(direction, -2); // Direction is if (event.getBlock().getLocation().getWorld().getName().equals("world")) { tempchunk = "chunk"; else if (event.getBlock().getLocation().getWorld().getName().equals("world_nether")) { tempchunk = "netherchunk"; if (event.isSticky()) { Chunk pistonChunk = piston.getChunk(); Chunk blockChunk = nextBlock.getChunk(); .get(tempchunk + "" + pistonChunk.getX() + "," + pistonChunk.getZ() + "owner")) != null) { if (!owner1.equals(owner2)) { event.setCancelled(true); piston.getRelative(event.getDirection()).setType(Material.AIR); event.setCancelled(true); piston.getRelative(event.getDirection()).setType(Material.AIR);
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onBlockPistonRetract(BlockPistonRetractEvent 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 < 2; i++) { x += dir.getModX(); y += dir.getModY(); z += dir.getModZ(); sscache.invalidateSnapshot(wn, x, y, z); mapManager.touch(wn, x, y, z, "pistonretract"); } }
/** * Gets the location where the possible moving block might be if the * retracting piston is sticky. * * @return The possible location of the possibly moving block. */ public Location getRetractLocation() { return getBlock().getRelative(getDirection(), 2).getLocation(); }