Class PlayerLeaveGameEvent
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.PlayerLeaveGameEvent
Called when a player leaves a Zentrix game.
This event is fired after a player has left the game, either by:
- Using the leave command
- Disconnecting from the server
- Being kicked
- Being eliminated (death)
This event is NOT cancellable - the player has already left.
Example Usage
@EventHandler
public void onPlayerLeaveGame(PlayerLeaveGameEvent event) {
ZentrixPlayer player = event.getPlayer();
ZentrixGame game = event.getGame();
LeaveReason reason = event.getReason();
switch (reason) {
case DEATH -> getLogger().info(player.getName() + " was eliminated");
case QUIT -> getLogger().info(player.getName() + " disconnected");
case COMMAND -> getLogger().info(player.getName() + " left voluntarily");
case KICK -> getLogger().info(player.getName() + " was kicked");
}
// Check remaining players
int remaining = event.getRemainingPlayers();
game.broadcast("&7" + remaining + " players remain!");
// Check if this triggers a win condition
if (event.couldTriggerWin()) {
getLogger().info("This leave may end the game!");
}
}
- Since:
- 1.0.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents the reason a player left a game.Nested classes/interfaces inherited from class org.bukkit.event.Event
org.bukkit.event.Event.Result -
Constructor Summary
ConstructorsConstructorDescriptionPlayerLeaveGameEvent(@NotNull ZentrixGame game, @NotNull ZentrixPlayer player, @Nullable ZentrixTeam team, @NotNull PlayerLeaveGameEvent.LeaveReason reason, int remainingPlayers, int remainingTeams, int playerKills, long survivalTime) Constructs a new PlayerLeaveGameEvent. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if this leave could trigger a win condition.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 ZentrixPlayerGets the player who is leaving the game.intGets the player's kill count at the time of leaving.@NotNull StringGets the player's name.@NotNull PlayerLeaveGameEvent.LeaveReasonGets the reason the player left the game.intGets the number of players remaining after this leave.intGets the number of teams remaining after this leave.longGets the player's survival time in seconds.@NotNull Optional<ZentrixTeam> getTeam()Gets the player's team at the time of leaving.booleanhadKills()Checks if the player had any kills before leaving.booleanwasDeath()Checks if the player left due to death/elimination.booleanChecks if the player left due to disconnecting.booleanChecks if the player was kicked.booleanChecks if the player left voluntarily (by command).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
-
PlayerLeaveGameEvent
public PlayerLeaveGameEvent(@NotNull @NotNull ZentrixGame game, @NotNull @NotNull ZentrixPlayer player, @Nullable @Nullable ZentrixTeam team, @NotNull @NotNull PlayerLeaveGameEvent.LeaveReason reason, int remainingPlayers, int remainingTeams, int playerKills, long survivalTime) Constructs a new PlayerLeaveGameEvent.- Parameters:
game- The game the player is leavingplayer- The player who is leavingteam- The player's team (may be null if not on a team)reason- The reason for leavingremainingPlayers- The number of players remaining after this leaveremainingTeams- The number of teams remaining after this leaveplayerKills- The player's kill count when leavingsurvivalTime- The player's survival time in seconds
-
-
Method Details
-
getPlayer
Gets the player who is leaving the game.- Returns:
- The player (never null)
-
getPlayerName
Gets the player's name.Convenience method equivalent to
getPlayer().getName().- Returns:
- The player's name (never null)
-
getTeam
Gets the player's team at the time of leaving.Returns empty if the player was not assigned to a team.
- Returns:
- Optional containing the team, or empty if no team
-
getReason
Gets the reason the player left the game.- Returns:
- The leave reason (never null)
-
wasVoluntary
public boolean wasVoluntary()Checks if the player left voluntarily (by command).- Returns:
trueif the player used a leave command
-
wasDeath
public boolean wasDeath()Checks if the player left due to death/elimination.- Returns:
trueif the player was eliminated
-
wasDisconnect
public boolean wasDisconnect()Checks if the player left due to disconnecting.- Returns:
trueif the player disconnected
-
wasKicked
public boolean wasKicked()Checks if the player was kicked.- Returns:
trueif the player was kicked
-
getRemainingPlayers
public int getRemainingPlayers()Gets the number of players remaining after this leave.- Returns:
- Remaining player count
-
getRemainingTeams
public int getRemainingTeams()Gets the number of teams remaining after this leave.- Returns:
- Remaining team count
-
getPlayerKills
public int getPlayerKills()Gets the player's kill count at the time of leaving.- Returns:
- The player's kills in this game
-
getSurvivalTime
public long getSurvivalTime()Gets the player's survival time in seconds.Measured from game start (PLAYING state) until leaving.
- Returns:
- Survival time in seconds
-
couldTriggerWin
public boolean couldTriggerWin()Checks if this leave could trigger a win condition.Returns true if only one team/player remains after this leave.
- Returns:
trueif this leave may end the game
-
hadKills
public boolean hadKills()Checks if the player had any kills before leaving.- Returns:
trueif the player got at least one 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
-