Solved how to get Killer's DisplayName from PlayerDeathEvent?

Discussion in 'Plugin Development' started by Dave_, Oct 16, 2012.

  1. Offline

    Dave_

    I noticed that they removed getKiller() from the event, or at least i think it used to be there. :/

    Anyways I need to know how to pull the killers display name.

    Code (Text):
    1.     @EventHandler
    2.     public void onPlayerDeath(PlayerDeathEvent event){
    3.         EntityDamageEvent damageEvent = event.getEntity().getLastDamageCause();
    4.         if(!(damageEvent instanceof EntityDamageByEntityEvent))
    5.             return;
    6.         Entity damager = ((EntityDamageByEntityEvent)damageEvent).getDamager();
    7.         if(damager instanceof Player){
    8.             kills = fileHandler.Kills.get(((Player) damager).getDisplayName());
    9.             fileHandler.Kills.put(((Player) damager).getDisplayName(), ++kills);
    10.         }
    11.         deaths = fileHandler.Deaths.get(event.getEntity().getDisplayName());
    12.         fileHandler.Deaths.put(event.getEntity().getDisplayName(), ++deaths);
    13.     }
     
  2. PlayerDeathEvent is kind of garbage... just sayin'.


    Use EntityDeathEvent
     
  3. ZeusAllMighty11
    no

    Dave_

    For this get the Entity which is an instanceOf a Player

    So for this to get there display name use this.

    String killersName = event.getEntity().getKiller().getDisplayName();
     
    Dave_ likes this.
  4. EntityDeathEvent works fine for me, screw playerdeathevent...
     
  5. You have to go through a check for a player in EntityDeathEvent because it could be a mob. If you use PlayerDeathEvent it's already done for you. Plus it will be easier for him because he already has PlayerDeathEvent in his code.
     
  6. Offline

    Dave_

    Ah ok, I looked over the getKiller() method on the IDE. Thanks for that!
     
  7. I thought you were going to ask how to get the Killer's IP address
     
    SimplyCode, Cirno, lol768 and 2 others like this.

Share This Page