diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java index 3a628ac2..5e85d776 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java @@ -19,6 +19,22 @@ package com.sk89q.worldguard.bukkit; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; + +import org.bukkit.block.Block; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffectType; + import com.sk89q.util.yaml.YAMLFormat; import com.sk89q.util.yaml.YAMLProcessor; import com.sk89q.worldguard.blacklist.Blacklist; @@ -28,16 +44,6 @@ import com.sk89q.worldguard.blacklist.loggers.FileLoggerHandler; import com.sk89q.worldguard.chest.ChestProtection; import com.sk89q.worldguard.chest.SignChestProtection; -import org.bukkit.block.Block; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.*; -import java.util.logging.Level; /** * Holds the configuration for individual worlds. @@ -101,6 +107,7 @@ public class WorldConfiguration { public boolean blockEnderDragonPortalCreation; public boolean blockFireballExplosions; public boolean blockFireballBlockDamage; + public boolean blockOtherExplosions; public boolean blockEntityPaintingDestroy; public boolean blockEntityItemFrameDestroy; public boolean blockPluginSpawning; @@ -344,6 +351,7 @@ private void loadConfiguration() { blockEntityItemFrameDestroy = getBoolean("mobs.block-item-frame-destroy", false); blockPluginSpawning = getBoolean("mobs.block-plugin-spawning", true); blockGroundSlimes = getBoolean("mobs.block-above-ground-slimes", false); + blockOtherExplosions = getBoolean("mobs.block-other-explosions", false); disableFallDamage = getBoolean("player-damage.disable-fall-damage", false); disableLavaDamage = getBoolean("player-damage.disable-lava-damage", false); diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java index a026934e..910524d6 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java @@ -516,6 +516,7 @@ public void onEntityExplode(EntityExplodeEvent event) { if (ent.getType() == witherType) { if (wcfg.blockWitherBlockDamage) { event.blockList().clear(); + event.setCancelled(true); return; } @@ -528,6 +529,7 @@ public void onEntityExplode(EntityExplodeEvent event) { if (ent.getType() == witherSkullType) { if (wcfg.blockWitherSkullBlockDamage) { event.blockList().clear(); + event.setCancelled(true); return; } @@ -540,6 +542,7 @@ public void onEntityExplode(EntityExplodeEvent event) { if (ent instanceof Creeper) { if (wcfg.blockCreeperBlockDamage) { event.blockList().clear(); + event.setCancelled(true); return; } @@ -555,6 +558,7 @@ public void onEntityExplode(EntityExplodeEvent event) { for (Block block : event.blockList()) { if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.CREEPER_EXPLOSION)) { event.blockList().clear(); + event.setCancelled(true); return; } } @@ -563,6 +567,7 @@ public void onEntityExplode(EntityExplodeEvent event) { } else if (ent instanceof EnderDragon) { if (wcfg.blockEnderDragonBlockDamage) { event.blockList().clear(); + event.setCancelled(true); return; } @@ -572,6 +577,7 @@ public void onEntityExplode(EntityExplodeEvent event) { for (Block block : event.blockList()) { if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE)) { event.blockList().clear(); + event.setCancelled(true); return; } } @@ -579,6 +585,7 @@ public void onEntityExplode(EntityExplodeEvent event) { } else if (ent instanceof TNTPrimed) { if (wcfg.blockTNTBlockDamage) { event.blockList().clear(); + event.setCancelled(true); return; } @@ -593,6 +600,7 @@ public void onEntityExplode(EntityExplodeEvent event) { for (Block block : event.blockList()) { if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.TNT)) { event.blockList().clear(); + event.setCancelled(true); return; } } @@ -600,6 +608,7 @@ public void onEntityExplode(EntityExplodeEvent event) { } else if (ent instanceof Fireball) { if (wcfg.blockFireballBlockDamage) { event.blockList().clear(); + event.setCancelled(true); return; } @@ -614,11 +623,28 @@ public void onEntityExplode(EntityExplodeEvent event) { for (Block block : event.blockList()) { if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.GHAST_FIREBALL)) { event.blockList().clear(); + event.setCancelled(true); return; } } } } + } else { + // null entity, caused by another plugin or so + if (wcfg.blockOtherExplosions) { + event.blockList().clear(); + event.setCancelled(true); + return; + } + if (wcfg.useRegions) { + RegionManager mgr = plugin.getGlobalRegionManager().get(world); + for (Block block : event.blockList()) { + if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.OTHER_EXPLOSION)) { + event.blockList().clear(); + return; + } + } + } } if (wcfg.signChestProtection) { diff --git a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java index 6d4b6746..9ae20e2a 100644 --- a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java +++ b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java @@ -37,6 +37,7 @@ public final class DefaultFlag { public static final StateFlag CREEPER_EXPLOSION = new StateFlag("creeper-explosion", true, RegionGroup.ALL); public static final StateFlag ENDERDRAGON_BLOCK_DAMAGE = new StateFlag("enderdragon-block-damage", true); public static final StateFlag GHAST_FIREBALL = new StateFlag("ghast-fireball", true, RegionGroup.ALL); + public static final StateFlag OTHER_EXPLOSION = new StateFlag("other-explosion", true); public static final StateFlag SLEEP = new StateFlag("sleep", true); public static final StateFlag TNT = new StateFlag("tnt", true, RegionGroup.ALL); public static final StateFlag LIGHTER = new StateFlag("lighter", true, RegionGroup.ALL); @@ -97,7 +98,7 @@ public final class DefaultFlag { PASSTHROUGH, BUILD, CONSTRUCT, PVP, CHEST_ACCESS, PISTONS, TNT, LIGHTER, USE, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP, MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS, - CREEPER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD, + CREEPER_EXPLOSION, OTHER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE, EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY, ENDERPEARL, ENTITY_ITEM_FRAME_DESTROY, ITEM_DROP, MAX_PLAYERS, MAX_PLAYERS_MESSAGE,