-
Notifications
You must be signed in to change notification settings - Fork 0
First Command
- The sender is the player or console (possibly a command block) that ran the command.
- The executor is the entity this command was executed as.
Defaults to the
sender. Is null if the executor is a console. Using other commands, this can be changed, e.g. by using/execute as. - The root is the 'base section' where you define the description, permission and aliases.
First, you have to specify the name as a section:
my-custom-command:That is the command root section.
In your command, you can now specify simple optional metadata like the description, permission and aliases of your command.
my-custom-command:
# The description of your command. Appears when players use `/help my-custom-command`.
description: 'My custom command that does custom stuff'
# The permission players need to see and run this command.
# If not set, every player will be able to see and run the command.
# Set this to `ccmd.command.<command-name>` if you are unsure.
permission: 'ccmd.command.my-custom-command'
# Aliases specify alternate names for this command.
# They do the exact same things as the command but with a different name.
# So you could type `/my-custom-command` or `/my-ccmd` with the same effect.
aliases: [ 'my-ccmd' ]Right now, the command is only visual and doesn't do anything. Let's change that!
In your command, specify an execution declaration (That's how the executes section is called)
For now, we want to execute a command.
my-custom-command:
...
executes:
type: COMMANDS
commands:
- 'say Hello World'You now have a command that says Hello World when you execute it.
There are many other execution types other than COMMANDS.
You can find more of them here
Sometimes, you want to require players to fit certain criteria for them to be able to see and run the command. For that, you can use requirements.
You can do that by adding a requirement declaration (the requires section)
my-custom-command:
...
requires:
type: JAVASCRIPT
javascript: () => senderIsPlayer && sender.getLevel() >= 100This requirement requires that the sender has to be a player that has at least 100 xp levels. If the player doesn't match that criteria, they don't see the command and can't execute it.
Often, you don't just want a command that can only be run as /command with no arguments.
With arguments, you can create everything from /greet DerOntey to /execute in minecraft:overworld run greet DerOntey.
To specify an argument, add a section that starts with the prefix then:.
Everything after the prefix is the name of the argument.
There's two types of arguments:
A fixed keyword in a command path that must be typed exactly as defined, such as creative in /gamemode creative.
The root of commands is also a literal, so /gamemode is a literal too.
They can have an execution and requirement declaration just like the command root (As the root is a literal).
my-custom-command:
...
then:advanced:
# LITERAL is already the default type, so you don't have to set `type: LITERAL`
type: LITERAL
requires:
type: JAVASCRIPT
javascript: () => isSenderPlayer && sender.getLevel >= 150
executes:
type: COMMANDS
commands:
- 'say Hello, World!'Now, if a player has 150 xp levels, they can run /my-custom-command advanced and the command will say Hello, World! with correct punctuation.
A dynamic placeholder that accepts variable input from the user, such as a player's name, a number, or a set of coordinates. Arguments may have an execution and requirement declaration just like literals, but they also have an argument declaration and can have custom suggestions.
Because arguments are first evaluated when the player runs the command, the values are not constant.
Therefore, you have to get them with getArgument("<argument-name>")
There are very many argument type providers, so look at the list here
my-custom-command:
...
then:required-xp:
type: ARGUMENT # This is required for arguments
argument:
type: INTEGER # argument type provider
min: 1
max: 200
executes:
type: JAVASCRIPT
javascript: |
() => {
if(!isSenderPlayer) {
sender.sendPlainMessage("Only players can run this command!")
return;
}
const requiredXp = getArgument("required-xp")
if(sender.getLevel() >= requiredXp)
sender.sendPlainMessage("You have at least the required xp!")
else
sender.sendPlainMessage("You don't have the required xp!")
}You now have a command where a player can test whether they have the required xp
Arguments can have suggestions. These are clickable bits of text that can have a tooltip. When clicked, they insert the text that they hold at your mouse position. When hovered, they show their tooltip (if they have one)
my-custom-command:
...
then:required-xp:
...
suggests:
type: LIST
list:
- 80
- value: 100
tooltip: 'The default value'
- 120
- value: 150
tooltip: 'The advanced value'That was a showcase of the biggest features of this plugin and how you can use them. Still, there's several other ways to utilize these features. These will be on the wiki too.
I hope you can build a simple command with this plugin now :)