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);
}
}
Aggregations