-
Bug
-
Resolution: Fixed
-
Minor
-
None
-
None
-
None
When directly attacking a mob, EntityTargetEvent will fire with TargetReason.TARGET_ATTACKED_NEARBY_ENTITY.
Based on the API docs, the correct result for this case should be TargetReason.TARGET_ATTACKED_ENTITY.
Steps:
1) Run fresh Spigot install with one plugin, using the listener below
2) Log in and use /summon Zombie
3) Punch the zombie
Result: EntityTargetEvent fires with TargetReason.TARGET_ATTACKED_NEARBY_ENTITY.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) public void onEntityTargetEvent(EntityTargetEvent event) { if (event.getReason() == TargetReason.CLOSEST_PLAYER) { event.setCancelled(true); } getLogger().info("EntityTargetEvent: " + event.getReason() + " " + "Cancelled: " + event.isCancelled()); }
[SpigotTest] EntityTargetEvent: CLOSEST_PLAYER Cancelled: true
[SpigotTest] EntityTargetEvent: CLOSEST_PLAYER Cancelled: true
[SpigotTest] EntityTargetEvent: TARGET_ATTACKED_NEARBY_ENTITY Cancelled: false
It is necessary to cancel TargetReason.CLOSEST_PLAYER so that you can hit the mob before it has already targeted you.