When using the COMMAND_CUSTOM command mode, it creates a new command that can run one or more existing commands with required or optional arguments passthrough.
Format Structure
The custom command format consists of multiple components and allows for a high degree of customizability. The following components are included:
Base Component: The base template for creating a custom command.
Child Component: A sub-child component that allows for the inclusion of arguments and sub-commands on a recursive basis.
Action Component: The action component allows for the execution of commands, evaluation of command state execution, and the ability to apply additional actions on a recursive basis depending on the command state.
Suggestion Provider Component: A suggestion provider for a list of items in the database, or an existing vanilla suggestion provider.
Full Example
JSON or JSON5
{"schemaVersion": 1,"commandMode":"COMMAND_CUSTOM","command":"hello","permission": 0,"message":"hello parent command","children": [ {"child":"name","type":"argument","argumentType":"minecraft:word","suggestionProvider": {"suggestionMode":"DATABASE_STARTS_WITH","suggestion":"$executor_name().home.suggestions" },"permission": 0,"message":"Hello name sub command","children": [ { } ],"actions": [ { } ] } ],"actions": [ {"startTime":"1000","id":"generic","command":"say Hello {{name}}","commandType":"SERVER","message":"We tried to say hello {{name}}","requireSuccess":false,"messageIfUnsuccessful":"We failed to say hello {{name}}","messageIfSuccessful":"We said hello {{name}}","actionsIfUnsuccessful": [ { } ],"actionsIfSuccessful": [ { } ] } ]}
TOML
schemaVersion =1commandMode ="COMMAND_CUSTOM"command ="hello"permission =0message ="hello parent command"[[children]]child ="name"type ="argument"argumentType ="minecraft:word"permission =0message ="Hello name sub command" [children.suggestionProvider] suggestionMode ="DATABASE_STARTS_WITH" suggestion ="$executor_name().home.suggestions" [[children.children]] [[children.actions]][[actions]]startTime ="1000"id ="generic"command ="say Hello {{name}}"commandType ="SERVER"message ="We tried to say hello {{name}}"requireSuccess =falsemessageIfUnsuccessful ="We failed to say hello {{name}}"messageIfSuccessful ="We said hello {{name}}" [[actions.actionsIfUnsuccessful]] [[actions.actionsIfSuccessful]]
YAML
schemaVersion:1commandMode:COMMAND_CUSTOMcommand:hellopermission:0message:hello parent commandchildren: - child:nametype:argumentargumentType:'minecraft:word'permission:0message:Hello name sub commandsuggestionProvider:suggestionMode:DATABASE_STARTS_WITHsuggestion:$executor_name().home.suggestionschildren: - {}actions: - {}actions: - startTime:'1000'id:genericcommand:'say Hello {{name}}'commandType:SERVERmessage:'We tried to say hello {{name}}'requireSuccess:falsemessageIfUnsuccessful:'We failed to say hello {{name}}'messageIfSuccessful:'We said hello {{name}}'actionsIfUnsuccessful: - {}actionsIfSuccessful: - {}
Create a custom command using COMMAND_CUSTOM
Understanding the basics
To begin, we must set our command mode to COMMAND_CUSTOM.
Next, let's send a message to the command executor (the player or console that runs the command).
JSON or JSON5
{"schemaVersion":1,"commandMode":"COMMAND_CUSTOM","command":"tools","message":"Here are some free wooden tools"}
TOML
schemaVersion =1commandMode ="COMMAND_CUSTOM"command ="tools"message ="Here are some free wooden tools"
YAML
schemaVersion:1commandMode:COMMAND_CUSTOMcommand:toolsmessage:Here are some free wooden tools
To personalize the message, let's get the executor's name and bind it to our message. We can obtain the executor's name using the $executor_name() function.
JSON or JSON5
{"schemaVersion":1,"commandMode":"COMMAND_CUSTOM","command":"tools","message":"Here are some free wooden tools, $executor_name()!"}
TOML
schemaVersion =1commandMode ="COMMAND_CUSTOM"command ="tools"message ="Here are some free wooden tools, $executor_name()!"
YAML
schemaVersion:1commandMode:COMMAND_CUSTOMcommand:toolsmessage:'Here are some free wooden tools, $executor_name()!'
Scenario
Player123 runs /tools
Output will return Here are some free wooden tools, Player123!
To continue, let's give the player a wooden sword. This can be done by using the actions field, which takes an array of command action objects as input.
JSON or JSON5
{"schemaVersion":1,"commandMode":"COMMAND_CUSTOM","command":"tools","message":"Here are some free wooden tools, $executor_name()!","actions": []}
TOML
schemaVersion =1commandMode ="COMMAND_CUSTOM"command ="tools"message ="Here are some free wooden tools, $executor_name()!"[[actions]]
YAML
schemaVersion:1commandMode:COMMAND_CUSTOMcommand:toolsmessage:'Here are some free wooden tools, $executor_name()!'actions: []
To complete this step, we will need to create a command action object inside the custom command.
JSON or JSON5
{"schemaVersion":1,"commandMode":"COMMAND_CUSTOM","command":"tools","message":"Here are some free wooden tools, $executor_name()!","actions": [ {"command":"give $executor_name() minecraft:wooden_sword" } ]}
TOML
schemaVersion =1commandMode ="COMMAND_CUSTOM"command ="tools"message ="Here are some free wooden tools, $executor_name()!"[[actions]]command ="give $executor_name() minecraft:wooden_sword"
YAML
schemaVersion:1commandMode:COMMAND_CUSTOMcommand:toolsmessage:'Here are some free wooden tools, $executor_name()!'actions: - command:'give $executor_name() minecraft:wooden_sword'
Before we proceed to run the command, we must define the type of execution between CLIENT and SERVER. Using CLIENT will imply that the executors run the command (in this case, the /give command), which means that if the executor does not have permission to use the /give command, our custom command will error out. To avoid this issue, we can use SERVER. Using SERVER will imply that the internal or dedicated server executes the custom command, not the executor. In this case, for our /tools command, we will need to use SERVER since players do not have access to the /give command."
JSON or JSON5
{"schemaVersion":1,"commandMode":"COMMAND_CUSTOM","command":"tools","message":"Here are some free wooden tools, $executor_name()!","actions": [ {"command":"give $executor_name() minecraft:wooden_sword","commandType":"SERVER" } ]}
TOML
schemaVersion =1commandMode ="COMMAND_CUSTOM"command ="tools"message ="Here are some free wooden tools, $executor_name()!"[[actions]]command ="give $executor_name() minecraft:wooden_sword"commandType ="SERVER"
YAML
schemaVersion:1commandMode:COMMAND_CUSTOMcommand:toolsmessage:'Here are some free wooden tools, $executor_name()!'actions: - command:'give $executor_name() minecraft:wooden_sword'commandType:SERVER
We can also schedule a start time for commands using startTime in milliseconds. This allows us to add a 1 second wait time for all commands to execute, allowing us to schedule the time according to our preferences. In this example, I will be scheduling them with a 1 second wait time between each command.
You can also include a message in the command action object.
JSON or JSON5
{"schemaVersion":1,"commandMode":"COMMAND_CUSTOM","command":"tools","message":"Here are some free wooden tools, $executor_name()!","actions": [ {"command":"give $executor_name() minecraft:wooden_sword","commandType":"SERVER","startTime":"1000","message":"Here is a wooden sword" }, {"command":"give $executor_name() minecraft:wooden_pickaxe","commandType":"SERVER","startTime":"1000","message":"Here is a wooden pickaxe" }, {"command":"give $executor_name() minecraft:wooden_axe","commandType":"SERVER","startTime":"1000","message":"Here is a wooden axe" }, {"command":"give $executor_name() minecraft:wooden_shovel","commandType":"SERVER","startTime":"1000","message":"Here is a wooden shovel, $executor_name()!" } ]}
TOML
schemaVersion =1commandMode ="COMMAND_CUSTOM"command ="tools"message ="Here are some free wooden tools, $executor_name()!"[[actions]]command ="give $executor_name() minecraft:wooden_sword"commandType ="SERVER"startTime ="1000"message ="Here is a wooden sword"[[actions]]command ="give $executor_name() minecraft:wooden_pickaxe"commandType ="SERVER"startTime ="1000"message ="Here is a wooden pickaxe"[[actions]]command ="give $executor_name() minecraft:wooden_axe"commandType ="SERVER"startTime ="1000"message ="Here is a wooden axe"[[actions]]command ="give $executor_name() minecraft:wooden_shovel"commandType ="SERVER"startTime ="1000"message ="Here is a wooden shovel, $executor_name()!"
YAML
schemaVersion:1commandMode:COMMAND_CUSTOMcommand:toolsmessage:'Here are some free wooden tools, $executor_name()!'actions: - command:'give $executor_name() minecraft:wooden_sword'commandType:SERVERstartTime:'1000'message:Here is a wooden sword - command:'give $executor_name() minecraft:wooden_pickaxe'commandType:SERVERstartTime:'1000'message:Here is a wooden pickaxe - command:'give $executor_name() minecraft:wooden_axe'commandType:SERVERstartTime:'1000'message:Here is a wooden axe - command:'give $executor_name() minecraft:wooden_shovel'commandType:SERVERstartTime:'1000'message:'Here is a wooden shovel, $executor_name()!'
Scenario:
Player123 runs the /tools command.
The message "Here are some free wooden tools, Player123!" is displayed.
A wooden sword is dropped, and the message "Here is a wooden sword" is printed; a 1 second wait time is initiated.
A wooden pickaxe is dropped, and the message "Here is a wooden pickaxe" is printed; a 1 second wait time is initiated.
A wooden axe is dropped, and the message "Here is a wooden axe" is printed; a 1 second wait time is initiated.
A wooden shovel is dropped, and the message "Here is a wooden shovel, Player123!" is displayed.