2 minutes estimated read time

States

A game will consist of multiple states, like "Waiting for more players", "Starting", "Running", "Ending", etc. States will always be their own classes that extend VitalMinigameInstanceState<T extends VitalMinigameInstance>.

MyInstanceState.java
public class MyInstanceState extends VitalMinigameInstanceState<MyInstance> {
    public MyInstanceState(MyInstance myInstance) {
        super(myInstance);
    }
}

Note that we are directly defining to which instance this state belongs to (<MyInstance>).
This way, we can always access our instance directly from our state to read or write game data, etc.

Event handling

Every state will by default always be a listener and can therefore directly receive events.
You can use the default Spigot event handlers in your states.

MyInstanceState.java
public class MyInstanceState extends VitalMinigameInstanceState<MyInstance> {
  public MyInstanceState(MyInstance myInstance) {
    super(myInstance);
  }
  
  @EventHandler
  public void onPlayerJoin(PlayerJoinEvent e) {
    // ...
  }
}

The event handlers that you define in your states will only receive events if the event that occurred actually came from your instance world.
Also, all of your event handlers will only be active when this state is currently active. This is what makes Vital minigames so powerful!

Switching states

You can freely switch between your states using the setState(VitalMinigameInstanceState) method in your instance class.
This allows you to, for example, switch a state directly from another state.

MyInstanceState.java
public class MyInstanceState extends VitalMinigameInstanceState<MyInstance> {
    public MyInstanceState(MyInstance myInstance) {
        super(myInstance);
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent e) {
        getInstance().setState(getInstance().getSomeOtherStateThatYouDefinedInYourInstance());
    }
}

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