Search in sources :

Example 1 with BlockPistonExtendKey

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));
        }
    }
}
Also used : 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) BlockPistonExtendKey(com.sk89q.worldguard.bukkit.listener.debounce.BlockPistonExtendKey) 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) 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 BlockPistonExtendKey (com.sk89q.worldguard.bukkit.listener.debounce.BlockPistonExtendKey)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 Block (org.bukkit.block.Block)1 BlockFace (org.bukkit.block.BlockFace)1 FallingBlock (org.bukkit.entity.FallingBlock)1 EventHandler (org.bukkit.event.EventHandler)1