From 3757056e4671f965b7f24f7fd308b746c507fe6e Mon Sep 17 00:00:00 2001 From: Wizjany Date: Tue, 9 Aug 2011 20:37:15 -0400 Subject: [PATCH] Fixed up explosion handling. --- .../worldguard/bukkit/WorldConfiguration.java | 13 +- .../bukkit/WorldGuardEntityListener.java | 117 ++++++++++-------- 2 files changed, 71 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java index ed333498..9b902af3 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java @@ -89,15 +89,16 @@ public class WorldConfiguration { public boolean noPhysicsSand; public boolean allowPortalAnywhere; public Set preventWaterDamage; - public boolean blockTNT; public boolean blockLighter; - public boolean disableTNTDamage; public boolean disableFireSpread; public Set disableFireSpreadBlocks; public boolean preventLavaFire; public Set allowedLavaSpreadOver; + public boolean blockTNTExplosions; + public boolean blockTNTBlockDamage; public boolean blockCreeperExplosions; public boolean blockCreeperBlockDamage; + public boolean blockFireballExplosions; public boolean blockFireballBlockDamage; public int loginProtection; public int spawnProtection; @@ -268,7 +269,9 @@ private void loadConfiguration() { allowPortalAnywhere = getBoolean("physics.allow-portal-anywhere", false); preventWaterDamage = new HashSet(getIntList("physics.disable-water-damage-blocks", null)); - blockTNT = getBoolean("ignition.block-tnt", false); + blockTNTExplosions = getBoolean("ignition.block-tnt", false); + // any better place to put this? + blockTNTBlockDamage = getBoolean("ignition.block-tnt-block-damage", false); blockLighter = getBoolean("ignition.block-lighter", false); preventLavaFire = getBoolean("fire.disable-lava-fire-spread", true); @@ -278,6 +281,7 @@ private void loadConfiguration() { blockCreeperExplosions = getBoolean("mobs.block-creeper-explosions", false); blockCreeperBlockDamage = getBoolean("mobs.block-creeper-block-damage", false); + blockFireballExplosions = getBoolean("mob.block-fireball-explosions", false); blockFireballBlockDamage = getBoolean("mobs.block-fireball-block-damage", false); antiWolfDumbness = getBoolean("mobs.anti-wolf-dumbness", false); @@ -287,7 +291,6 @@ private void loadConfiguration() { exactRespawn = getBoolean("spawn.exact-respawn", false); teleportToHome = getBoolean("spawn.teleport-to-home-on-death", false); - disableTNTDamage = getBoolean("player-damage.disable-tnt-damage", false); disableFallDamage = getBoolean("player-damage.disable-fall-damage", false); disableLavaDamage = getBoolean("player-damage.disable-lava-damage", false); disableFireDamage = getBoolean("player-damage.disable-fire-damage", false); @@ -409,7 +412,7 @@ private void loadConfiguration() { logger.log(Level.INFO, enforceOneSession ? "WorldGuard: (" + worldName + ") Single session is enforced." : "WorldGuard: (" + worldName + ") Single session is NOT ENFORCED."); - logger.log(Level.INFO, blockTNT + logger.log(Level.INFO, blockTNTExplosions ? "WorldGuard: (" + worldName + ") TNT ignition is blocked." : "WorldGuard: (" + worldName + ") TNT ignition is PERMITTED."); logger.log(Level.INFO, blockLighter diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java index 985a052d..845521c9 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java @@ -131,7 +131,6 @@ private void registerEvent(String typeName, Priority priority) { */ @Override public void onEntityInteract(EntityInteractEvent event) { - //bukkit doesn't actually throw this event yet, someone add a ticket to leaky Entity entity = event.getEntity(); Block block = event.getBlock(); @@ -193,7 +192,7 @@ private void onEntityDamageByBlock(EntityDamageByBlockEvent event) { return; } - if (wcfg.disableExplosionDamage && event.getCause() == DamageCause.BLOCK_EXPLOSION) { + if (wcfg.disableExplosionDamage && type == DamageCause.BLOCK_EXPLOSION) { event.setCancelled(true); return; } @@ -279,9 +278,36 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) { } } - if (attacker != null && attacker instanceof TNTPrimed && wcfg.disableTNTDamage) { - event.setCancelled(true); - return; + if (attacker != null && attacker instanceof TNTPrimed) { + if (wcfg.blockTNTExplosions) { + event.setCancelled(true); + return; + } + if (wcfg.useRegions) { + Vector pt = toVector(defender.getLocation()); + RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld()); + ApplicableRegionSet set = mgr.getApplicableRegions(pt); + if (!set.allows(DefaultFlag.TNT)) { + event.setCancelled(true); + return; + } + } + } + + if (attacker != null && attacker instanceof Fireball) { + if (wcfg.blockFireballExplosions) { + event.setCancelled(true); + return; + } + if (wcfg.useRegions) { + Vector pt = toVector(defender.getLocation()); + RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld()); + ApplicableRegionSet set = mgr.getApplicableRegions(pt); + if (!set.allows(DefaultFlag.GHAST_FIREBALL)) { + event.setCancelled(true); + return; + } + } } if (attacker != null && attacker instanceof LivingEntity @@ -497,42 +523,57 @@ public void onEntityExplode(EntityExplodeEvent event) { } if (ent instanceof LivingEntity) { - if (wcfg.blockCreeperBlockDamage) { - event.setCancelled(true); - return; - } - - if (wcfg.blockCreeperExplosions) { + if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) { event.setCancelled(true); return; } if (wcfg.useRegions) { - Vector pt = toVector(l); - RegionManager mgr = plugin.getGlobalRegionManager().get(world); + if (wcfg.useRegions) { + RegionManager mgr = plugin.getGlobalRegionManager().get(world); - if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.CREEPER_EXPLOSION)) { - event.setCancelled(true); - return; + for (Block block : event.blockList()) { + if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.CREEPER_EXPLOSION)) { + event.setCancelled(true); + return; + } + } } } } else if (ent instanceof TNTPrimed) { - if (wcfg.blockTNT) { + if (wcfg.blockTNTBlockDamage || wcfg.blockTNTExplosions) { event.setCancelled(true); return; } if (wcfg.useRegions) { - Vector pt = toVector(l); RegionManager mgr = plugin.getGlobalRegionManager().get(world); - if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.TNT)) { - event.setCancelled(true); - return; + for (Block block : event.blockList()) { + if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.TNT)) { + event.setCancelled(true); + return; + } + } + } + } else if (ent instanceof Fireball) { + if (wcfg.blockFireballBlockDamage || wcfg.blockFireballExplosions) { + 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.GHAST_FIREBALL)) { + event.setCancelled(true); + return; + } } } } - + if (wcfg.signChestProtection) { for (Block block : event.blockList()) { if (wcfg.isChestProtected(block)) { @@ -542,19 +583,6 @@ public void onEntityExplode(EntityExplodeEvent event) { } } - if (wcfg.useRegions) { - RegionManager mgr = plugin.getGlobalRegionManager().get(world); - - // Whoo, for each block - for (Block block : event.blockList()) { - Vector pt = toVector(block); - - if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.TNT)) { - event.setCancelled(true); - return; - } - } - } } /** @@ -567,9 +595,6 @@ public void onExplosionPrime(ExplosionPrimeEvent event) { } ConfigurationManager cfg = plugin.getGlobalStateManager(); - Location l = event.getEntity().getLocation(); - World world = l.getWorld(); - WorldConfiguration wcfg = cfg.get(world); Entity ent = event.getEntity(); if (cfg.activityHaltToggle) { @@ -578,22 +603,6 @@ public void onExplosionPrime(ExplosionPrimeEvent event) { return; } - if (ent instanceof Fireball) { - if (wcfg.blockFireballBlockDamage) { - event.setCancelled(true); - return; - } - - if (wcfg.useRegions) { - Vector pt = toVector(l); - RegionManager mgr = plugin.getGlobalRegionManager().get(world); - - if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.GHAST_FIREBALL)) { - event.setCancelled(true); - return; - } - } - } } /**