From 35f268319e55c52707c528ba87e29bbd09222705 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 18 Dec 2011 23:16:12 +0100 Subject: [PATCH] Split off ender dragon block damage from creeper block damage. --- .../worldguard/bukkit/WorldConfiguration.java | 2 ++ .../bukkit/WorldGuardEntityListener.java | 21 ++++++++++++++++++- .../protection/flags/DefaultFlag.java | 3 ++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java index ac64eb97..9ca8249f 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java @@ -101,6 +101,7 @@ public class WorldConfiguration { public boolean blockTNTBlockDamage; public boolean blockCreeperExplosions; public boolean blockCreeperBlockDamage; + public boolean blockEnderDragonBlockDamage; public boolean blockFireballExplosions; public boolean blockFireballBlockDamage; // public int loginProtection; @@ -314,6 +315,7 @@ private void loadConfiguration() { blockCreeperExplosions = getBoolean("mobs.block-creeper-explosions", false); blockCreeperBlockDamage = getBoolean("mobs.block-creeper-block-damage", false); + blockEnderDragonBlockDamage = getBoolean("mobs.block-enderdragon-block-damage", false); blockFireballExplosions = getBoolean("mobs.block-fireball-explosions", false); blockFireballBlockDamage = getBoolean("mobs.block-fireball-block-damage", false); antiWolfDumbness = getBoolean("mobs.anti-wolf-dumbness", false); diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java index 98949497..053af57e 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java @@ -31,6 +31,7 @@ import org.bukkit.entity.Creature; import org.bukkit.entity.CreatureType; import org.bukkit.entity.Creeper; +import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Entity; import org.bukkit.entity.Fireball; import org.bukkit.entity.LivingEntity; @@ -543,7 +544,7 @@ public void onEntityExplode(EntityExplodeEvent event) { return; } - if (ent instanceof LivingEntity) { + if (ent instanceof Creeper) { if (wcfg.blockCreeperBlockDamage || wcfg.blockCreeperExplosions) { event.setCancelled(true); return; @@ -561,6 +562,24 @@ public void onEntityExplode(EntityExplodeEvent event) { } } } + } else if (ent instanceof EnderDragon) { + if (wcfg.blockEnderDragonBlockDamage) { + event.setCancelled(true); + return; + } + + if (wcfg.useRegions) { + if (wcfg.useRegions) { + RegionManager mgr = plugin.getGlobalRegionManager().get(world); + + for (Block block : event.blockList()) { + if (!mgr.getApplicableRegions(toVector(block)).allows(DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE)) { + event.setCancelled(true); + return; + } + } + } + } } else if (ent instanceof TNTPrimed) { if (wcfg.blockTNTBlockDamage || wcfg.blockTNTExplosions) { event.setCancelled(true); 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 3fe8b838..e9391589 100644 --- a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java +++ b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java @@ -33,6 +33,7 @@ public final class DefaultFlag { public static final StateFlag MOB_DAMAGE = new StateFlag("mob-damage", 'm', true); public static final StateFlag MOB_SPAWNING = new StateFlag("mob-spawning", true); public static final StateFlag CREEPER_EXPLOSION = new StateFlag("creeper-explosion", 'c', true); + public static final StateFlag ENDERDRAGON_BLOCK_DAMAGE = new StateFlag("enderdragon-block-damage", true); public static final StateFlag GHAST_FIREBALL = new StateFlag("ghast-fireball", true); public static final StateFlag SLEEP = new StateFlag("sleep", true); public static final StateFlag TNT = new StateFlag("tnt", 't', true); @@ -86,7 +87,7 @@ public final class DefaultFlag { PASSTHROUGH, BUILD, PVP, CHEST_ACCESS, PISTONS, TNT, LIGHTER, USE, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP, MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, - CREEPER_EXPLOSION, GHAST_FIREBALL, ENDER_BUILD, + CREEPER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE, EXIT, EXIT_PERM, ENTRY, ENTRY_PERM, HEAL_AMOUNT, HEAL_DELAY, MIN_HEAL, MAX_HEAL,