Solved how to get Killer's DisplayName from PlayerDeathEvent?

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

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


    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.

        public void onPlayerDeath(PlayerDeathEvent event){
            EntityDamageEvent damageEvent = event.getEntity().getLastDamageCause();
            if(!(damageEvent instanceof EntityDamageByEntityEvent))
            Entity damager = ((EntityDamageByEntityEvent)damageEvent).getDamager();
            if(damager instanceof Player){
                kills = fileHandler.Kills.get(((Player) damager).getDisplayName());
                fileHandler.Kills.put(((Player) damager).getDisplayName(), ++kills);
            deaths = fileHandler.Deaths.get(event.getEntity().getDisplayName());
            fileHandler.Deaths.put(event.getEntity().getDisplayName(), ++deaths);
  2. PlayerDeathEvent is kind of garbage... just sayin'.

    Use EntityDeathEvent
  3. ZeusAllMighty11


    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


    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.
Thread Status:
Not open for further replies.

Share This Page