Hello guys, i searched how get the killer of a player with PlayerDeathEvent, i didn’t find any topic talking about this.
So I wonder if it is possible at the moment to get the killer of a player or an entity.
I searched with “event.getCause()” but I didn’t find anything about this
Or, you could use Cause#getCause(), like was originally suggested.
@Subscribe public void onPlayerDeath(PlayerDeathEvent event) {
Cause cause = event.getCause();
if (cause instanceof Player) {
// Killer was player.
}
}
@Subscribe public void onPlayerDeath(PlayerDeathEvent event) {
Cause cause = event.getCause();
if(cause.getCause() instanceof Player){
//Killer was player
}
}
event.getCause gets you the Cause container. Cause.getCause() gets you the object that caused this event.
This is starting to get unwieldly, Getting the player who killed another player in a death event would be a decent helper method to have.
Having getCause(Player.class) automatically scan the cause hierarchy for a responsible player would be extremely useful.
Would be the owner of players, detenator of tnt if available, placer of lava if available, and just all around be useful to have in the API.
OvercastNetworks Tracker previously did a lot of work in order to track the cause of player deaths it would be useful if similar trackers were in Sponge.