Class PlayerDeathGameEvent
java.lang.Object
org.bukkit.event.Event
dev.itsharshxd.zentrix.api.events.ZentrixEvent
dev.itsharshxd.zentrix.api.events.ZentrixGameEvent
dev.itsharshxd.zentrix.api.events.player.PlayerDeathGameEvent
Called when a player is eliminated (dies) in a Zentrix game.
This event is fired after a player dies and is about to be converted to a spectator. At this point:
- The player has died
- Death message has been prepared
- The player is about to become a spectator
- Team elimination may be triggered if this was the last team member
This event is NOT cancellable.
Example Usage
@EventHandler
public void onPlayerDeath(PlayerDeathGameEvent event) {
ZentrixPlayer victim = event.getVictim();
ZentrixGame game = event.getGame();
// Check if killed by another player
if (event.hasKiller()) {
ZentrixPlayer killer = event.getKiller().get();
getLogger().info(victim.getName() + " was killed by " + killer.getName());
} else {
getLogger().info(victim.getName() + " died to environmental damage");
}
// Check if this death eliminates a team
if (event.eliminatesTeam()) {
event.getVictimTeam().ifPresent(team -> {
game.broadcast("&c" + team.getDisplayName() + " has been eliminated!");
});
}
// Get death location for custom effects
Location deathLoc = event.getDeathLocation();
deathLoc.getWorld().strikeLightningEffect(deathLoc);
}
- Since:
- 1.0.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents the cause of a player's death.Nested classes/interfaces inherited from class org.bukkit.event.Event
org.bukkit.event.Event.Result -
Constructor Summary
ConstructorsConstructorDescriptionPlayerDeathGameEvent(@NotNull ZentrixGame game, @NotNull ZentrixPlayer victim, @Nullable ZentrixPlayer killer, @Nullable ZentrixTeam victimTeam, @NotNull org.bukkit.Location deathLocation, @NotNull PlayerDeathGameEvent.DeathCause deathCause, boolean eliminatesTeam, int remainingPlayers, int remainingTeams) Constructs a new PlayerDeathGameEvent. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if this death could trigger a win condition.booleanChecks if this death eliminates the victim's team.@NotNull PlayerDeathGameEvent.DeathCauseGets the cause of death.@NotNull org.bukkit.LocationGets the location where the player died.static @NotNull org.bukkit.event.HandlerListGets the static handler list for this event type.@NotNull org.bukkit.event.HandlerListGets the handler list for this event.@NotNull Optional<ZentrixPlayer> Gets the player who killed the victim, if any.@NotNull Optional<org.bukkit.entity.Player> Gets the Bukkit player instance of the killer, if any and online.Gets the killer's name, if any.intGets the number of players remaining after this death.intGets the number of teams remaining after this death.longGets the victim's survival time in this game, in seconds.@NotNull ZentrixPlayerGets the player who died.@NotNull Optional<org.bukkit.entity.Player> Gets the Bukkit player instance of the victim, if online.intGets the victim's kill count before dying.@NotNull StringGets the victim's name.@NotNull Optional<ZentrixTeam> Gets the victim's team.booleanChecks if the victim was killed by another player.booleanChecks if this death was caused by border damage.booleanChecks if this death was environmental (not by another player).booleanChecks if this death was caused by another player.booleanChecks if the killer and victim were on the same team.Methods inherited from class dev.itsharshxd.zentrix.api.events.ZentrixGameEvent
getArenaName, getGame, getGameId, getGameState, getGameTypeName, getPlayerCountMethods inherited from class org.bukkit.event.Event
callEvent, getEventName, isAsynchronous
-
Constructor Details
-
PlayerDeathGameEvent
public PlayerDeathGameEvent(@NotNull @NotNull ZentrixGame game, @NotNull @NotNull ZentrixPlayer victim, @Nullable @Nullable ZentrixPlayer killer, @Nullable @Nullable ZentrixTeam victimTeam, @NotNull @NotNull org.bukkit.Location deathLocation, @NotNull @NotNull PlayerDeathGameEvent.DeathCause deathCause, boolean eliminatesTeam, int remainingPlayers, int remainingTeams) Constructs a new PlayerDeathGameEvent.- Parameters:
game- The game where the death occurredvictim- The player who diedkiller- The player who killed the victim (null if environmental death)victimTeam- The victim's team (null if not on a team)deathLocation- The location where the player dieddeathCause- The cause of deatheliminatesTeam- Whether this death eliminates the victim's teamremainingPlayers- The number of players remaining after this deathremainingTeams- The number of teams remaining after this death
-
-
Method Details
-
getVictim
Gets the player who died.- Returns:
- The victim (never null)
-
getKiller
Gets the player who killed the victim, if any.Returns empty if the victim died to environmental damage (fall damage, border damage, drowning, etc.).
- Returns:
- Optional containing the killer, or empty if environmental death
-
hasKiller
public boolean hasKiller()Checks if the victim was killed by another player.- Returns:
trueif there is a killer
-
getVictimBukkit
Gets the Bukkit player instance of the victim, if online.- Returns:
- Optional containing the victim's Bukkit player, or empty if offline
-
getKillerBukkit
Gets the Bukkit player instance of the killer, if any and online.- Returns:
- Optional containing the killer's Bukkit player, or empty if no killer or offline
-
getVictimName
Gets the victim's name.Convenience method equivalent to
getVictim().getName().- Returns:
- The victim's name (never null)
-
getKillerName
Gets the killer's name, if any.- Returns:
- Optional containing the killer's name, or empty if no killer
-
getVictimTeam
Gets the victim's team.- Returns:
- Optional containing the victim's team, or empty if not on a team
-
getDeathLocation
@NotNull public @NotNull org.bukkit.Location getDeathLocation()Gets the location where the player died.Returns a clone to prevent modification of the original location.
- Returns:
- A clone of the death location (never null)
-
getDeathCause
Gets the cause of death.- Returns:
- The death cause (never null)
-
eliminatesTeam
public boolean eliminatesTeam()Checks if this death eliminates the victim's team.Returns true if the victim was the last alive member of their team.
- Returns:
trueif this death eliminates the team
-
getRemainingPlayers
public int getRemainingPlayers()Gets the number of players remaining after this death.- Returns:
- Remaining player count
-
getRemainingTeams
public int getRemainingTeams()Gets the number of teams remaining after this death.- Returns:
- Remaining team count
-
wasPlayerKill
public boolean wasPlayerKill()Checks if this death was caused by another player.- Returns:
trueif killed by another player
-
wasBorderDeath
public boolean wasBorderDeath()Checks if this death was caused by border damage.- Returns:
trueif killed by the border
-
wasEnvironmentalDeath
public boolean wasEnvironmentalDeath()Checks if this death was environmental (not by another player).- Returns:
trueif environmental death
-
getSurvivalTime
public long getSurvivalTime()Gets the victim's survival time in this game, in seconds.- Returns:
- Survival time in seconds
-
getVictimKills
public int getVictimKills()Gets the victim's kill count before dying.- Returns:
- The victim's kill count
-
couldTriggerWin
public boolean couldTriggerWin()Checks if this death could trigger a win condition.Returns true if only one team remains after this death.
- Returns:
trueif this death may end the game
-
wasTeamKill
public boolean wasTeamKill()Checks if the killer and victim were on the same team.This can happen when friendly fire is enabled.
- Returns:
trueif this was a team kill
-
getHandlers
@NotNull public @NotNull org.bukkit.event.HandlerList getHandlers()Gets the handler list for this event.- Overrides:
getHandlersin classZentrixGameEvent- Returns:
- The handler list
-
getHandlerList
@NotNull public static @NotNull org.bukkit.event.HandlerList getHandlerList()Gets the static handler list for this event type.- Returns:
- The handler list
-