Skip to content

Commit bb96c5c

Browse files
committed
feat: some argument page, and full grammar check
1 parent ba58858 commit bb96c5c

29 files changed

+442
-143
lines changed

docs/en/create-commands/arguments/arguments.md

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,47 +32,29 @@ The CommandAPI is very flexible when it comes to registering arguments, and lets
3232

3333
:::tabs
3434
===Java
35-
```java
36-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:arguments1}}
37-
```
35+
<<< @/../reference-code/src/main/java/createcommands/arguments/Arguments.java#registerArgumentsExample
3836
===Kotlin
39-
```kotlin
40-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:arguments1}}
41-
```
37+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsExample
4238
===Kotlin DSL
43-
```kotlin
44-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:arguments1}}
45-
```
39+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsExampleDSL
4640
:::
4741

4842
:::tabs
4943
===Java
50-
```java
51-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:arguments2}}
52-
```
44+
<<< @/../reference-code/src/main/java/createcommands/arguments/Arguments.java#registerArgumentsVarargExample
5345
===Kotlin
54-
```kotlin
55-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:arguments2}}
56-
```
46+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsVarargExample
5747
===Kotlin DSL
58-
```kotlin
59-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:arguments2}}
60-
```
48+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsVarargExampleDSL
6149
:::
6250

6351
:::tabs
6452
===Java
65-
```java
66-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:arguments3}}
67-
```
53+
<<< @/../reference-code/src/main/java/createcommands/arguments/Arguments.java#registerArgumentsListExample
6854
===Kotlin
69-
```kotlin
70-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:arguments3}}
71-
```
55+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsListExample
7256
===Kotlin DSL
73-
```kotlin
74-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:arguments3}}
75-
```
57+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#registerArgumentsListExampleDSL
7658
:::
7759

7860
## Argument Casting
@@ -81,17 +63,11 @@ To access arguments, they have to be casted to the type that the argument repres
8163

8264
:::tabs
8365
===Java
84-
```java
85-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:arguments4}}
86-
```
66+
<<< @/../reference-code/src/main/java/createcommands/arguments/Arguments.java#argumentCastExample
8767
===Kotlin
88-
```kotlin
89-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:arguments4}}
90-
```
68+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#argumentCastExample
9169
===Kotlin DSL
92-
```kotlin
93-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:arguments4}}
94-
```
70+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/Arguments.kt#argumentCastExampleDSL
9571
:::
9672

9773
The type to cast each argument (declared in the `dev.jorel.commandapi.arguments` package) is listed below:

docs/en/create-commands/arguments/command-arguments.md

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,9 @@ This is how these commands are implemented:
108108

109109
:::tabs
110110
===Java
111-
```java
112-
{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:commandArguments1}}
113-
```
111+
<<< @/../reference-code/src/main/java/createcommands/arguments/CommandArguments.java#getArgExample
114112
===Kotlin
115-
```kotlin
116-
{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:commandArguments1}}
117-
```
113+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/CommandArguments.kt#getArgExample
118114
:::
119115

120116
::::
@@ -161,7 +157,7 @@ Optional<String> getRawOptional(int index);
161157

162158
::::tip Example - Access raw arguments by node name and index
163159

164-
To demonstrate how to access raw arguments, we are going to implement the `/mycommand` again, this time with the following syntax:
160+
To demonstrate how to access raw arguments, we’re going to implement the `/mycommand` again, this time with the following syntax:
165161

166162
```mccmd
167163
/mycommand <entities>
@@ -171,13 +167,9 @@ We want to find out which entity selector is being used when the command is exec
171167

172168
:::tabs
173169
===Java
174-
```java
175-
{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:commandArguments2}}
176-
```
170+
<<< @/../reference-code/src/main/java/createcommands/arguments/CommandArguments.java#getRawExample
177171
===Kotlin
178-
```kotlin
179-
{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:commandArguments2}}
180-
```
172+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/CommandArguments.kt#getRawExample
181173
:::
182174

183175
::::
@@ -192,7 +184,7 @@ Unsafe arguments provide the ability to access an argument without needing to ca
192184
String name = (String) args.get("name");
193185
```
194186

