Solved Get Killer on PlayerDeathEvent (1.10)??

Discussion in 'Spigot Plugin Development' started by NovaFox161, Jun 28, 2016.

  1. Well, I ran into an interesting issue with PlayerDeathEvent and EntityDeathEvent.

    I am working on a minigame plugin and need to listen to the PlayerDeathEvent to make sure the player is out, I need to get the killer and if they are a player, do stuff with them, but PlayerDeathEvent doesn't have a getKiller() method anymore??

    For Bukkit and Spigot 1.9 it has the getKiller() method, but in the latest 1.10 it doesn't. It's just gone.
    Checked on the JavaDocs and found nothing (event in EntityDeathEvent).

    Anyone know what this is about and a way to get the killer in 1.10??

    Code from a 1.9 plugin I made:
    Code (Text):
    public void onPlayerDeath(PlayerDeathEvent event) {
            Player player = event.getEntity();
            if (ArenaManager.getManager().isInGame(player)) {
                Arena arena = ArenaManager.getManager().getArena(player);
                if (arena.getStatus().equals(ArenaStatus.INGAME)) {
                    if (player.getKiller() != null) {
                        if (player.getKiller() instanceof Player) {
                            //Do stuff here
                        }
                    }
                }
            }
        }
    And then code from the 1.10 plugin (without getKiller() because it doesn't exist):
    Code (Text):
    public void onDeath(PlayerDeathEvent event) {
            if (ArenaManager.getManager().isInGame(event.getEntity())) {
                if (event.getDeathMessage() != null) {
                    event.setDeathMessage(null);
                }
                //Player is out because they died. Respawn listener will handle the rest.
            } else if (ArenaManager.getManager().isSpectating(event.getEntity())) {
                //Arena spectator died somehow.
                if (event.getDeathMessage() != null) {
                    event.setDeathMessage(null);
                }
                event.setKeepInventory(true);
                event.setDroppedExp(0);
                event.setKeepLevel(true);
                //Respawn listener will teleport them back to the right place
            }
        }

    Thanks for any help!
     
  2. player.getKiller();
     
  3. You know it's Entity#getKiller() and not EntityDeathEvent#getKiller() right? It's always been that way, even in your code.
     
  4. oh my god..... Well thank you. Sometimes you just have those dumb moments. Well, thank you for pointing that out. I sorta just had a brain fart.
     
  5. Code (Text):
    @EventHandler
        public void onDeath(PlayerDeathEvent event) {
            if ((event.getEntity() instanceof Player)) {
                Player player = event.getEntity();
                Player killer = player.getKiller();
            }
        }