Getting the entities killer in 1.5.2 with EntityDeathEvent?

Discussion in 'Plugin Development' started by Gawdzahh, Jun 1, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Gawdzahh

    Since they have removed EntityDeathByEntityEvent in the new bukkit releases I have found it very hard to simply get a killer of a entity when they die.

    The only answer I could think of would be to use EntityDamageByEntityEvent and then check against it with EntityDeathEvent to check if the entity died, But thats alot of code just to get the killer of an entity.

    So I have posted this hoping to find someone that knows or can think of a efficient method to getting an entities killer when it dies.
     
  2. Offline

    Minecrell

    Gawdzahh Can't you use something like this?
    Code:java
    1. @EventHandler
    2. public void onEntityDeath(EntityDeathEvent event) {
    3. LivingEntity entity = event.getEntity();
    4. EntityDamageEvent damageEvent = entity.getLastDamageCause();
    5.  
    6. if ((damageEvent != null) && (damageEvent instanceof EntityDamageByEntityEvent)) {
    7. Entity killer = ((EntityDamageByEntityEvent) damageEvent).getDamager();
    8.  
    9. // Now do anything with the entity
    10. }
    11. }
     
    Gawdzahh likes this.
  3. Offline

    Gawdzahh

    Minecrell , Thanks dude... Now lets just see if this works :)
     
Thread Status:
Not open for further replies.

Share This Page