Class GameEndEvent

java.lang.Object
org.bukkit.event.Event

public class GameEndEvent extends ZentrixGameEvent
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:
  • 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 ending
      endReason - The reason the game ended
      winningTeam - 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

      @NotNull public @NotNull GameEndEvent.EndReason getEndReason()
      Gets the reason the game ended.
      Returns:
      The end reason (never null)
    • getWinningTeam

      @NotNull public @NotNull Optional<ZentrixTeam> 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

      @NotNull public @NotNull Collection<ZentrixPlayer> 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:
      true if 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

      @NotNull public @NotNull String 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:
      true if the game ended with a winner determined
    • isForcedEnd

      public boolean isForcedEnd()
      Checks if the game was forcibly ended.
      Returns:
      true if the game was force-ended
    • getHandlers

      @NotNull public @NotNull org.bukkit.event.HandlerList getHandlers()
      Gets the handler list for this event.
      Overrides:
      getHandlers in class ZentrixGameEvent
      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