Updated /ClaimExplosions and global explosions.

Now even when surface explosions are blocked, both /ClaimExplosions and
the global config option to allow all explosion damage inside land
claims will override that block.
This commit is contained in:
ryanhamshire 2015-03-28 13:30:08 -07:00
parent 123fc4c284
commit e91924eb94

View File

@ -195,64 +195,77 @@ class EntityEventHandler implements Listener
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onEntityExplode(EntityExplodeEvent explodeEvent) public void onEntityExplode(EntityExplodeEvent explodeEvent)
{ {
List<Block> blocks = explodeEvent.blockList(); //only applies to claims-enabled worlds
Location location = explodeEvent.getLocation(); Location location = explodeEvent.getLocation();
World world = location.getWorld();
if(!GriefPrevention.instance.claimsEnabledForWorld(world)) return;
//FEATURE: explosions don't destroy blocks when they explode near or above sea level in standard worlds //FEATURE: explosions don't destroy blocks when they explode near or above sea level in standard worlds
boolean isCreeper = (explodeEvent.getEntity() != null && explodeEvent.getEntity() instanceof Creeper); boolean isCreeper = (explodeEvent.getEntity() != null && explodeEvent.getEntity() instanceof Creeper);
//exception for some land claims in survival worlds, see notes below boolean applySeaLevelRules = world.getEnvironment() == Environment.NORMAL && ((isCreeper && GriefPrevention.instance.config_blockSurfaceCreeperExplosions) || (!isCreeper && GriefPrevention.instance.config_blockSurfaceOtherExplosions));
Claim originationClaim = null;
if(!GriefPrevention.instance.creativeRulesApply(location)) List<Block> blocks = explodeEvent.blockList();
//special rule for creative worlds: explosions don't destroy anything
if(GriefPrevention.instance.creativeRulesApply(explodeEvent.getLocation()))
{ {
originationClaim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null); for(int i = 0; i < blocks.size(); i++)
{
Block block = blocks.get(i);
if(GriefPrevention.instance.config_mods_explodableIds.Contains(new MaterialInfo(block.getTypeId(), block.getData(), null))) continue;
blocks.remove(i--);
}
return;
} }
if( location.getWorld().getEnvironment() == Environment.NORMAL && GriefPrevention.instance.claimsEnabledForWorld(location.getWorld()) && ((isCreeper && GriefPrevention.instance.config_blockSurfaceCreeperExplosions) || (!isCreeper && GriefPrevention.instance.config_blockSurfaceOtherExplosions))) //make a list of blocks which were allowed to explode
{ List<Block> explodedBlocks = new ArrayList<Block>();
for(int i = 0; i < blocks.size(); i++) Claim cachedClaim = null;
{ for(int i = 0; i < blocks.size(); i++)
Block block = blocks.get(i); {
if(GriefPrevention.instance.config_mods_explodableIds.Contains(new MaterialInfo(block.getTypeId(), block.getData(), null))) continue; Block block = blocks.get(i);
//in survival worlds, if claim explosions are enabled for the source claim, allow non-creeper explosions to destroy blocks in and under that claim even above sea level. //always ignore air blocks
if(!isCreeper && originationClaim != null && originationClaim.areExplosivesAllowed && originationClaim.contains(block.getLocation(), true, false)) continue; if(block.getType() == Material.AIR) continue;
if(block.getLocation().getBlockY() > GriefPrevention.instance.getSeaLevel(location.getWorld()) - 7) //always allow certain block types to explode
{ if(GriefPrevention.instance.config_mods_explodableIds.Contains(new MaterialInfo(block.getTypeId(), block.getData(), null)))
blocks.remove(i--); {
} explodedBlocks.add(block);
} continue;
} }
//special rule for creative worlds: explosions don't destroy anything //is it in a land claim?
if(GriefPrevention.instance.creativeRulesApply(explodeEvent.getLocation())) Claim claim = this.dataStore.getClaimAt(block.getLocation(), false, cachedClaim);
{ if(claim != null)
for(int i = 0; i < blocks.size(); i++) {
{ cachedClaim = claim;
Block block = blocks.get(i); }
if(GriefPrevention.instance.config_mods_explodableIds.Contains(new MaterialInfo(block.getTypeId(), block.getData(), null))) continue;
//if yes, apply claim exemptions if they should apply
blocks.remove(i--); if((claim != null && claim.areExplosivesAllowed) || !GriefPrevention.instance.config_blockClaimExplosions)
} {
} explodedBlocks.add(block);
continue;
//FEATURE: explosions don't damage claimed blocks }
Claim claim = null;
for(int i = 0; i < blocks.size(); i++) //for each destroyed block //if no, then also consider sea level rules
{ if(applySeaLevelRules)
Block block = blocks.get(i); {
if(block.getType() == Material.AIR) continue; //if it's air, we don't care if(block.getLocation().getBlockY() < GriefPrevention.instance.getSeaLevel(world) - 7)
{
if(GriefPrevention.instance.config_mods_explodableIds.Contains(new MaterialInfo(block.getTypeId(), block.getData(), null))) continue; explodedBlocks.add(block);
}
claim = this.dataStore.getClaimAt(block.getLocation(), false, claim); }
//if the block is claimed, remove it from the list of destroyed blocks }
if(claim != null && !claim.areExplosivesAllowed && GriefPrevention.instance.config_blockClaimExplosions)
{ //clear original damage list and replace with allowed damage list
blocks.remove(i--); blocks.clear();
} blocks.addAll(explodedBlocks);
}
} }
//when an item spawns... //when an item spawns...