summaryrefslogtreecommitdiffstats
path: root/nms-patches/PathfinderGoalTempt.patch
blob: df8f4dcbaf9cf0cbd40f0edaaed995a9210b967e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
--- a/net/minecraft/server/PathfinderGoalTempt.java
+++ b/net/minecraft/server/PathfinderGoalTempt.java
@@ -2,6 +2,12 @@
 
 import com.google.common.collect.Sets;
 import java.util.Set;
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTargetEvent;
+import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
+// CraftBukkit end
 
 public class PathfinderGoalTempt extends PathfinderGoal {
 
@@ -12,7 +18,7 @@
     private double e;
     private double f;
     private double g;
-    private EntityHuman h;
+    private EntityLiving h; // CraftBukkit
     private int i;
     private boolean j;
     private final Set<Item> k;
@@ -39,7 +45,18 @@
             return false;
         } else {
             this.h = this.a.world.findNearbyPlayer(this.a, 10.0D);
-            return this.h == null ? false : this.a(this.h.getItemInMainHand()) || this.a(this.h.getItemInOffHand());
+            // CraftBukkit start
+            // PAIL: rename
+            boolean tempt = this.h == null ? false : this.a(this.h.getItemInMainHand()) || this.a(this.h.getItemInOffHand());
+            if (tempt) {
+                EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent(this.a, this.h, EntityTargetEvent.TargetReason.TEMPT);
+                if (event.isCancelled()) {
+                    return false;
+                }
+                this.h = ((CraftLivingEntity) event.getTarget()).getHandle();
+            }
+            return tempt;
+            // CraftBukkit end
         }
     }