Class GameEndEvent
java.lang.Object
org.bukkit.event.Event
dev.itsharshxd.zentrix.api.events.ZentrixEvent
dev.itsharshxd.zentrix.api.events.ZentrixGameEvent
dev.itsharshxd.zentrix.api.events.game.GameEndEvent
Called when a Zentrix game ends.
This event is fired when a game concludes, either because a winner has been determined or the game was forcibly ended. At this point:
- The winning team/player has been determined (if any)
- Game phases have stopped
- Players are transitioning to end-game state
- Rewards are about to be distributed
This event is NOT cancellable.
Example Usage
@EventHandler
public void onGameEnd(GameEndEvent event) {
ZentrixGame game = event.getGame();
EndReason reason = event.getEndReason();
if (reason == EndReason.WINNER_DETERMINED) {
event.getWinningTeam().ifPresent(team -> {
getLogger().info("Team " + team.getDisplayName() + " won!");
});
// Announce winners
for (ZentrixPlayer winner : event.getWinners()) {
winner.getBukkitPlayer().ifPresent(p -> {
Bukkit.broadcastMessage(p.getName() + " is victorious!");
});
}
}
getLogger().info("Game in " + event.getArenaName() + " ended. " +
"Duration: " + event.getGameDuration() + " seconds");
}
- Since:
- 1.0.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents the reason a game ended.Nested classes/interfaces inherited from class org.bukkit.event.Event
org.bukkit.event.Event.Result -
Constructor Summary
ConstructorsConstructorDescriptionGameEndEvent(@NotNull ZentrixGame game, @NotNull GameEndEvent.EndReason endReason, @Nullable ZentrixTeam winningTeam, @NotNull Collection<ZentrixPlayer> winners, long gameDuration) Constructs a new GameEndEvent. -
Method Summary
Modifier and TypeMethodDescription@NotNull GameEndEvent.EndReasonGets the reason the game ended.@NotNull StringGets the game duration formatted as a human-readable string.longGets the total game duration in seconds.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.intGets the number of winners.@NotNull Collection<ZentrixPlayer> Gets all winning players.@NotNull Optional<ZentrixTeam> Gets the winning team.booleanChecks if there is a winner.booleanChecks if the game was forcibly ended.booleanChecks if the game ended normally with a winner.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
-
GameEndEvent
public GameEndEvent(@NotNull @NotNull ZentrixGame game, @NotNull @NotNull GameEndEvent.EndReason endReason, @Nullable @Nullable ZentrixTeam winningTeam, @NotNull @NotNull Collection<ZentrixPlayer> winners, long gameDuration) Constructs a new GameEndEvent.- Parameters:
game- The game that is endingendReason- The reason the game endedwinningTeam- The winning team (may be null if no winner)winners- The winning players (may be empty if no winners)gameDuration- The total game duration in seconds
-
-
Method Details
-
getEndReason
Gets the reason the game ended.- Returns:
- The end reason (never null)
-
getWinningTeam
Gets the winning team.Returns empty if there is no winner (e.g., game was force-ended or all players left).
- Returns:
- Optional containing the winning team, or empty if no winner
-
getWinners
Gets all winning players.For team games, this includes all members of the winning team. For solo games, this will contain a single player (the winner). Returns an empty collection if there is no winner.
- Returns:
- An unmodifiable collection of winners (never null, may be empty)
-
hasWinner
public boolean hasWinner()Checks if there is a winner.- Returns:
trueif there are winners
-
getGameDuration
public long getGameDuration()Gets the total game duration in seconds.This is the time from when the game entered PLAYING state until this end event was fired.
- Returns:
- Game duration in seconds
-
getFormattedDuration
Gets the game duration formatted as a human-readable string.Examples: "45s", "2m 30s", "1h 15m"
- Returns:
- Formatted duration string (never null)
-
getWinnerCount
public int getWinnerCount()Gets the number of winners.- Returns:
- The winner count
-
isNormalEnd
public boolean isNormalEnd()Checks if the game ended normally with a winner.- Returns:
trueif the game ended with a winner determined
-
isForcedEnd
public boolean isForcedEnd()Checks if the game was forcibly ended.- Returns:
trueif the game was force-ended
-
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
-