PlayerDeathEvent event.getKiller();

Discussion in 'Plugin Development' started by mattrick, Sep 1, 2013.

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

    mattrick

    I am trying to change a death message, but Eclipse is giving me an error because I want to get the Entity that killed the player, not player. Here is my code:
    Code:java
    1. @EventHandler
    2. public void PlayerDeath(PlayerDeathEvent event){
    3. Player player = event.getEntity();
    4. EntityDamageEvent dmgcause = player.getLastDamageCause();
    5. DamageCause dc = dmgcause.getCause();
    6. Entity dmgentity = player.getKiller();
    7. if (dc == DamageCause.CONTACT && dmgentity instanceof Wolf){
    8.  
    9. }

    Is there any way to do this?
     
  2. Offline

    Chinwe

    You may need to listen to EntityDamageEvent instead, and check when the damagee is a player, and that getDamage() is greater than getHealth(), as getKiller() only returns a player :(
     
Thread Status:
Not open for further replies.

Share This Page