This page relates to GameStages, which has built-in support!

Accessing Player Stages

Link to accessing-player-stages

When GameStages is installed you will be able to access the stage data of a player in your scripts. This can be done any time you have access to a player in your scripts, for example inside a player event listener.

New Player Methods

Link to new-player-methods

These are all of the new player methods added by GameStages.

Any time you have access to a player you can add a stage using the following method.

ZenScript
Copy
// player.addGameStage(String stageName);
player.addGameStage("stage_one");

Any time you have access to a player you can remove a stage using the following method.

ZenScript
Copy
// player.removeGameStage(String stageName);
player.removeGameStage("stage_one");

You can also clear all stages granted to a player using the clear method.

ZenScript
Copy
player.clearGameStages();

Checking GameStages

Link to checking-gamestages

Any time you have access to a player you can check if they have a specific stage.

ZenScript
Copy
//player.hasGameStage(String stageName);
player.hasGameStage("stage_one");

You can also check if the player has any stage from an array of potential stages.

ZenScript
Copy
//player.hasAnyGameStages(String... stageNames);
player.hasAnyGameStages("stage_one", "stage_two", "defeated_boss_a");

// Alternatively
var validStagesForX as string[] = [ "stage_one", "stage_two", "defeated_boss_a" ];
player.hasAnyGameStages(validStagesForX);

You can also check if the player has all of the stages from an array.

ZenScript
Copy
//player.hasllGameStages(String... stageNames);
player.hasAllGameStages("stage_one", "stage_two", "defeated_boss_a");

// Alternatively
var requiredStagesForX as string[] = [ "stage_one", "stage_two", "defeated_boss_a" ];
player.hasAllGameStages(requiredStagesForX);

Example 1 - Event Listeners

Link to example-1---event-listeners

This example registers a new event listener that will will give a player a stage when they join the game if they haven't already unlocked it.

ZenScript
Copy
import crafttweaker.api.events.CTEventManager;
import crafttweaker.api.event.entity.player.MCPlayerLoggedInEvent; 

// Registers an event listener for the MCPlayerLoggedInEvent.
CTEventManager.register<MCPlayerLoggedInEvent>((event) => {

     // The code in here will be ran every time any player loggs in.

     // Gets the player from the event context.
     var player = event.player;

     // Only give the stage to the player if they don't have it already. This
     // is not required but it is considered best practice. 
     if (!player.hasGameStage("one")) {

         // Gives the stage "one" to the player.
         player.addGameStage("one");

         // Tell the player they unlocked a stage.
         player.sendMessage("You logged in! Here is stage 'one'.");
     }
});