Solved how to get Killer's DisplayName from PlayerDeathEvent?

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

  1. Offline

    Dave_

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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 BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    PlayerDeathEvent is kind of garbage... just sayin'.


    Use EntityDeathEvent
  3. Offline

    messageofdeath

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @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();

    This post has been edited 1 time. It was last edited by messageofdeath Oct 16, 2012.
    Dave_ likes this.
  4. Offline

    ZeusAllMighty11 BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    EntityDeathEvent works fine for me, screw playerdeathevent...
  5. Offline

    messageofdeath

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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_

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Ah ok, I looked over the getKiller() method on the IDE. Thanks for that!
  7. Offline

    Gravity BukkitDev Team Lead Moderator BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I thought you were going to ask how to get the Killer's IP address

Share This Page