use of com.sk89q.worldguard.bukkit.listener.debounce.BlockPistonRetractKey in project WorldGuard by EngineHub.
the class EventAbstractionListener method onBlockPistonRetract.
@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();
ArrayList<Block> blocks = new ArrayList<>(event.getBlocks());
int originalSize = blocks.size();
Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, cause, event.getBlock().getWorld(), blocks, Material.AIR));
if (originalSize != blocks.size()) {
event.setCancelled(true);
return;
}
for (Block b : blocks) {
Location loc = b.getRelative(direction).getLocation();
Events.fireToCancel(event, new PlaceBlockEvent(event, cause, loc, b.getType()));
}
entry.setCancelled(event.isCancelled());
if (event.isCancelled()) {
playDenyEffect(piston.getLocation().add(0.5, 1, 0.5));
}
}
}
}
Aggregations