2 minutes estimated read time

Global mini-game states

Below is an example for a global game state for the vital-minigames module.
In a game, only one state can currently be active at a given time.

Only the currently active state will receive events.

MyGlobalMinigameState.java
@GlobalMinigameState
public class MyGlobalMinigameState extends VitalGlobalMinigameState {
    @Override
    public void onEnable() {
        for (final var player : Bukkit.getOnlinePlayers()) {
            player.sendMessage("This state was enabled.");
        }
    }

    @Override
    public void onDisable() {
        for (final var player : Bukkit.getOnlinePlayers()) {
            player.sendMessage("This state was disabled.");
        }
    }

    // This event method will only be active when this state is currently active.
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent e) {
        e.getPlayer().sendMessage("You have joined the game during this active state.");
    }
}

To switch between states, use the global VitalGlobalMinigameService bean.
Use VitalGlobalMinigameService.setState(Class<? extends VitalGlobalMinigameState>) to switch to a new state.

The old state will be deactivated and will no longer receive any events.
The new state will be activated and can now receive events.

If the old state was a countdown state, the countdown will be stopped and reset.

Found an issue?

Help us improve the documentation by reporting typos, missing information, or anything confusing.

Don't worry, we will auto-fill most of the annoying fields.

Create GitHub issue

This site and the Vital framework were built with ❤️ by Mike Neumann