Skip to content

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.


  • Package: dev.despical.tntrun.api.event.game
  • Parent Class: GameEvent
  • Cancellable: Yes

In addition to the methods inherited from GameEvent, this event provides access to both the current and proposed game states.

MethodReturn TypeDescription
getOldState()GameStateReturns the current state of the game before the transition.
getNewState()GameStateReturns the state the game is attempting to enter.
isCancelled()booleanChecks if the state transition has been blocked.
setCancelled(boolean)voidSet to true to stop the game from changing 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.

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!");
}
}
}

Trigger logic exactly when a game moves into the ending phase.

@EventHandler
public void onGameEnding(GameStateChangeEvent event) {
if (event.getNewState() == GameState.ENDING) {
System.out.println("Arena " + event.getArena().getId() + " is now finishing.");
}
}