use of com.sk89q.worldguard.bukkit.listener.debounce.BlockPistonExtendKey in project WorldGuard by EngineHub.
the class EventAbstractionListener method onBlockPistonExtend.
@EventHandler(ignoreCancelled = true)
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
EventDebounce.Entry entry = pistonExtendDebounce.getIfNotPresent(new BlockPistonExtendKey(event), event);
if (entry != null) {
Cause cause = create(event.getBlock());
List<Block> blocks = new ArrayList<>(event.getBlocks());
int originalLength = blocks.size();
Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, cause, event.getBlock().getWorld(), blocks, Material.AIR));
if (originalLength != blocks.size()) {
event.setCancelled(true);
return;
}
BlockFace dir = event.getDirection();
for (int i = 0; i < blocks.size(); i++) {
Block existing = blocks.get(i);
if (existing.getPistonMoveReaction() == PistonMoveReaction.MOVE || existing.getPistonMoveReaction() == PistonMoveReaction.PUSH_ONLY || existing.getType() == Material.PISTON || existing.getType() == Material.STICKY_PISTON) {
blocks.set(i, existing.getRelative(dir));
}
}
Events.fireBulkEventToCancel(event, new PlaceBlockEvent(event, cause, 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));
}
}
}
Aggregations