--- a/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetSet.java
+++ b/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetSet.java
@@ -8,6 +8,13 @@
 import net.minecraft.world.entity.ai.behavior.declarative.BehaviorBuilder;
 import net.minecraft.world.entity.ai.memory.MemoryModuleType;
 
+// CraftBukkit start
+import net.minecraft.server.level.EntityPlayer;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTargetEvent;
+// CraftBukkit end
+
 public class BehaviorAttackTargetSet {
 
     public BehaviorAttackTargetSet() {}
@@ -35,6 +42,17 @@
                             if (!entityinsentient.canAttack(entityliving)) {
                                 return false;
                             } else {
+                                // CraftBukkit start
+                                EntityTargetEvent event = CraftEventFactory.callEntityTargetLivingEvent(entityinsentient, entityliving, (entityliving instanceof EntityPlayer) ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.CLOSEST_ENTITY);
+                                if (event.isCancelled()) {
+                                    return false;
+                                }
+                                if (event.getTarget() == null) {
+                                    memoryaccessor.erase();
+                                    return true;
+                                }
+                                entityliving = ((CraftLivingEntity) event.getTarget()).getHandle();
+                                // CraftBukkit end
                                 memoryaccessor.set(entityliving);
                                 memoryaccessor1.erase();
                                 return true;
