Get entity killer when the killer is not a player

Discussion in 'Plugin Development' started by Raxor1234, Aug 5, 2015.

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

    Raxor1234

    Hello, I've been looking around for a bit and can't seem to find it... .getKiller() does not work for what im trying to do. Thanks!
     
  2. Offline

    Eos

    Check if the Entity is not a instanceof a Player.
     
  3. Offline

    SuperOriginal

    Check if getLastDamageCause is instanceof EntityDamageByEntityEvent, if it is, then you can just cast and use getDamager()
     
    Konato_K likes this.
  4. Offline

    Raxor1234

    Sorry I am really new but I am trying to get the killer inside of a EntityDeathEvent, this is my code:

    @EventHandler
    public void onDeath(EntityDeathEvent e){
    if (!(e.getEntity() instanceof Player)){
    e.getEntity.getDamager() ?

    dosent work.
     
  5. @Raxor1234
    (getLastDamageCause() is from Entity)
     
  6. Offline

    mine-care

    @Raxor1234 ^^
    Ninja'ed by @megamichiel

    I see you followed @Eos 's solution, umm what you mean it doesnt work? Is it a compiler error? is it a Runtime error? is it something but not an error? does the code execute in the if? Have you debuged?
     
  7. Offline

    SuperOriginal

    on EntityDeathEvent
    if entity.getLastDamageCause() is a EntityDamageByEntityEvent
    Cast getLastDamageCause() to EntityDamageByEntityEvent
    The killer is EntityDamageByEntityEvent.getDamager()
     
  8. Offline

    Raxor1234

    EntityDamageByEntityEvent cst = (EntityDamageByEntityEvent) e.getEntity().getLastDamageCause();

    is that correct ?

    that returns me the killed entity not the killer... D:
     
    Last edited: Aug 6, 2015
  9. Offline

    SuperOriginal

    cst.getDamager() is the killer, and I hope you're running the proper checks beforehand.
     
  10. Offline

    Raxor1234

    Well. I solved it myself.. I actually found another way to get the killer, im gonna be posting the simple code later when i get home so if other people have the same problem they can solve it.
     
Thread Status:
Not open for further replies.

Share This Page