How to see if player death is caused by entity?

Discussion in 'Plugin Development' started by Lolmewn, May 31, 2012.

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

    Lolmewn

    So, I'm having a problem. How can I see, using onPlayerDeath btw, if an entity killed the player? And not for example by falling to death?

    ~Mewn
     
  2. Offline

    BobbyD441

    try:
    Code:
    public void onPlayerDeath(PlayerDeathEvent event)
        {
            //A player died
            Player player = event.getEntity();
            if(player.getKiller() instanceof LivingEntity)
            {
                   //Do stuff here
            }
    }
     
  3. Offline

    Lolmewn

    BobbyD441
    I saw that, however, getKiller() returns a Player. What if it's a skeleton?
     
  4. Offline

    BobbyD441

    In that case you could use the getLastDamageCause() =)
     
  5. Offline

    Lolmewn

    Actually, I found this working:
    Code:
    @EventHandler(priority = EventPriority.MONITOR)
        public void onPlayerDeath(PlayerDeathEvent event){
            EntityDamageEvent e = event.getEntity().getLastDamageCause();
            if(e instanceof EntityDamageByEntityEvent){
                this.plugin.debug("Yep!");
            }
        }
     
Thread Status:
Not open for further replies.

Share This Page