Commands
Commands allow you to execute specific actions in response to user input. Here's an example of how to create them step by step:
Explanation of the code:
Registering and Creating a Command:
You use the registerCommand
method to register a new command. CommandInfo.builder()
creates a command information object.
Command Configuration:
.name("command")
: Sets the command name as "command"..aliases(["c", "cmd"])
: Assigns aliases to the command, in this case, "c" and "cmd"..description("Simple example command in MCJS")
: Provides a description for the command..permission("commands.command")
: Defines the permission required to execute the command..target(CommandTarget.ALL)
: Specifies the command target (ALL, PLAYER, or CONSOLE)..async(false)
: Indicates whether the command runs asynchronously or not. In this case, it is set to false, meaning it is synchronous.
Command Function:
This is the function that will be executed when the command is invoked. In this example, it uses the API.message
function to send a message to the command sender with the content "Hello World!". The function returns true
to indicate that the command was executed successfully.
Last updated