addCommand

Create custom commands with scripts.

Overview:

Functions:

API Reference

addCommand()

Creates a custom command

addCommand("commandName", {
    onCommand: function(sender, args) {},
    onTabComplete: function(sender, args) {}
}, "permission.example");

Parameters:

  • commandName (String) The name of the command (without /)

  • handler (Object) Contains methods like onCommand and optionally onTabComplete

  • permission (optional) (String) The permission string required to execute or tab-complete this command. If there is no permission given, the command is available to all players (and ops by default)

Methods:

  • onCommand(sender, args) (required) Called when the command is executed.

    • sender: The player or console who executed the command.

    • args: A Java array of arguments.

  • onTabComplete(sender, args) (optional) Called to provide tab-completion suggestions. Must return a Java List.

To read the arguments you need to convert them to a readable array via toArray(..)

To return modified arguments you need to convert the array back to a JavaList via toJavaList(..)


Example:

Players without openjs.command.adminhello will not see the command in suggestions or tab-complete. Operators do have all permission by default, unless restricted by permission plugins.

Last updated

Was this helpful?