--- a/net/minecraft/world/entity/ai/behavior/StartAttacking.java
+++ b/net/minecraft/world/entity/ai/behavior/StartAttacking.java
@@ -5,12 +5,18 @@
 import java.util.function.Function;
 import java.util.function.Predicate;
 import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
 import net.minecraft.world.entity.LivingEntity;
 import net.minecraft.world.entity.Mob;
 import net.minecraft.world.entity.ai.memory.MemoryModuleType;
 import net.minecraft.world.entity.ai.memory.MemoryStatus;
+import org.bukkit.craftbukkit.v1_19_R1.entity.CraftLivingEntity;
+import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTargetEvent;
+// CraftBukkit end
 
 public class StartAttacking<E extends Mob> extends Behavior<E> {
+
     private final Predicate<E> canAttackPredicate;
     private final Function<E, Optional<? extends LivingEntity>> targetFinderFunction;
 
@@ -25,30 +31,37 @@
     }
 
     public StartAttacking(Function<E, Optional<? extends LivingEntity>> targetGetter) {
-        this((entity) -> {
+        this((entityinsentient) -> {
             return true;
         }, targetGetter);
     }
 
-    @Override
     protected boolean checkExtraStartConditions(ServerLevel world, E entity) {
         if (!this.canAttackPredicate.test(entity)) {
             return false;
         } else {
-            Optional<? extends LivingEntity> optional = this.targetFinderFunction.apply(entity);
-            return optional.isPresent() ? entity.canAttack(optional.get()) : false;
+            Optional<? extends LivingEntity> optional = (Optional) this.targetFinderFunction.apply(entity);
+
+            return optional.isPresent() ? entity.canAttack((LivingEntity) optional.get()) : false;
         }
     }
 
-    @Override
     protected void start(ServerLevel world, E entity, long time) {
-        this.targetFinderFunction.apply(entity).ifPresent((target) -> {
-            setAttackTarget(entity, target);
+        (this.targetFinderFunction.apply(entity)).ifPresent((entityliving) -> { // CraftBukkit - decompile error
+            StartAttacking.setAttackTarget(entity, entityliving);
         });
     }
 
     public static <E extends Mob> void setAttackTarget(E entity, LivingEntity target) {
-        entity.getBrain().setMemory(MemoryModuleType.ATTACK_TARGET, target);
+        // CraftBukkit start
+        EntityTargetEvent event = CraftEventFactory.callEntityTargetLivingEvent(entity, target, (target instanceof ServerPlayer) ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.CLOSEST_ENTITY);
+        if (event.isCancelled()) {
+            return;
+        }
+        target = (event.getTarget() != null) ? ((CraftLivingEntity) event.getTarget()).getHandle() : null;
+        // CraftBukkit end
+
+        entity.getBrain().setMemory(MemoryModuleType.ATTACK_TARGET, target); // CraftBukkit - decompile error
         entity.getBrain().eraseMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE);
     }
 }
