summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect/src/com/earth2me
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsProtect/src/com/earth2me')
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java1
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java22
2 files changed, 23 insertions, 0 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
index 3a041413f..d66fcca12 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
@@ -55,6 +55,7 @@ public class EssentialsProtect extends JavaPlugin
pm.registerEvent(Type.BLOCK_BURN, blockListener, Priority.Highest, this);
pm.registerEvent(Type.ENTITY_EXPLODE, entityListener, Priority.Highest, this);
pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Highest, this);
+ pm.registerEvent(Type.ENTITY_TARGET, entityListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
pm.registerEvent(Type.CREATURE_SPAWN, entityListener, Priority.Highest, this);
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
index 29118bdfb..cb7d8ed1c 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
@@ -27,6 +27,8 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
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;
public class EssentialsProtectEntityListener extends EntityListener
@@ -234,4 +236,24 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true);
}
}
+
+ @Override
+ public void onEntityTarget(EntityTargetEvent event) {
+ if (!(event.getTarget() instanceof Player)) {
+ return;
+ }
+ User user = User.get(event.getTarget());
+ if ((event.getReason() == TargetReason.CLOSEST_PLAYER ||
+ event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY ||
+ event.getReason() == TargetReason.PIG_ZOMBIE_TARGET) &&
+ EssentialsProtect.guardSettings.get("protect.prevent.entitiytarget") &&
+ !user.isAuthorized("essentials.protect.entitytarget.bypass")
+ )
+ {
+ event.setCancelled(true);
+ return;
+ }
+ }
+
+
}