Skip to content

GameStateChangeEvent

The GameStateChangeEvent is triggered immediately before a Santa Says game transitions between states (e.g., from WAITING to STARTING). This event allows developers to inspect the transition and, if necessary, cancel it to prevent the state from changing.


  • Package: io.greenmc.santasays.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 the 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 to the first round has begun.
  • IN_GAME: The game loop is active and tasks are running.
  • ENDING: The game has finished, and winners are being displayed.
  • RESTARTING: The arena is cleaning up and resetting.

You can use this to prevent a game from starting if external conditions (like a server-wide event) are not met.

import io.greenmc.santasays.api.event.game.GameStateChangeEvent;
import io.greenmc.santasays.api.game.GameState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class StateLockListener implements Listener {
@EventHandler
public void onStateChange(GameStateChangeEvent event) {
// Prevent the game from starting if a global lock is active
if (event.getNewState() == GameState.STARTING && isGlobalLockActive()) {
event.setCancelled(true);
event.getGame().broadcast("§cThe game cannot start right now!");
}
}
}

Trigger logic or update boss bars exactly when a game moves into the ending phase.

@EventHandler
public void onGameEnding(GameStateChangeEvent event) {
if (event.getNewState() == GameState.ENDING) {
// Logic to run right before the game officially enters the ending phase
System.out.println("Arena " + event.getArena().getName() + " is now finishing.");
}
}