Solved Get entity killer

Discussion in 'Plugin Development' started by Condolent, Jun 28, 2014.

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

    Condolent

    So I'm using the EntityDeathEvent and I want to get the killer.
    I read on some places on the forum that you should use entity.getKiller() but it seems like it's been removed :/

    Anyone know what it's replaced with??
     
  2. Offline

    Traks

    Check if the entity is a LivingEntity, then cast the entity to LivingEntity, which gives you access to the getKiller() method.

    Note: LivingEntity#getKiller() only returns players
     
  3. Offline

    Condolent

    Traks Thanks, gonna try soon! I'm making a sort of event if a player kills a zombie so it's only good it returns players :p

    Not entirerly sure how to do this. Tried
    Code:java
    1. if(ent.getType()==EntityType.ZOMBIE) {
    2. if(ent.isDead()) {
    3.  
    4. }
    5. }
    and in there do something like, ent.getKiller() but I can't seem to figure it out :/

    Got it!
    This is how I did it for others experiencing the same problem:
    Code:java
    1. if(e.getEntity() instanceof Zombie) {
    2. String KillerName = e.getEntity().getKiller().getUniqueId().toString();
    3. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page