GameEndEvent
The GameEndEvent is triggered after a TNT Run game finishes and enters the ending phase. At this point, the winner and placements have been calculated, summary messages have been sent, player statistics have been applied, and arena records have been updated.
Technical Overview
Section titled “Technical Overview”- Package:
dev.despical.tntrun.api.event.game - Parent Class:
GameEvent - Cancellable: No
Methods
Section titled “Methods”This event inherits all utility methods from the base GameEvent class and adds methods to retrieve final match results.
| Method | Return Type | Description |
|---|---|---|
getWinner() | User | Returns the User who won the game. Can be null if no winner exists. |
getTop3() | Map<UUID, Integer> | Returns an immutable map containing the UUIDs and final scores of the top 3 players. |
Game State at Conclusion
Section titled “Game State at Conclusion”When this event is called, the game instance is in its ending flow:
- Final Rankings: The
ScoreRegistryhas finalized the winner and top-three results. - Statistic Updates: Wins, losses, streaks, and survival records have already been applied.
- Player Status: Players remain in the game until the ending timer finishes or they leave.
Example Usage
Section titled “Example Usage”This example demonstrates how to reward the winner and log the top 3 results.
import dev.despical.tntrun.api.event.game.GameEndEvent;import dev.despical.tntrun.user.User;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;
public class GameRewardListener implements Listener {
@EventHandler public void onGameEnd(GameEndEvent event) { User winner = event.getWinner();
if (winner != null) { Player player = winner.getPlayer(); if (player != null) { player.giveExpLevels(1); player.sendMessage("You won this TNT Run match!"); } }
event.getTop3().forEach((uuid, score) -> { System.out.println("TNT Run podium: " + uuid + " with " + score + " points."); }); }}