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; } }
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); }
@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; } } } }
/** * 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.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); } } } } }
blocks = new ArrayList<>(event.getBlocks()); } catch (NoSuchMethodError e) { blocks = Lists.newArrayList(event.getRetractLocation().getBlock());
List<Block> blocks = event.getBlocks();