summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect/src/com
diff options
context:
space:
mode:
authorsnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-04-07 20:32:00 +0000
committersnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-04-07 20:32:00 +0000
commit79bd8d0b2c49efc23163e3eb8c43f622242e8ee9 (patch)
treea4a980207cc699395af958325bd65e6396a831ea /EssentialsProtect/src/com
parent5dcb5e02fb19040986eea8cb09604ba941cf30af (diff)
downloadEssentials-79bd8d0b2c49efc23163e3eb8c43f622242e8ee9.tar
Essentials-79bd8d0b2c49efc23163e3eb8c43f622242e8ee9.tar.gz
Essentials-79bd8d0b2c49efc23163e3eb8c43f622242e8ee9.tar.lz
Essentials-79bd8d0b2c49efc23163e3eb8c43f622242e8ee9.tar.xz
Essentials-79bd8d0b2c49efc23163e3eb8c43f622242e8ee9.zip
[trunk] Monster don't target players.
new config: protect.prevent.entitytarget new permission: essentials.protect.entitytarget.bypass git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1145 e251c2fe-e539-e718-e476-b85c1f46cddb
Diffstat (limited to 'EssentialsProtect/src/com')
-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;
+ }
+ }
+
+
}