Detect When A Player Kills Another Player?

Discussion in 'Spigot Plugin Development' started by SamB440, Jun 8, 2015.

  1. Hi, I'd like to know how I can detect when a player kills another player, And have it execute a server command afterwards.


  2. listen to the player death event, check for #Player.getKiller(), make sure it's not null, make sure it's an instance of Player, make sure it's not the player killing themselves, run your command
    • Funny Funny x 1
    • Useful Useful x 1
  3. In other words. Use the PlayerDeathEvent. Check the killer, if it's InstanceOf Player then check if the
    Code (Text):
    player.getKiller() == null)
    If it's not null then run your command
    Code (Text):
    player.sendMessage("You have been killed by: " + player.getKiller());
  4. Thanks guys. I'll try this out!