Skip to content

Commit 697f6e4

Browse files
committed
feat: new particle, sync with dev/dev branch
1 parent 778ed4d commit 697f6e4

File tree

15 files changed

+1147
-3
lines changed

15 files changed

+1147
-3
lines changed

docs/en/create-commands/aliases.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
order: 8
3+
authors:
4+
- JorelAli
5+
- willkroboth
6+
- DerEchtePilz
7+
---
8+
9+
# Aliases
10+
11+
Aliases for commands can be added by using the `withAliases()` method when registering a command. Aliases allow you to run the same command with a different 'name' from the original registered command name.
12+
13+
::::tip Example – Using aliases for `/getpos`
14+
15+
In this example, we register the command `/getpos` that returns the command sender's location. We apply the aliases `/getposition`, `/getloc`, `/getlocation` and `/whereami` as well, using the `withAliases()` method.
16+
17+
:::tabs
18+
===Java
19+
<<< @/../reference-code/src/main/java/createcommands/Aliases.java#aliasesExample
20+
===Kotlin
21+
<<< @/../reference-code/src/main/kotlin/createcommands/Aliases.kt#aliasesExample
22+
===Kotlin DSL
23+
<<< @/../reference-code/src/main/kotlin/createcommands/Aliases.kt#aliasesExampleDSL
24+
:::
25+
26+
::::

