--- a/net/minecraft/world/entity/ai/behavior/StartAttacking.java
+++ b/net/minecraft/world/entity/ai/behavior/StartAttacking.java
@@ -27,6 +_,17 @@
                             if (!entity.canAttack(livingEntity)) {
                                 return false;
                             } else {
+                                // CraftBukkit start
+                                org.bukkit.event.entity.EntityTargetEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetLivingEvent(entity, livingEntity, (livingEntity instanceof net.minecraft.server.level.ServerPlayer) ? org.bukkit.event.entity.EntityTargetEvent.TargetReason.CLOSEST_PLAYER : org.bukkit.event.entity.EntityTargetEvent.TargetReason.CLOSEST_ENTITY);
+                                if (event.isCancelled()) {
+                                    return false;
+                                }
+                                if (event.getTarget() == null) {
+                                    memoryAccessor.erase();
+                                    return true;
+                                }
+                                livingEntity = ((org.bukkit.craftbukkit.entity.CraftLivingEntity) event.getTarget()).getHandle();
+                                // CraftBukkit end
                                 memoryAccessor.set(livingEntity);
                                 memoryAccessor1.erase();
                                 return true;