195-
When using unsafe arguments you can make your code look like this:
187+
When using unsafe arguments, you can make your code look like this:
196188

197189
```java
198190
String name = args.getUnchecked("name");
@@ -202,7 +194,7 @@ Unsafe arguments can also be accessed by their node names and their indices.
202194

203195
### Access arguments by node name
204196

205-
Unsafe arguments can also be accessed by node name which, again, is the recommended way of doing it.
197+
Node name can also access unsafe arguments which, again, is the recommended way of doing it.
206198

207199
Use these methods when accessing unsafe arguments by their node name:
208200

@@ -236,13 +228,9 @@ Here, we don't actually want to cast the argument, so we use unsafe arguments to
236228

237229
:::tabs
238230
===Java
239-
```java
240-
{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:commandArguments3}}
241-
```
231+
<<< @/../reference-code/src/main/java/createcommands/arguments/CommandArguments.java#getUncheckedExample
242232
===Kotlin
243-
```kotlin
244-
{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:commandArguments3}}
245-
```
233+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/CommandArguments.kt#getUncheckedExample
246234
:::
247235

248236
::::
@@ -251,11 +239,12 @@ Here, we don't actually want to cast the argument, so we use unsafe arguments to
251239

252240
:::warning **Developer's Note:**
253241

254-
The following methods cannot be used to access a value returned by a `CustomArgument` as its return type depends on the base argument for it.
242+
The following methods can’t be used to access a value returned by a `CustomArgument` as its return type depends on the base argument for it.
255243

256244
:::
257245

258-
Lastly, the CommandArguments class offers you a way to access your arguments in a more safe way by using internal casts. Again, methods are offered to access arguments by their
246+
Lastly, the CommandArguments class offers you a way to access your arguments in a safer way by using internal casts.
247+
Again, methods are offered to access arguments by their
259248
index or their node name:
260249

261250
```java
@@ -296,17 +285,13 @@ T getOptionalByArgument(Argument<T> argumentType);
296285
However, while safer, this also introduces the need to first initialize your arguments before you can start implementing your command.
297286
To visualize this, we want to implement the command from [Access arguments by node name and index](#access-arguments-by-index) again, but this time using safe arguments with an argument instance:
298287

299-
::::tip Example - Access safe arguments using an argument instance
288+
::::tip Example Access safe arguments using an argument instance
300289

301290
:::tabs
302291
===Java
303-
```java
304-
{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:commandArguments4}}
305-
```
292+
<<< @/../reference-code/src/main/java/createcommands/arguments/CommandArguments.java#getByArgumentExample
306293
===Kotlin
307-
```kotlin
308-
{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:commandArguments4}}
309-
```
294+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/CommandArguments.kt#getByArgumentExample
310295
:::
311296

312297
::::

docs/en/create-commands/arguments/listed-arguments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ authors:
88

99
# Listed arguments
1010

11-
Arguments have a setting which determine whether they are present in the [`CommandArguments args`](./command-arguments) that is populated when executing a command.
11+
Arguments have a setting that determines whether they’re present in the [`CommandArguments args`](./command-arguments) that is populated when executing a command.
1212

1313
By default, the `LiteralArgument` has this setting set to `false`, hence the literal values are _not_ present in the [`CommandArguments args`](command-arguments).
1414

docs/en/create-commands/arguments/optional-arguments.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ authors:
77

88
# Optional Arguments
99

10-
Sometimes, you want to implement a command that has arguments that do not need to be entered. Take a `/sayhi` command for example. You may want to say "Hi" to yourself, or to another player. For that, we want this command syntax:
10+
Sometimes, you want to implement a command that has arguments that don’t need to be entered. Take a `/sayhi` command for example. You may want to say "Hi" to yourself or to another player. For that, we want this command syntax:
1111

1212
```mccmd
1313
/sayhi - Says "Hi!" to yourself
@@ -30,7 +30,7 @@ For example, say we're registering a command `/sayhi`:
3030
/sayhi <target> - Says "Hi!" to a target player
3131
```
3232

33-
For that, we are going to register a command `/sayhi`. To add optional arguments, we are going to use the `withOptionalArguments(Argument... args)` method:
33+
For that, we’re going to register a command `/sayhi`. To add optional arguments, we’re going to use the `withOptionalArguments(Argument... args)` method:
3434

3535
:::tabs
3636
===Java
@@ -48,7 +48,7 @@ For that, we are going to register a command `/sayhi`. To add optional arguments
4848
:::
4949

5050

51-
This gives us the ability to run both `/sayhi` and `/sayhi <target>` with the same command name "sayhi", but have different results based on the arguments used.
51+
This allows us to run both `/sayhi` and `/sayhi <target>` with the same command name `sayhi`, but have different results based on the arguments used.
5252

5353
You can notice two things:
5454

@@ -61,7 +61,7 @@ With optional arguments, there is a possibility of them being not present in the
6161

6262
## Setting existing arguments as optional arguments
6363

64-
In order to set arguments as optional the CommandAPI has the method `setOptional(boolean)`:
64+
To set arguments as optional, the CommandAPI has the method `setOptional(boolean)`:
6565

6666
```java
6767
Argument setOptional(boolean optional);
@@ -96,7 +96,7 @@ Optional<Object> getOptional(String nodeName)
9696

9797
The examples will be using the `getOptional` methods but there is no downside of using the `getOrDefault` methods.
9898

99-
:::tip Example - `/sayhi` command while using the getOptional method
99+
::::tip Example - `/sayhi` command while using the getOptional method
100100

101101
Let's register the `/sayhi` command from above a second time - this time using a `getOptional` method. We are using the exact same command syntax:
102102

@@ -139,9 +139,13 @@ You will need to use this method if you want to have a required argument after a
139139
1. You have a `CommandAPICommand` and you add arguments to it.
140140
2. After your required arguments, you can provide optional arguments.
141141

142-
At this point your command is basically done. Any attempt to add a required argument will result in an `OptionalArgumentException`. However, this is where the `combineWith` method comes in.
143-
This method allows you to combine arguments. Let's say you have an optional `StringArgument` (here simplified to `A`) and you want a required `PlayerArgument` (here simplified to `B`).
144-
Argument `B` should only be required if argument `A` is given. To implement that logic, we are going to use the `combineWith` method so that we have this syntax:
142+
At this point, your command is basically done.
143+
Any attempt to add a required argument will result in an `OptionalArgumentException`.
144+
However, this is where the `combineWith` method comes in.
145+
This method allows you to combine arguments.
146+
Let's say you have an optional `StringArgument` (here simplified to `A`) and you want a required `PlayerArgument` (here simplified to `B`).
147+
Argument `B` should only be required if argument `A` is given.
148+
To implement that logic, we’re going to use the `combineWith` method so that we have this syntax:
145149

146150
```java
147151
A.combineWith(B)
@@ -168,7 +172,7 @@ new CommandAPICommand("mycommand")
168172
.withArguments(C)
169173
```
170174

171-
This would result in an `OptionalArgumentException` because you are declaring a required argument after an optional argument without creating that exception for argument `C` like you do for argument `B`.
175+
This would result in an `OptionalArgumentException` because you’re declaring a required argument after an optional argument without creating that exception for argument `C` like you do for argument `B`.
172176

173177
::::tip Example - Required arguments after optional arguments
174178

@@ -180,7 +184,7 @@ We want to register a command `/rate` with the following syntax:
180184
/rate <topic> <rating> <target> - Rates a topic with a rating and sends a message to the target
181185
```
182186

183-
To implement that structure we make use of the `combineWith` method to make the argument after the optional argument \<topic> required:
187+
To implement that structure, we make use of the `combineWith` method to make the argument after the optional argument \<topic> required:
184188

185189
:::tabs
186190
===Java

docs/en/create-commands/arguments/suggestions/async-suggestions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ authors:
88

99
# Asynchronous suggestions
1010

11-
In addition to normal suggestions, safely-typed suggestions and suggestions with tooltips, the CommandAPI can support computing the list of suggestions to send to a player asynchronously. This allows you to perform suggestions independent of the main server thread, which is useful for slow operations, such as:
11+
In addition to normal suggestions, safely typed suggestions and suggestions with tooltips, the CommandAPI can support computing the list of suggestions to send to a player asynchronously. This allows you to perform suggestions independent of the main server thread, which is useful for slow operations, such as:
1212

1313
- Retrieving suggestions from a remote database
1414
- Retrieving information from the web
@@ -54,7 +54,7 @@ CompletableFuture.supplyAsync(() -> {
5454

5555
## Asynchronous suggestions examples
5656

57-
::::tip Example - Reading keys from a config file
57+
::::tip Example Reading keys from a config file
5858

5959
Say you wanted to write a command to modify your plugin's config file. Since the config file is an external file, you ideally want to access the file in a separate thread to the main server thread to retain performance for players on the server. We have the following command syntax:
6060

docs/en/create-commands/arguments/suggestions/safe-suggestions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ authors:
99

1010
# Type-Safe suggestions
1111

12-
So far, we've covered how to replace suggestions using the `replaceSuggestions()` method. The issue with using strings for suggestion listings is that they are prone to errors - it is possible to suggest something which is not actually a valid argument, which makes that suggestion unusable. As a result, some arguments include the `replaceSafeSuggestions()`, which provides type-safety checks for argument suggestions, as well as automatic "Bukkit-to-suggestion" conversion.
12+
So far, we've covered how to replace suggestions using the `replaceSuggestions()` method. The issue with using strings for suggestion listings is that they’re prone to errors - it is possible to suggest something, which is not actually a valid argument, which makes that suggestion unusable. As a result, some arguments include the `replaceSafeSuggestions()`, which provides type-safety checks for argument suggestions, as well as automatic "Bukkit-to-suggestion" conversion.
1313

14-
The whole point of the safe argument suggestions method is that parameters entered this method are **guaranteed** to work.
14+
The whole point of the safe argument suggestions method is that parameters entered in this method are **guaranteed** to work.
1515

1616
The use of the safe replace suggestions function is the same as `replaceSuggestions()` from the previous section, except instead of returning a `String[]`, you now return a `T[]`, where `T` is the class corresponding to the argument. This is described in more detail in the table below.
1717

@@ -40,7 +40,7 @@ SafeSuggestions<T> tooltipsAsync(Function<SuggestionInfo, CompletableFuture<Tool
4040

4141
Not all arguments support safe suggestions. This is mostly due to implementation constraints or inadequate support by the Bukkit API.
4242

43-
The list of supported arguments are displayed in the following table. The parameter `T` (shown in the method signatures above) are also provided for each argument. This parameter is the same as the cast argument described in [Argument Casting](../command-arguments#argument-casting), except for a few exceptions which are outlined in **bold**.
43+
The list of supported arguments is displayed in the following table. The parameter `T` (shown in the method the signatures above) are also provided for each argument. This parameter is the same as the cast argument described in [Argument Casting](../command-arguments#argument-casting), except for a few exceptions which are outlined in **bold**.
4444

4545
| Argument | Class (T) |
4646
|---------------------------------------------------------------------------------:|:-----------------------------------------------|
@@ -92,7 +92,7 @@ These create representations of ticks (e.g. `40t`), days (e.g. `2d`) and seconds
9292

9393
## Safe function arguments
9494

95-
Although all safe arguments are indeed "type-safe", the function argument uses a `NamespacedKey` which cannot be checked fully at compile time. As a result, this is argument should be used with caution - providing a `NamespacedKey` suggestion that does not exist when the server is running will cause that command to fail if that suggestion is used.
95+
Although all safe arguments are indeed "type-safe", the function argument uses a `NamespacedKey` which cannot be checked fully at compile time. As a result, this is argument should be used with caution - providing a `NamespacedKey` suggestion that doesn’t exist when the server is running will cause that command to fail if that suggestion is used.
9696

9797
## Safe scoreboard slot arguments
9898

0 commit comments

Comments
 (0)