Search in sources :

Example 1 with HangingPreBreakEvent

use of org.cubeengine.module.log.action.hanging.HangingPreBreakEvent in project modules-extra by CubeEngine.

the class ListenerBlock method logAttachedBlocks.

public static void logAttachedBlocks(LogListener ll, EventManager em, Block block, ActionBlock action) {
    if (!block.getType().isSolid() && !(block.getType() == SUGAR_CANE_BLOCK)) {
        // cannot have attached
        return;
    }
    for (Block aBlock : BlockUtil.getAttachedBlocks(block)) {
        em.fireEvent(new BlockPreBreakEvent(aBlock.getLocation(), action));
    }
    for (Block dBlock : BlockUtil.getDetachableBlocksOnTop(block)) {
        if (// ignore upper door halfs
        isNotUpperDoorHalf(dBlock)) {
            em.fireEvent(new BlockPreBreakEvent(dBlock.getLocation(), action));
        }
    }
    if (ll.isActive(HangingBreak.class, block.getWorld())) {
        Location location = block.getLocation();
        Location entityLocation = block.getLocation();
        for (Entity entity : block.getChunk().getEntities()) {
            if (entity instanceof Hanging && location.distanceSquared(entity.getLocation(entityLocation)) < 4) {
                em.fireEvent(new HangingPreBreakEvent(entityLocation, action));
            }
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Hanging(org.bukkit.entity.Hanging) Block(org.bukkit.block.Block) ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) HangingPreBreakEvent(org.cubeengine.module.log.action.hanging.HangingPreBreakEvent) Location(org.spongepowered.api.world.Location)

Aggregations

Block (org.bukkit.block.Block)1 Hanging (org.bukkit.entity.Hanging)1 ActionPlayerBlock (org.cubeengine.module.log.action.block.player.ActionPlayerBlock)1 HangingPreBreakEvent (org.cubeengine.module.log.action.hanging.HangingPreBreakEvent)1 Entity (org.spongepowered.api.entity.Entity)1 Location (org.spongepowered.api.world.Location)1