summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-11-04 16:45:02 +0000
committerKHobbits <rob@khobbits.co.uk>2012-11-04 16:45:02 +0000
commit6f1a70dc8bc4fca8098c972c2c9ff10bad711826 (patch)
tree3e26b87ee49e13ee54aabd60148941daecc24ea4 /EssentialsProtect
parent7369155166d5644c8e14ab8646d752221c47036e (diff)
downloadEssentials-6f1a70dc8bc4fca8098c972c2c9ff10bad711826.tar
Essentials-6f1a70dc8bc4fca8098c972c2c9ff10bad711826.tar.gz
Essentials-6f1a70dc8bc4fca8098c972c2c9ff10bad711826.tar.lz
Essentials-6f1a70dc8bc4fca8098c972c2c9ff10bad711826.tar.xz
Essentials-6f1a70dc8bc4fca8098c972c2c9ff10bad711826.zip
Fix missing mob target block
Diffstat (limited to 'EssentialsProtect')
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java102
1 files changed, 39 insertions, 63 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
index a0d1a48f9..1ca9519ce 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
@@ -38,33 +38,27 @@ public class EssentialsProtectEntityListener implements Listener
}
final User user = ess.getUser(target);
+ final DamageCause cause = event.getCause();
+
if (event instanceof EntityDamageByBlockEvent)
{
- final DamageCause cause = event.getCause();
-
if (prot.getSettingBool(ProtectConfig.disable_contactdmg)
&& cause == DamageCause.CONTACT
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.contact")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && !(target instanceof Player && shouldBeDamaged(user, "contact")))
{
event.setCancelled(true);
return;
}
if (prot.getSettingBool(ProtectConfig.disable_lavadmg)
&& cause == DamageCause.LAVA
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.lava")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && !(target instanceof Player && shouldBeDamaged(user, "lava")))
{
event.setCancelled(true);
return;
}
if (prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)
&& cause == DamageCause.BLOCK_EXPLOSION
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.tnt")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && !(target instanceof Player && shouldBeDamaged(user, "tnt")))
{
event.setCancelled(true);
return;
@@ -77,58 +71,43 @@ public class EssentialsProtectEntityListener implements Listener
final Entity eAttack = edEvent.getDamager();
final User attacker = ess.getUser(eAttack);
- // PVP Settings
- if (target instanceof Player && eAttack instanceof Player
- && prot.getSettingBool(ProtectConfig.disable_pvp)
- && (!user.isAuthorized("essentials.protect.pvp") || !attacker.isAuthorized("essentials.protect.pvp")))
- {
- event.setCancelled(true);
- return;
- }
-
//Creeper explode prevention
- if (eAttack instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.creeper")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ if (eAttack instanceof Creeper
+ && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
+ || prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg))
+ && !(target instanceof Player && shouldBeDamaged(user, "creeper")))
{
event.setCancelled(true);
return;
}
- if (eAttack instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg)
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.creeper")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
+ && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg)
+ && !(target instanceof Player && shouldBeDamaged(user, "fireball")))
{
event.setCancelled(true);
return;
}
- if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
- && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg)
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.fireball")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ if (event.getEntity() instanceof WitherSkull
+ && prot.getSettingBool(ProtectConfig.prevent_witherskull_playerdmg)
+ && !(target instanceof Player && shouldBeDamaged(user, "witherskull")))
{
event.setCancelled(true);
return;
}
-
- if ((event.getEntity() instanceof WitherSkull
- && prot.getSettingBool(ProtectConfig.prevent_witherskull_playerdmg)
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.witherskull")
- && !user.isAuthorized("essentials.protect.damage.disable"))))
+
+ if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg)
+ && !(target instanceof Player && shouldBeDamaged(user, "tnt")))
{
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")))
+ // PVP Settings
+ if (target instanceof Player && eAttack instanceof Player
+ && prot.getSettingBool(ProtectConfig.disable_pvp)
+ && (!user.isAuthorized("essentials.protect.pvp") || !attacker.isAuthorized("essentials.protect.pvp")))
{
event.setCancelled(true);
return;
@@ -136,9 +115,7 @@ public class EssentialsProtectEntityListener implements Listener
if (edEvent.getDamager() instanceof Projectile
&& target instanceof Player
- && ((prot.getSettingBool(ProtectConfig.disable_projectiles)
- && !(user.isAuthorized("essentials.protect.damage.projectiles")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && ((prot.getSettingBool(ProtectConfig.disable_projectiles) && !shouldBeDamaged(user, "projectiles"))
|| (((Projectile)edEvent.getDamager()).getShooter() instanceof Player
&& prot.getSettingBool(ProtectConfig.disable_pvp)
&& (!user.isAuthorized("essentials.protect.pvp")
@@ -149,13 +126,11 @@ public class EssentialsProtectEntityListener implements Listener
}
}
- final DamageCause cause = event.getCause();
if (target instanceof Player)
{
if (cause == DamageCause.FALL
&& prot.getSettingBool(ProtectConfig.disable_fall)
- && !(user.isAuthorized("essentials.protect.damage.fall")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && !shouldBeDamaged(user, "fall"))
{
event.setCancelled(true);
return;
@@ -163,41 +138,35 @@ public class EssentialsProtectEntityListener implements Listener
if (cause == DamageCause.SUFFOCATION
&& prot.getSettingBool(ProtectConfig.disable_suffocate)
- && !(user.isAuthorized("essentials.protect.damage.suffocation")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && !shouldBeDamaged(user, "suffocation"))
{
event.setCancelled(true);
return;
}
- if ((cause == DamageCause.FIRE
- || cause == DamageCause.FIRE_TICK)
+ if ((cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK)
&& prot.getSettingBool(ProtectConfig.disable_firedmg)
- && !(user.isAuthorized("essentials.protect.damage.fire")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && !shouldBeDamaged(user, "fire"))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.DROWNING
&& prot.getSettingBool(ProtectConfig.disable_drown)
- && !(user.isAuthorized("essentials.protect.damage.drowning")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && !shouldBeDamaged(user, "drowning"))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.LIGHTNING
&& prot.getSettingBool(ProtectConfig.disable_lightning)
- && !(user.isAuthorized("essentials.protect.damage.lightning")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && !shouldBeDamaged(user, "lightning"))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.WITHER
&& prot.getSettingBool(ProtectConfig.disable_wither)
- && !(user.isAuthorized("essentials.protect.damage.wither"))
- && !user.isAuthorized("essentials.protect.damage.disable"))
+ && !shouldBeDamaged(user, "wither"))
{
event.setCancelled(true);
return;
@@ -205,6 +174,12 @@ public class EssentialsProtectEntityListener implements Listener
}
}
+ private boolean shouldBeDamaged(final User user, final String type)
+ {
+ return (user.isAuthorized("essentials.protect.damage.".concat(type))
+ && !user.isAuthorized("essentials.protect.damage.disable"));
+ }
+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityExplode(final EntityExplodeEvent event)
{
@@ -253,12 +228,12 @@ public class EssentialsProtectEntityListener implements Listener
return;
}
else if ((event.getEntity() instanceof WitherSkull)
- && prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion))
+ && prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion))
{
event.setCancelled(true);
return;
}
-
+
// This code will prevent explosions near protected rails, signs or protected chests
// TODO: Use protect db instead of this code
@@ -325,6 +300,7 @@ public class EssentialsProtectEntityListener implements Listener
|| event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY
|| event.getReason() == TargetReason.PIG_ZOMBIE_TARGET
|| event.getReason() == TargetReason.RANDOM_TARGET
+ || event.getReason() == TargetReason.DEFEND_VILLAGE
|| event.getReason() == TargetReason.TARGET_ATTACKED_OWNER
|| event.getReason() == TargetReason.OWNER_ATTACKED_TARGET)
&& prot.getSettingBool(ProtectConfig.prevent_entitytarget)