Solved EntityDeathEvent getting killer

Discussion in 'Spigot Plugin Development' started by Qruet, Jun 8, 2017.

  1. I'm aware of
    Code (Text):
    Entity killer = event.getEntity().getKiller();
    , however it appears that it only gets the killer if it's a player. I'm trying to check to see if two entities, specifically wolves, kill one another. It goes as far as checking to see if the entity that died (victim) is a wolf but when it checks to see if the killer is instanceof Wolf it doesn't seem to properly execute. As far as I understand getKiller() only works when the LivingEntity is instanceof of a Player entity. Wondering if there's another approach to doing this. As the title suggests, I'm listening for the EntityDeathEvent.
    ~Geekles
     
  2. Listen to the entity damage by entity event instead.
     
  3. What do you mean exactly? Like check to see if the entity damaged is dead? I tried it and it appears that it also doesn't work.

    Code (Text):
        @EventHandler
        public void petDamage(EntityDamageByEntityEvent event){
            Entity damager = event.getDamager();
            Entity victim = event.getEntity();
            if(isPixie(victim) == true){
                    Wolf pixie1 = (Wolf) victim;
                     //stuff
                 }
                            if(pixie1.isDead() == true){
                                                   
                             Bukkit.broadcastMessage("A pixie died!");
                     }
    ~Geekles
     
  4. Not that it's dead. Check if the amount of damage being dealt is equal or more than it's health. If it is, then this is the killing blow, and you have access to the killer even if it's not a player.
     
  5. Ah cool, thanks, got it working now.
    ~Geekles