Class GameStateChangeEvent

java.lang.Object
org.bukkit.event.Event
dev.despical.whackme.api.event.WhackMeEvent
dev.despical.whackme.api.event.game.GameEvent
dev.despical.whackme.api.event.game.GameStateChangeEvent
All Implemented Interfaces:
org.bukkit.event.Cancellable

public final class GameStateChangeEvent extends GameEvent implements org.bukkit.event.Cancellable
Called immediately before a Whack Me game changes state.

The game still reports getOldState() during dispatch. Cancelling the event prevents assignment of getNewState() and prevents the target state's first tick from running.

 @EventHandler
 public void onStateChange(GameStateChangeEvent event) {
     if (event.getNewState() == GameState.IN_GAME && maintenanceMode) {
         event.setCancelled(true);
     }
 }
 
API note: Cancelling internal recovery transitions such as RESTARTING may leave a game occupied. Listeners should only cancel a transition when they also manage the resulting lifecycle.
  • Constructor Details

    • GameStateChangeEvent

      public GameStateChangeEvent(Game game, GameState oldState, GameState newState)
      Creates a state change event.
      Parameters:
      game - game whose state is changing
      oldState - currently assigned state
      newState - requested destination state
  • Method Details

    • getOldState

      public GameState getOldState()
      Returns the state assigned when the event was fired.
      Returns:
      current state before the transition
    • getNewState

      public GameState getNewState()
      Returns the requested destination state.
      Returns:
      state that will be assigned unless cancelled
    • isCancelled

      public boolean isCancelled()
      Returns whether the state transition has been cancelled.
      Specified by:
      isCancelled in interface org.bukkit.event.Cancellable
      Returns:
      true when the old state must be retained
    • setCancelled

      public void setCancelled(boolean cancel)
      Sets whether the requested transition should be prevented.
      Specified by:
      setCancelled in interface org.bukkit.event.Cancellable
      Parameters:
      cancel - true to retain the old state
    • getHandlers

      @NotNull public @NotNull org.bukkit.event.HandlerList getHandlers()
      Specified by:
      getHandlers in class org.bukkit.event.Event
    • getHandlerList

      public static org.bukkit.event.HandlerList getHandlerList()