I want to program a listener. As soon as a player dies there should be a message saying that he is dying. Well I have a code but errors come out of it.
Code:
@EventHandler
public void onEDeath (EntityDeathEvent e) {
if (e.getEntity (). GetKiller ()! = null) {
Player player = (Player) e.getEntity ();
Player player2 = e.getEntity (). GetKiller ();
Bukkit.broadcastMessage ("§e" + player.getName () + "§7 was killed by §e" + player2.getName () + "§7.");
} else {
Player player = (Player) e.getEntity ();
Bukkit.broadcastMessage ("§e" + player.getName () + "§7is dead.");
}
}
The else method bring errors.
Can someone send me a code?
This is the wrong event.
The correct one is called "PlayerDeathEvent".
And another tip: do not broadcast, replace the death message, otherwise both will come.
Replace EntityDeathEvent with PlayerDeathEvent