GameStateChangeEvent
The GameStateChangeEvent is triggered immediately before a TNT Run game transitions between states, such as from WAITING to STARTING. This event allows developers to inspect the transition and, if necessary, cancel it to prevent the state from changing.
Technical Overview
Section titled “Technical Overview”- Package:
dev.despical.tntrun.api.event.game - Parent Class:
GameEvent - Cancellable: Yes
Methods
Section titled “Methods”In addition to the methods inherited from GameEvent, this event provides access to both the current and proposed game states.
| Method | Return Type | Description |
|---|---|---|
getOldState() | GameState | Returns the current state of the game before the transition. |
getNewState() | GameState | Returns the state the game is attempting to enter. |
isCancelled() | boolean | Checks if the state transition has been blocked. |
setCancelled(boolean) | void | Set to true to stop the game from changing states. |
Available Game States
Section titled “Available Game States”The game typically cycles through the following states:
WAITING: Players are joining the lobby.STARTING: The countdown before active gameplay has begun.IN_GAME: Blocks are being removed and players are surviving.ENDING: The game has finished and results are being displayed.RESTARTING: The arena is cleaning up and resetting.INACTIVE: The arena is not currently available as an active game.
Example Usage
Section titled “Example Usage”Blocking a Game Start
Section titled “Blocking a Game Start”You can use this to prevent a game from starting if external conditions are not met.
import dev.despical.tntrun.api.event.game.GameStateChangeEvent;import dev.despical.tntrun.game.GameState;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;
public class StateLockListener implements Listener {
@EventHandler public void onStateChange(GameStateChangeEvent event) { if (event.getNewState() == GameState.IN_GAME && isGlobalLockActive()) { event.setCancelled(true); event.getGame().broadcast("The game cannot start right now!"); } }}Updating UI Before Transition
Section titled “Updating UI Before Transition”Trigger logic exactly when a game moves into the ending phase.
@EventHandlerpublic void onGameEnding(GameStateChangeEvent event) { if (event.getNewState() == GameState.ENDING) { System.out.println("Arena " + event.getArena().getId() + " is now finishing."); }}