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

    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:
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            EntityDamageEvent damageEvent = event.getEntity().getLastDamageCause();
            if(!(damageEvent instanceof EntityDamageByEntityEvent))
                return;
            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. Offline

    ZeusAllMighty11

    PlayerDeathEvent is kind of garbage... just sayin'.


    Use EntityDeathEvent
     
  3. Offline

    messageofdeath

    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. Offline

    ZeusAllMighty11

    EntityDeathEvent works fine for me, screw playerdeathevent...
     
  5. Offline

    messageofdeath

    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. Offline

    Gravity

    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