Skip to content

API ‐ CommandManager

laz edited this page Jul 6, 2026 · 8 revisions

CommandManager

Register(Command, Action)

Register new command with function.

CommandManager.Register(new Command("hub", "Teleport back to hub"), tpHub);

You will also need to create function for every command that will get called on command use. Example below shows function for "hub" command including trasfering to hub World if player isn't there.

private void tpHub(Player player)
{
    if (player.CurrentWorld.LevelName != "hub")
    {
        player.ChangeWorld(Server.GetWorld("hub"), new Vector3(2, -54, -11));
    }
    else
    {
        player.Teleport(new Vector3(2, -54, -11));
    }
}

Unregister(string)

Unregister built-in or other registered commands that you don't need.

CommandManager.Unregister("about")

Command

Command(string, string, byte(optional), List(optional))

Command can be also initialized using optional permission level and parameters. In example you can see how to register command with permission 0 (anyone can access) and BoolP parameter that means alwaysday command will have true and false options.

CommandManager.Register(new Command("alwaysday", "Locks and unlocks day-night cycle.", 0, new List<Parameter>() { new BoolP("lock", true) }), Action);

You can also have multiple parameters and make more complex commands. Example is showing working clear command implementation using these parameters.

Bool after parameter tells if parameter is optional and command can be executed without this parameter otherwise error will be displayed about invalid command syntax. new IntP("data", true)// true - optional, command can be executed without this value, false - command can't be executed without this parameter


public static void Action(CommandAction action)
{
    var targets = PlayerParameter.Get(action, 0);
    var item = ItemParameter.Get(action, 1);
    var data = IntParameter.Get(action, 2);
    var maxCount = IntParameter.Get(action, 3);

    foreach (var target in targets)
    {
        target.Inventory.Clear(item);
    }

    if (targets.Count() > 0)
    {
        action.Player.SendMessage($"Cleared the inventory of {string.Join(", ", targets.Select(i => i.Username))}");
    }
}

Parameter

Add various parameter types to the command.

(parameter type)(string, bool(optional))

If optional bool is true - optional, command can be executed without this value, false - command can't be executed without this parameter.

IntP(string, bool(optional))

Add int parameter to the command.

CommandManager.Register(new Command("inttest", "int test command.", 0, new List<Parameter>() { new int("int value", true) }), Action);

public static void Action(CommandAction action)
{
    int number = IntParameter.Get(action, 0); //int value from command
}

(parameter type).Get(CommandAction, int);

.get is function that returns specific value from CommandAction using index (int) where parameter is located in Command.

For example in here first parameter is new PlayerP("player") so index 0 is where we will need to get player parameter so it is PlayerParameter.Get(action, 0). Next parameter is command is new ItemP("ItemName", true), so it's index is 1 because it is secound parameter in command that means it is accessible with item = ItemParameter.Get(action, 1) where 1 is secound index

CommandManager.Register(new Command("clear", "Clears items from player inventory.", 0, new List<Parameter>() { new PlayerP("player"), new ItemP("ItemName", true), new IntP("data", true), new IntP("maxCount", true) }), Clear.Action);

public static void Action(CommandAction action)
{
    var targets = PlayerParameter.Get(action, 0);
    var item = ItemParameter.Get(action, 1);
    var data = IntParameter.Get(action, 2);
    var maxCount = IntParameter.Get(action, 3);
}
``

Clone this wiki locally