Search in sources :

Example 1 with BlockPistonRetractKey

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));
            }
        }
    }
}
Also used : BlockPistonRetractKey(com.sk89q.worldguard.bukkit.listener.debounce.BlockPistonRetractKey) InventoryMoveItemEventDebounce(com.sk89q.worldguard.bukkit.listener.debounce.legacy.InventoryMoveItemEventDebounce) EventDebounce(com.sk89q.worldguard.bukkit.listener.debounce.EventDebounce) EntityEntityEventDebounce(com.sk89q.worldguard.bukkit.listener.debounce.legacy.EntityEntityEventDebounce) BlockEntityEventDebounce(com.sk89q.worldguard.bukkit.listener.debounce.legacy.BlockEntityEventDebounce) BlockFace(org.bukkit.block.BlockFace) Cause(com.sk89q.worldguard.bukkit.cause.Cause) Entry(com.sk89q.worldguard.bukkit.listener.debounce.legacy.AbstractEventDebounce.Entry) ArrayList(java.util.ArrayList) FallingBlock(org.bukkit.entity.FallingBlock) Block(org.bukkit.block.Block) BreakBlockEvent(com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent) PlaceBlockEvent(com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Cause (com.sk89q.worldguard.bukkit.cause.Cause)1 BreakBlockEvent (com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent)1 PlaceBlockEvent (com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent)1 BlockPistonRetractKey (com.sk89q.worldguard.bukkit.listener.debounce.BlockPistonRetractKey)1 EventDebounce (com.sk89q.worldguard.bukkit.listener.debounce.EventDebounce)1 Entry (com.sk89q.worldguard.bukkit.listener.debounce.legacy.AbstractEventDebounce.Entry)1 BlockEntityEventDebounce (com.sk89q.worldguard.bukkit.listener.debounce.legacy.BlockEntityEventDebounce)1 EntityEntityEventDebounce (com.sk89q.worldguard.bukkit.listener.debounce.legacy.EntityEntityEventDebounce)1 InventoryMoveItemEventDebounce (com.sk89q.worldguard.bukkit.listener.debounce.legacy.InventoryMoveItemEventDebounce)1 ArrayList (java.util.ArrayList)1 Location (org.bukkit.Location)1 Block (org.bukkit.block.Block)1 BlockFace (org.bukkit.block.BlockFace)1 FallingBlock (org.bukkit.entity.FallingBlock)1 EventHandler (org.bukkit.event.EventHandler)1