docs/en/create-commands/arguments/types/misc/particle-arguments.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,21 @@ The particle argument requires additional data for a particle depending on what
171171
</ul>
172172
</td>
173173
</tr>
174+
<tr>
175+
<td><code>TRAIL</code></td>
176+
<td>
177+
<pre>trail{color:[<b>red</b>,<b>green</b>,<b>blue</b>],target:[<b>x</b>,<b>y</b>,<b>z</b>],duration:<b>duration</b>}</pre>
178+
<ul style="padding-left: 1.5em;">
179+
<li><b><code>red</code></b> - number for red, between 0.0 and 1.0</li>
180+
<li><b><code>green</code></b> - number for green, between 0.0 and 1.0</li>
181+
<li><b><code>blue</code></b> - number for blue, between 0.0 and 1.0</li>
182+
<li><b><code>x</code></b> - decimal x-coordinate to move the particle to</li>
183+
<li><b><code>y</code></b> - decimal y-coordinate to move the particle to</li>
184+
<li><b><code>z</code></b> - decimal z-coordinate to move the particle to</li>
185+
<li><b><code>duration</code></b> - ime in ticks to take to move towards its destination</li>
186+
</ul>
187+
</td>
188+
</tr>
174189
<tr>
175190
<td><code>VIBRATION</code></td>
176191
<td>
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
order: 11
3+
authors:
4+
- JorelAli
5+
- willkroboth
6+
- DerEchtePilz
7+
- MC-XiaoHei
8+
---
9+
10+
# Command trees
11+
12+
So far in this documentation, we've described many different ways to register commands. We've described writing commands by declaring a `CommandAPICommand` object, using a list of arguments and providing an executor for the command. We've also described another way of registering commands with multiple "paths" using the `withSubcommand` method to generate a tree-like structure. As of CommandAPI 7.0.0, another method for registering commands, _command trees_, has been introduced.
13+
14+
## The `executes()` and `then()` methods
15+
16+
The Command Tree represents command structures in a tree-like fashion, in a very similar way that Brigadier's API lets you declare commands. Command tree commands effectively revolve around two methods:
17+
18+
```java
19+
public T executes(CommandExecutor executor);
20+
21+
public CommandTree then(ArgumentTree branch);
22+
public ArgumentTree then(ArgumentTree branch);
23+
```
24+
25+
The `executes()` method is the same `executes()` method that you have seen previously in this documentation for normal CommandAPI commands. This also includes all of the `executes...()` methods described in [Normal command executors](./executors/normal-executors#restricting-who-can-run-your-command), but for the sake of simplicity, we'll simply refer to all of these by `executes()`.
26+
27+
The `then()` method allows you to create new "branches" in your command "tree" data structure. If you are familiar with [Brigadier](https://github.com/Mojang/brigadier)'s `then()` method for argument nodes, then you should feel right at home. Otherwise, for all intents and purposes `then()` lets you specify additional paths that a command can take when a user is typing their command.
28+
29+
Because the underlying type hierarchy of command trees is fairly complex (`then()` having multiple return types and taking in `ArgumentTree` objects), instead of trying to describe how all of that works, we'll instead describe how to make command trees by using the methods `executes()` and `then()` in practice.
30+
31+
## Declaring a command tree
32+
33+
The basic syntax of a command tree is effectively identical to a normal `CommandAPICommand`, but instead you use the `CommandTree` object. For example, if we want to create a simple command which sends "Hi!" to a command sender, we declare the name of our command, make use of the `executes()` method, and then we use the `CommandTree` constructor instead of the `CommandAPICommand` constructor:
34+
35+
```mccmd
36+
/sayhi
37+
```
38+
39+
```java
40+
new CommandAPICommand("sayhi")
41+
.executes((sender, args) -> {
42+
sender.sendMessage("Hi!");
43+
})
44+
.register();
45+
```
46+
47+
$$\downarrow$$
48+
49+
```java
50+
new CommandTree("sayhi")
51+
.executes((sender, args) -> {
52+
sender.sendMessage("Hi!");
53+
})
54+
.register();
55+
```
56+
57+
## Adding arguments to a command tree
58+
59+
Unlike the `CommandAPICommand` class, the `CommandTree` class doesn't let you add arguments using the `withArguments()` method. Instead, it makes use of the `then()` method, which allows you to provide an argument to it. This is best described with an example.
60+
61+
::::tip Example – Declaring a command tree with a single argument
62+
63+
Say we want to take our `/sayhi` command from above and also have an argument which lets you specify a target player. In this example, we'll have the following command syntax:
64+
65+
```mccmd
66+
/sayhi - Says "Hi!" to the current sender
67+
/sayhi <target> - Says "Hi!" to a target player
68+
```
69+
70+
We can do this by adding a `PlayerArgument` to our command. As described above, to add this argument, we must use the `then()` method:
71+
72+
:::tabs
73+
===Java
74+
<<< @/../reference-code/src/main/java/createcommands/CommandTrees.java#commandTreesExample
75+
===Kotlin
76+
<<< @/../reference-code/src/main/kotlin/createcommands/CommandTrees.kt#commandTreesExample
77+
:::
78+
79+
In this example, we have our normal `/sayhi` command using the `executes()` method. We then add a new argument (a new "branch" in our "tree"), the `PlayerArgument`, using the `then()` method. **We want to make this branch executable, so we also use the `executes()` method _on the argument itself_**. To register the full command tree (which includes both `/sayhi` and `/sayhi <target>`), we call `register()` on the `CommandTree` object.
80+
81+
::::
82+
83+
### Reduce indentation with nested arguments
84+
85+
Sometimes we will need such a `CommandTree`:
86+
87+
:::tabs
88+
===Java
89+
<<< @/../reference-code/src/main/java/createcommands/CommandTrees.java#legacyLargeArgumentsExample
90+
===Kotlin
91+
<<< @/../reference-code/src/main/kotlin/createcommands/CommandTrees.kt#legacyLargeArgumentsExample
92+
===Kotlin DSL
93+
<<< @/../reference-code/src/main/kotlin/createcommands/CommandTrees.kt#legacyLargeArgumentsExampleDSL
94+
:::
95+
96+
Well, there's too much indentation. We can use nested arguments to reduce the indentation levels:
97+
98+
:::tabs
99+
===Java
100+
<<< @/../reference-code/src/main/java/createcommands/CommandTrees.java#nestedLargeArgumentsExample
101+
===Kotlin
102+
<<< @/../reference-code/src/main/kotlin/createcommands/CommandTrees.kt#nestedLargeArgumentsExample
103+
===Kotlin DSL
104+
<<< @/../reference-code/src/main/kotlin/createcommands/CommandTrees.kt#nestedLargeArgumentsExampleDSL
105+
:::
106+
107+
That's effectively all of the basics of command trees! We start by writing a normal command, use `executes()` to make it executable and use `then()` to add additional paths to our command. Finally, we finish up with `register()` to register our command. Below, I've included a few more examples showcasing how to design commands using command trees.
108+
109+
## Command tree examples
110+
111+
::::tip Example – Sign editing plugin
112+
113+
Say we wanted to create a plugin to let a user edit signs. We have a single command tree `/signedit`, with a number of branching paths `set`, `clear`, `copy` and `paste` which represent various operations that this command can be performed on a sign:
114+
115+
```mccmd
116+
/signedit set <line_number> <text> - Sets the text for a line on a sign
117+
/signedit clear <line_number> - Clears a sign's text on a specific line
118+
/signedit copy <line_number> - Copies the current text from a line on a sign
119+
/signedit paste <line_number> - Pastes the copied text onto a line on a sign
120+
```
121+
122+
:::tabs
123+
===Java
124+
<<< @/../reference-code/src/main/java/createcommands/CommandTrees.java#signeditCommandExample
125+
===Kotlin
126+
<<< @/../reference-code/src/main/kotlin/createcommands/CommandTrees.kt#signeditCommandExample
127+
:::
128+
129+
::::

docs/en/create-commands/help.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
order: 9
3+
authors:
4+
- JorelAli
5+
- willkroboth
6+
- DerEchtePilz
7+
---
8+
9+
# Help
10+
11+
Help topics can be added to your command using the `withHelp()`, `withShortDescription()`, `withFullDescription()` or `withUsage()` methods when registering a command. Help allows users to understand what your command does and provides them with a list of usage forms to aid in writing a command.
12+
13+
## Parts of a help
14+
15+
A help topic consists of two mains parts:
16+
17+
- A short description which is displayed in a help list and displayed at the top of a help topic for that command
18+
- A full description which is displayed in the "Description" section of a help topic
19+
20+
This can be seen with the following example, for a command `/mycmd`. This example has the short description _"Says hi"_, and a full description _"Broadcasts hi to everyone on the server"_. The short help is shown in the help list, which (in this example) is viewed using `/help 5`. The full description is shown for the help for the command on its own, which is viewed using `/help mycmd`:
21+
22+
![help image](/images/help.png)
23+
24+
## Help methods and semantics
25+
26+
The CommandAPI has three methods to register parts of a help. The `withShortDescription()` sets the short description for the command, the `withFullDescription()` sets the full description for the command and `withHelp()` is a simple way to set both the short and full description at the same time. The `withHelp()` method is the recommended method to use to set the help for a command.
27+
28+
If no short description is provided, the CommandAPI will attempt to use the full description if one is present. Note that this may be truncated automatically, so it is recommended to provide your own short description.
29+
30+
These are the following methods that the CommandAPI provides to set the help topic for a command:
31+
32+
```java
33+
CommandAPICommand withShortDescription(String description);
34+
```
35+
36+
The `withShortDescription` method simply sets the short description for the command. In the above screenshot, the short description is "Says hi".
37+
38+
```java
39+
CommandAPICommand withFullDescription(String description);
40+
```
41+
42+
The `withFullDescription` method sets the full description for the command. In the above screenshot, the full description is "Broadcasts hi to everyone on the server".
43+
44+
```java
45+
CommandAPICommand withHelp(String shortDescription, String fullDescription);
46+
```
47+
48+
The `withHelp` method sets both the short description and the full description at the same time.
49+
50+
::::tip Example – Adding help to a command
51+
52+
In this simple example, we implement the above screenshot's help topic. We register a command `/mycmd` and use the `withShortDescription` and `withFullDescription` methods to create a help topic:
53+
54+
:::tabs
55+
===Java
56+
<<< @/../reference-code/src/main/java/createcommands/Help.java#helpExampleStep1
57+
===Kotlin
58+
<<< @/../reference-code/src/main/kotlin/createcommands/Help.kt#helpExampleStep1
59+
===Kotlin DSL
60+
<<< @/../reference-code/src/main/kotlin/createcommands/Help.kt#helpExampleStep1DSL
61+
:::
62+
63+
We could also register this command using the `withHelp` method instead:
64+
65+
:::tabs
66+
===Java
67+
<<< @/../reference-code/src/main/java/createcommands/Help.java#helpExampleStep2
68+
===Kotlin
69+
<<< @/../reference-code/src/main/kotlin/createcommands/Help.kt#helpExampleStep2
70+
===Kotlin DSL
71+
<<< @/../reference-code/src/main/kotlin/createcommands/Help.kt#helpExampleStep2DSL
72+
:::
73+
74+
::::
75+
76+
## Advanced help topics
77+
78+
For more control over help topics, the CommandAPI offers the following method, which allows you to provide your own `HelpTopic` object:
79+
80+
```java
81+
CommandAPICommand withHelp(HelpTopic helpTopic);
82+
```
83+
84+
::::tip Example – Adding locale-specific help
85+
86+
In this example, we implement locale-specific help so players can see help in their desired language. To do this, we must make use of the Bukkit `HelpTopic` object which gives us more control over the content of help that is displayed to a player:
87+
88+
:::tabs
89+
===Java
90+
<<< @/../reference-code/src/main/java/createcommands/Help.java#helpTopicExampleStep1
91+
===Kotlin
92+
<<< @/../reference-code/src/main/kotlin/createcommands/Help.kt#helpTopicExampleStep1
93+
:::
94+
95+
We then add our new `HelpTopic` to the command using the `withHelp` method:
96+
97+
:::tabs
98+
===Java
99+
<<< @/../reference-code/src/main/java/createcommands/Help.java#helpTopicExampleStep2
100+
===Kotlin
101+
<<< @/../reference-code/src/main/kotlin/createcommands/Help.kt#helpTopicExampleStep2
102+
:::
103+
104+
::::
105+
106+
## Command usage
107+
108+
When registering a command, there also is a command usage generated. The CommandAPI provides a way to customise this usage by providing the `withUsage()` method:
109+
110+
```java
111+
CommandAPICommand withUsage(String... usage)
112+
```
113+
114+
::::tip Example – Providing a command usage
115+
116+
In this example, we want to showcase how usage generation displays the usage vs. how a custom usage displays the usage:
117+
118+
```mccmd
119+
/command <help> <admin|user|moderator|vip>
120+
/command <reload> <commandsystem|config|server>
121+
```
122+
123+
This is how it would get displayed:
124+
125+
```yaml
126+
Usage:
127+
- /command <help> <admin>
128+
- /command <help> <user>
129+
- /command <help> <moderator>
130+
- /command <help> <vip>
131+
- /command <reload> <commandsystem>
132+
- /command <reload> <config>
133+
- /command <reload> <server>
134+
```
135+
136+
Now, we are implementing the `withUsage()` method:
137+
138+
```java
139+
new CommandAPICommand("...")
140+
.withUsage(
141+
"/command <help> <section>",
142+
"/command <reload> <system>"
143+
)
144+
```
145+
146+
By using `withUsage()` like that, the CommandAPI will produce this usage:
147+
148+
```yaml
149+
Usage:
150+
- /command <help> <section>
151+
- /command <reload> <system>
152+
```
153+
154+
::::

0 commit comments

Comments
 (0)