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:
parent
123fc4c284
commit
e91924eb94
|
|
@ -195,35 +195,18 @@ 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))
|
|
||||||
{
|
|
||||||
originationClaim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( location.getWorld().getEnvironment() == Environment.NORMAL && GriefPrevention.instance.claimsEnabledForWorld(location.getWorld()) && ((isCreeper && GriefPrevention.instance.config_blockSurfaceCreeperExplosions) || (!isCreeper && GriefPrevention.instance.config_blockSurfaceOtherExplosions)))
|
List<Block> blocks = explodeEvent.blockList();
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
//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.
|
|
||||||
if(!isCreeper && originationClaim != null && originationClaim.areExplosivesAllowed && originationClaim.contains(block.getLocation(), true, false)) continue;
|
|
||||||
|
|
||||||
if(block.getLocation().getBlockY() > GriefPrevention.instance.getSeaLevel(location.getWorld()) - 7)
|
|
||||||
{
|
|
||||||
blocks.remove(i--);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//special rule for creative worlds: explosions don't destroy anything
|
//special rule for creative worlds: explosions don't destroy anything
|
||||||
if(GriefPrevention.instance.creativeRulesApply(explodeEvent.getLocation()))
|
if(GriefPrevention.instance.creativeRulesApply(explodeEvent.getLocation()))
|
||||||
|
|
@ -235,26 +218,56 @@ class EntityEventHandler implements Listener
|
||||||
|
|
||||||
blocks.remove(i--);
|
blocks.remove(i--);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//FEATURE: explosions don't damage claimed blocks
|
//make a list of blocks which were allowed to explode
|
||||||
Claim claim = null;
|
List<Block> explodedBlocks = new ArrayList<Block>();
|
||||||
for(int i = 0; i < blocks.size(); i++) //for each destroyed block
|
Claim cachedClaim = null;
|
||||||
|
for(int i = 0; i < blocks.size(); i++)
|
||||||
{
|
{
|
||||||
Block block = blocks.get(i);
|
Block block = blocks.get(i);
|
||||||
if(block.getType() == Material.AIR) continue; //if it's air, we don't care
|
|
||||||
|
|
||||||
if(GriefPrevention.instance.config_mods_explodableIds.Contains(new MaterialInfo(block.getTypeId(), block.getData(), null))) continue;
|
//always ignore air blocks
|
||||||
|
if(block.getType() == Material.AIR) continue;
|
||||||
|
|
||||||
claim = this.dataStore.getClaimAt(block.getLocation(), false, claim);
|
//always allow certain block types to explode
|
||||||
//if the block is claimed, remove it from the list of destroyed blocks
|
if(GriefPrevention.instance.config_mods_explodableIds.Contains(new MaterialInfo(block.getTypeId(), block.getData(), null)))
|
||||||
if(claim != null && !claim.areExplosivesAllowed && GriefPrevention.instance.config_blockClaimExplosions)
|
|
||||||
{
|
{
|
||||||
blocks.remove(i--);
|
explodedBlocks.add(block);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//is it in a land claim?
|
||||||
|
Claim claim = this.dataStore.getClaimAt(block.getLocation(), false, cachedClaim);
|
||||||
|
if(claim != null)
|
||||||
|
{
|
||||||
|
cachedClaim = claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if yes, apply claim exemptions if they should apply
|
||||||
|
if((claim != null && claim.areExplosivesAllowed) || !GriefPrevention.instance.config_blockClaimExplosions)
|
||||||
|
{
|
||||||
|
explodedBlocks.add(block);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if no, then also consider sea level rules
|
||||||
|
if(applySeaLevelRules)
|
||||||
|
{
|
||||||
|
if(block.getLocation().getBlockY() < GriefPrevention.instance.getSeaLevel(world) - 7)
|
||||||
|
{
|
||||||
|
explodedBlocks.add(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//clear original damage list and replace with allowed damage list
|
||||||
|
blocks.clear();
|
||||||
|
blocks.addAll(explodedBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
//when an item spawns...
|
//when an item spawns...
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onItemSpawn(ItemSpawnEvent event)
|
public void onItemSpawn(ItemSpawnEvent event)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user