Search in sources :

Example 36 with UndoList

use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.

the class ExplosionController method onEntityExplode.

@EventHandler(priority = EventPriority.LOWEST)
public void onEntityExplode(EntityExplodeEvent event) {
    Entity explodingEntity = event.getEntity();
    if (explodingEntity == null)
        return;
    UndoList blockList = getExplosionUndo(explodingEntity);
    boolean cancel = event.isCancelled();
    cancel = cancel || explodingEntity.hasMetadata("cancel_explosion");
    if (blockList != null) {
        com.elmakers.mine.bukkit.api.action.CastContext context = blockList.getContext();
        if (!cancel && context != null && !context.hasBreakPermission(explodingEntity.getLocation().getBlock())) {
            cancel = true;
        }
    }
    if (cancel) {
        event.setCancelled(true);
    } else if (maxTNTPerChunk > 0 && explodingEntity.getType() == EntityType.PRIMED_TNT) {
        Chunk chunk = explodingEntity.getLocation().getChunk();
        if (chunk == null || !chunk.isLoaded())
            return;
        int tntCount = 0;
        Entity[] entities = chunk.getEntities();
        for (Entity entity : entities) {
            if (entity != null && entity.getType() == EntityType.PRIMED_TNT) {
                tntCount++;
            }
        }
        if (tntCount > maxTNTPerChunk) {
            event.setCancelled(true);
        } else {
            if (blockList != null) {
                blockList.explode(explodingEntity, event.blockList());
            }
        }
    } else if (blockList != null) {
        blockList.explode(explodingEntity, event.blockList());
        blockList.getOwner().registerForUndo(blockList);
    }
}
Also used : Entity(org.bukkit.entity.Entity) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Chunk(org.bukkit.Chunk) EventHandler(org.bukkit.event.EventHandler)

Aggregations

UndoList (com.elmakers.mine.bukkit.api.block.UndoList)36 EventHandler (org.bukkit.event.EventHandler)15 Entity (org.bukkit.entity.Entity)14 Block (org.bukkit.block.Block)13 Location (org.bukkit.Location)10 FallingBlock (org.bukkit.entity.FallingBlock)10 Mage (com.elmakers.mine.bukkit.api.magic.Mage)8 LivingEntity (org.bukkit.entity.LivingEntity)6 Player (org.bukkit.entity.Player)6 ItemStack (org.bukkit.inventory.ItemStack)6 Ageable (org.bukkit.entity.Ageable)4 PigZombie (org.bukkit.entity.PigZombie)4 Slime (org.bukkit.entity.Slime)4 Zombie (org.bukkit.entity.Zombie)4 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)3 Target (com.elmakers.mine.bukkit.utility.Target)3 Nullable (javax.annotation.Nullable)3 BlockFace (org.bukkit.block.BlockFace)3 Skeleton (org.bukkit.entity.Skeleton)3