Fixed explosions destroying too many blocks.

Due to a breaking Spigot change in 1.8.3.
This commit is contained in:
ryanhamshire 2015-04-08 14:16:06 -07:00
parent 1bfb57b9e0
commit 38cbab1c40

View File

@ -52,6 +52,7 @@ import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityBreakDoorEvent; import org.bukkit.event.entity.EntityBreakDoorEvent;
@ -194,22 +195,31 @@ class EntityEventHandler implements Listener
//when an entity explodes... //when an entity explodes...
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onEntityExplode(EntityExplodeEvent explodeEvent) public void onEntityExplode(EntityExplodeEvent explodeEvent)
{
this.handleExplosion(explodeEvent.getLocation(), explodeEvent.getEntity(), explodeEvent.blockList());
}
//when a block explodes...
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onBlockExplode(BlockExplodeEvent explodeEvent)
{
this.handleExplosion(explodeEvent.getBlock().getLocation(), null, explodeEvent.blockList());
}
void handleExplosion(Location location, Entity entity, List<Block> blocks)
{ {
//only applies to claims-enabled worlds //only applies to claims-enabled worlds
Location location = explodeEvent.getLocation();
World world = location.getWorld(); World world = location.getWorld();
if(!GriefPrevention.instance.claimsEnabledForWorld(world)) return; 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 surface blocks by default
boolean isCreeper = (explodeEvent.getEntity() != null && explodeEvent.getEntity() instanceof Creeper); boolean isCreeper = (entity != null && entity instanceof Creeper);
boolean applySeaLevelRules = world.getEnvironment() == Environment.NORMAL && ((isCreeper && GriefPrevention.instance.config_blockSurfaceCreeperExplosions) || (!isCreeper && GriefPrevention.instance.config_blockSurfaceOtherExplosions)); boolean applySurfaceRules = world.getEnvironment() == Environment.NORMAL && ((isCreeper && GriefPrevention.instance.config_blockSurfaceCreeperExplosions) || (!isCreeper && GriefPrevention.instance.config_blockSurfaceOtherExplosions));
List<Block> blocks = explodeEvent.blockList();
//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(location))
{ {
for(int i = 0; i < blocks.size(); i++) for(int i = 0; i < blocks.size(); i++)
{ {
@ -253,8 +263,8 @@ class EntityEventHandler implements Listener
continue; continue;
} }
//if no, then also consider sea level rules //if no, then also consider surface rules
if(applySeaLevelRules) if(applySurfaceRules && claim == null)
{ {
if(block.getLocation().getBlockY() < GriefPrevention.instance.getSeaLevel(world) - 7) if(block.getLocation().getBlockY() < GriefPrevention.instance.getSeaLevel(world) - 7)
{ {