From 3d232e13d9c30284a83e4df2c3e4d62fd22f2950 Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 18 Jul 2011 07:22:28 +0200 Subject: [PATCH] New config settings for Protect: protect.prevent.tnt-playerdamage protect.prevent.fireball-fire protect.prevent.fireball-playerdamage --- Essentials/src/config.yml | 3 ++ .../essentials/protect/EssentialsProtect.java | 1 + .../EssentialsProtectEntityListener.java | 31 +++++++++++++++++++ .../essentials/protect/ProtectConfig.java | 3 ++ 4 files changed, 38 insertions(+) diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 9505a7646..7aaec6027 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -342,7 +342,10 @@ protect: lightning-fire-spread: true portal-creation: false tnt-explosion: false + tnt-playerdamage: false fireball-explosion: false + fireball-fire: false + fireball-playerdamage: false creeper-explosion: false creeper-playerdamage: false creeper-blockdamage: false diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java index 53843843f..216a37564 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java @@ -53,6 +53,7 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Highest, this); pm.registerEvent(Type.CREATURE_SPAWN, entityListener, Priority.Highest, this); pm.registerEvent(Type.ENTITY_TARGET, entityListener, Priority.Highest, this); + pm.registerEvent(Type.EXPLOSION_PRIME, entityListener, Priority.Highest, this); final EssentialsProtectWeatherListener weatherListener = new EssentialsProtectWeatherListener(this); pm.registerEvent(Type.LIGHTNING_STRIKE, weatherListener, Priority.Highest, this); diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index ceb72bd8d..a71bcbd09 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -18,8 +18,10 @@ import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.entity.CraftTNTPrimed; import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; +import org.bukkit.entity.Fireball; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -30,6 +32,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityListener; import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.EntityTargetEvent.TargetReason; +import org.bukkit.event.entity.ExplosionPrimeEvent; public class EssentialsProtectEntityListener extends EntityListener @@ -118,6 +121,24 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); return; } + + if (eAttack instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg) + && !(target instanceof Player + && user.isAuthorized("essentials.protect.damage.fireball") + && !user.isAuthorized("essentials.protect.damage.disable"))) + { + event.setCancelled(true); + return; + } + + if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg) + && !(target instanceof Player + && user.isAuthorized("essentials.protect.damage.tnt") + && !user.isAuthorized("essentials.protect.damage.disable"))) + { + event.setCancelled(true); + return; + } } if (event instanceof EntityDamageByProjectileEvent @@ -314,4 +335,14 @@ public class EssentialsProtectEntityListener extends EntityListener return; } } + + @Override + public void onExplosionPrime(ExplosionPrimeEvent event) + { + if (event.getEntity() instanceof CraftFireball + && prot.getSettingBool(ProtectConfig.prevent_fireball_fire)) + { + event.setFire(false); + } + } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java index 12b7c9fd9..9959db8c6 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java @@ -32,7 +32,10 @@ public enum ProtectConfig prevent_portal_creation("protect.prevent.portal-creation", false), prevent_block_on_rail("protect.protect.prevent-block-on-rails", false), prevent_tnt_explosion("protect.prevent.tnt-explosion", false), + prevent_tnt_playerdmg("protect.prevent.tnt-playerdamage", false), prevent_fireball_explosion("protect.prevent.fireball-explosion", false), + prevent_fireball_fire("protect.prevent.fireball-fire", false), + prevent_fireball_playerdmg("protect.prevent.fireball-playerdamage", false), prevent_creeper_explosion("protect.prevent.creeper-explosion", true), prevent_creeper_playerdmg("protect.prevent.creeper-playerdamage", false), prevent_creeper_blockdmg("protect.prevent.creeper-blockdamage", false),