2 minutes estimated read time

States

Every game will consist of multiple states (phases); every state defines a single part of your game, like "Waiting for more players", "Starting", "In game", "Ending", etc.
A state will always be its own class.

MyState.java
@GlobalMinigameState
public class MyState extends VitalGlobalMinigameState {
    
}

Every state will essentially be a listener that will only receive events when the state is active.

MyState.java
@GlobalMinigameState
public class MyState extends VitalGlobalMinigameState {
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent e) {
        // …
    }   
}

There can only be one state active at a given time.

Since we are building a global game, the state is handled globally by the VitalGlobalMinigameService.
Use this as a bean to switch between states, Vital will automatically handle event registration and all of that complicated stuff for you.

vitalGlobalMinigameService.setState(MyState.class);

When switching states, Vital automatically unregisters all of your event handlers from your old states.
Your new state is activated, and all of your event handlers for your new state will be registered and can now receive events.

If you are building a global game, you might want to store all of your game-related data, like player kills, stats, etc. in a separate Spring bean, or a service class that you can inject everywhere.

Lifecycles

LifecycleUsage
onEnable()Perform an action when this state is enabled.
onDisable()Perform an action when this state is disabled.

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