⌨️ Commands API¶
Want players or the operator to type /hello and reach your feature? Register a command.
Registering commands¶
Registering a command¶
Rust: command::register(name, description, permission, handler)
Go: levilamina.RegisterCommand(name, description, permission, handler)
Zig: levilamina.registerCommand(name, description, permission, handler)
- Parameters:
- name : string
the command name, without the slash - description : string
shown in the game's command hints - permission : permission
who may use it: anyone, game directors, admins, the host, the owner, lowest to highest - handler : function
runs whenever someone runs the command, on the server thread. The text after the command: Rustinv.raw(), Goinv.Args, Ziginv.args
- name : string
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror, Ziglevilamina.Error!void- Register while enabling. Bedrock cannot unregister a command, so it stays until the server stops; while your mod is disabled, Pier mutes its commands.
- Slot:
register_command -
Example:
- Rust
Rust - Go
Go - Zig
A command with parameters¶
Rust: command::builder(name, description, permission).overload(..).register(handler)
Go: levilamina.NewCommand(name, description, permission).Overload(..).Register(handler)
Zig: levilamina.slot("register_command_ex")
Lets the game parse the parameters, with completion in the chat box. Each overload is one combination of parameters.
- Parameters:
- overload : overload
required parameters, optional ones, literal words and enum parameters, in order
- overload : overload
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror - Slot:
register_command_ex -
Example:
- Rust
Rust - Go
Two overloads must not accept the same input
When two overloads both match what a player typed, the game picks one. Words that mean different things but take the same parameters, such as menu, help and status, belong in one enum parameter.
Registering a command enum¶
Rust: command::register_enum(name, values)
Go: levilamina.RegisterCommandEnum(name, values)
Zig: levilamina.slot("register_command_enum")
- Parameters:
- name : string
the enum's name, by which an overload refers to it - values : a list of names and values
every value of the enum
- name : string
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror - Slot:
register_command_enum -
Example:
- Rust
Rust - Go
Go
Running commands¶
Running a command as the console¶
Rust: ctx.host().execute_command(cmd)
Go: levilamina.ExecuteCommand(cmd)
Zig: levilamina.executeCommand(cmd)
- Parameters:
- cmd : string
the command, without the slash
- cmd : string
- Return value: the command's output. Zig logs the output at debug level
- Return type: Rust
Result<String>, Go([]CommandOutput, error), Ziglevilamina.Error!void- Server thread only; before the level has loaded it returns an error.
- Slot:
execute_command -
Example:
- Rust
Rust - Go
Go - Zig
Zig