1.12.2 Get the attacker from an EntityDamageEvent if there is one?

Discussion in 'Spigot Plugin Development' started by AtomIsHere, Jan 15, 2020.

  1. I know EntityDamagedByEntityEvent exists however I need a way to get the attacker from EntityDamageEvent. I realised that EntityDamagedByEntityEvent extends EntityDamageEvent so can I just to see if EntityDamageEvent is an instance of it?
     
  2. I think it’s better to use the EntityDamageByEntityEvent and manage it separately from simple damaging.
     
  3. I have code that is run when a player is damaged, and that code needs a check to see if an entity, or in my case, player caused that damage.
    https://hastebin.com/pepejiyicu.cs here is my code for reference.
     
  4. if(event instanceof EntityDamageByEntityEvent)
    Entity attacker = ((EntityDamageByEntityEvent)event).getDamager()
     
    • Like Like x 1