From 3804ba654e0e905f16e19108939877c1e322c4d9 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 1 Jul 2016 11:40:42 +1000 Subject: SPIGOT-1373: Implement EntityTargetEvent for TEMPT. This can be a high frequency event call. Use with care. --- nms-patches/PathfinderGoalTempt.patch | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 nms-patches/PathfinderGoalTempt.patch diff --git a/nms-patches/PathfinderGoalTempt.patch b/nms-patches/PathfinderGoalTempt.patch new file mode 100644 index 00000000..d59fc830 --- /dev/null +++ b/nms-patches/PathfinderGoalTempt.patch @@ -0,0 +1,44 @@ +--- a/net/minecraft/server/PathfinderGoalTempt.java ++++ b/net/minecraft/server/PathfinderGoalTempt.java +@@ -3,6 +3,12 @@ + import com.google.common.collect.Sets; + import java.util.Set; + import javax.annotation.Nullable; ++// 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 { + +@@ -13,7 +19,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 k; +@@ -40,7 +46,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 + } + } + -- cgit v1.2.3