Getting the Player that killed an Entity

Discussion in 'Plugin Development' started by finalblade1234, May 3, 2013.

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

    finalblade1234

    How do i get the player that killed the Entity in EntityDeathEvent?
     
  2. Offline

    MP5K

    Hello finalblade1234,
    You could use the EntityDamageByEntityEvent and check if the entity is dying (if live - damage == 0).
     
  3. Offline

    EcMiner

    I think you could do like

    Code:java
    1.  
    2. Entity ent = event.getEntity();
    3. Player killer = ent.getKiller();
    4.  
     
  4. Offline

    Compressions

  5. Offline

    LucasEmanuel

    In pseudo

    Code:
    listen to EntityDeathEvent:
      if event.getEntity.getKiller instanceof Player:
        # do something
    This will work with any animal/player if the animal/player was killed by a player. :)
     
  6. Offline

    Hollasch

    Code:java
    1. @EventHandler
    2. public void playerKillEntity(EntityDeathEvent event)
    3. {
    4. LivingEntity e = event.getEntity();
    5. Player killer = e.getKiller();
    6. }
     
Thread Status:
Not open for further replies.

Share This Page