Skip to content

Commit 0830410

Browse files
committed
feat: suggestion pages
1 parent 6f4a67b commit 0830410

File tree

12 files changed

+629
-116
lines changed

12 files changed

+629
-116
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
---
22
order: 6
3+
title: Async suggestions
34
authors:
45
- DerEchtePilz
56
- willkroboth
67
- JorelAli
8+
- MC-XiaoHei
79
---
810

911
# Asynchronous suggestions
@@ -42,7 +44,6 @@ As with all asynchronous operations running in a Minecraft server, you should **
4244

4345
```java
4446
CompletableFuture.supplyAsync(() -> {
45-
4647
Bukkit.getScheduler().scheduleAsyncDelayedTask(plugin, () ->
4748
// Your code here
4849
);
@@ -66,13 +67,11 @@ We make use of the `ArgumentSuggestions.stringsAsync` method to provide asynchro
6667

6768
:::tabs
6869
===Java
69-
```java
70-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:asyncSuggestions1}}
71-
```
70+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/AsyncSuggestions.java#asyncSuggestionsExample
7271
===Kotlin
73-
```kotlin
74-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:asyncSuggestions1}}
75-
```
72+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/AsyncSuggestions.kt#asyncSuggestionsExample
73+
===Kotlin DSL
74+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/AsyncSuggestions.kt#asyncSuggestionsExampleDSL
7675
:::
7776

7877
::::

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

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,18 @@ To do this, we first register our custom items:
121121

122122
:::tabs
123123
===Java
124-
```java
125-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:safeArgumentSuggestions1}}
126-
```
124+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#registerCustomItem
127125
===Kotlin
128-
```kotlin
129-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:safeArgumentSuggestions1}}
130-
```
126+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#registerCustomItem
131127
:::
132128

133129
Once we've done that, we can now include them in our command registration. To do this, we use `replaceSafeSuggestions(recipes)` and then register our command as normal:
134130

135131
:::tabs
136132
===Java
137-
```java
138-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:safeArgumentSuggestions2}}
139-
```
133+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#registerCommandWithSafeSuggestions
140134
===Kotlin
141-
```kotlin
142-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:safeArgumentSuggestions2}}
143-
```
135+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#registerCommandWithSafeSuggestions
144136
:::
145137

146138
::::
@@ -157,44 +149,32 @@ Now say that we don't want non-op players to spawn bosses. To do this, we'll cre
157149

158150
:::tabs
159151
===Java
160-
```java
161-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:safeArgumentSuggestions3}}
162-
```
152+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#createForbiddenMobsList
163153
===Kotlin
164-
```kotlin
165-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:safeArgumentSuggestions3}}
166-
```
154+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#createForbiddenMobsList
167155
:::
168156

169157
We then use our safe arguments to return an `EntityType[]` as the list of values that are suggested to the player. In this example, we use the `sender()` method to determine if the sender has permissions to view the suggestions:
170158

171159
:::tabs
172160
===Java
173-
```java
174-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:safeArgumentSuggestions4}}
175-
```
161+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#createSafeArguments
176162
===Kotlin
177-
```kotlin
178-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:safeArgumentSuggestions4}}
179-
```
163+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#createSafeArguments
180164
:::
181165

182166
Now we register our command as normal:
183167

184168
:::tabs
185169
===Java
186-
```java
187-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:safeArgumentSuggestions5}}
188-
```
170+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#registerSpawnMobCommand
189171
===Kotlin
190-
```kotlin
191-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:safeArgumentSuggestions5}}
192-
```
172+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#registerSpawnMobCommand
193173
:::
194174

195175
::::
196176

197-
:::: Example - Removing a potion effect from a player
177+
::::tip Example Removing a potion effect from a player
198178

199179
Say we wanted to remove a potion effect from a player. To do this, we'll use the following command syntax:
200180

@@ -206,26 +186,18 @@ Now, we don't want to remove a potion effect that doesn't exist on a player, so
206186

207187
:::tabs
208188
===Java
209-
```java
210-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:safeArgumentSuggestions6}}
211-
```
189+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#createSafePotionEffectArguments
212190
===Kotlin
213-
```kotlin
214-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:safeArgumentSuggestions6}}
215-
```
191+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#createSafePotionEffectArguments
216192
:::
217193

218194
And then we can register our command as normal:
219195

220196
:::tabs
221197
===Java
222-
```java
223-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:safeArgumentSuggestions7}}
224-
```
198+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/SafeSuggestions.java#registerRemoveEffectCommand
225199
===Kotlin
226-
```kotlin
227-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:safeArgumentSuggestions7}}
228-
```
200+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/SafeSuggestions.kt#registerRemoveEffectCommand
229201
:::
230202

231203
::::

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ We then implement our warp teleporting command using `replaceSuggestions()` on t
2424

2525
:::tabs
2626
===Java
27-
```java
28-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:stringArgumentSuggestions1}}
29-
```
27+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java#createWarpCommand
3028
===Kotlin
31-
```kotlin
32-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:stringArgumentSuggestions1}}
33-
```
29+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt#createWarpCommand
3430
:::
3531

3632
::::
@@ -53,26 +49,18 @@ Let's say we have a simple class to get the friends of a command sender:
5349

5450
:::tabs
5551
===Java
56-
```java
57-
// todo public {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:stringArgumentSuggestions2}}
58-
```
52+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java#createFriendsClass
5953
===Kotlin
60-
```kotlin
61-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:stringArgumentSuggestions2}}
62-
```
54+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt#createFriendsClass
6355
:::
6456

6557
We can then use this to generate our suggested list of friends:
6658

6759
:::tabs
6860
===Java
69-
```java
70-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:stringArgumentSuggestions3}}
71-
```
61+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java#createFriendCommand
7262
===Kotlin
73-
```kotlin
74-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:stringArgumentSuggestions3}}
75-
```
63+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt#createFriendCommand
7664
:::
7765

7866
::::
@@ -117,13 +105,9 @@ When run, this command will send a message to a target player within the provide
117105

118106
:::tabs
119107
===Java
120-
```java
121-
// todo {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:stringArgumentSuggestions4}}
122-
```
108+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/StringSuggestions.java#createLocalMessageCommand
123109
===Kotlin
124-
```kotlin
125-
// todo {{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:stringArgumentSuggestions4}}
126-
```
110+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/StringSuggestions.kt#createLocalMessageCommand
127111
:::
128112

129113
As shown in this code, we use the `previousArgs()` method access the previously declared arguments. In this example, `info.previousArgs()` will be `{ int }`, where this `int` refers to the radius. Note how this object array only has the previously declared arguments (and not for example `{ int, Player, String }`).

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ First, we'll declare our arguments. Here, we'll use the `stringsWithTooltips` me
5050

5151
:::tabs
5252
===Java
53-
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#stringSuggestionTooltipsExampleDeclare
53+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#createArgumentsWithTooltips
5454
===Kotlin
55-
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#stringSuggestionTooltipsExampleDeclare
55+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#createArgumentsWithTooltips
5656
:::
5757

5858
Finally, we declare our command as normal:
5959

6060
:::tabs
6161
===Java
62-
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#stringSuggestionTooltipsExampleRegister
62+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#registerEmoteCommand
6363
===Kotlin
64-
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#stringSuggestionTooltipsExampleRegister
64+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#registerEmoteCommand
6565
:::
6666

6767
::::
@@ -87,9 +87,9 @@ Let's say we've created a simple plugin which has custom items. For a custom ite
8787

8888
:::tabs
8989
===Java
90-
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#customTooltipExampleDeclare
90+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#createCustomItemClass
9191
===Kotlin
92-
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#customTooltipExampleDeclare
92+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#createCustomItemClass
9393
:::
9494

9595
We make use of the `Tooltip.messageFromString()` method to generate a Brigadier `Message` object from our string tooltip.
@@ -98,9 +98,9 @@ Let's also say that our plugin has registered lots of `CustomItem`s and has this
9898

9999
:::tabs
100100
===Java
101-
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#customTooltipExampleRegister
101+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#registerCustomItemCommand
102102
===Kotlin
103-
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#customTooltipExampleRegister
103+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#registerCustomItemCommand
104104
:::
105105

106106
::::
@@ -144,18 +144,18 @@ First, we'll declare our arguments. Here, we use a `LocationArgument` and use th
144144

145145
:::tabs
146146
===Java
147-
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#tooltipsWithSafeSuggestionsExampleDeclare
147+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#createArgumentsWithTooltipsAndSafeSuggestions
148148
===Kotlin
149-
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#tooltipsWithSafeSuggestionsExampleDeclare
149+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#createArgumentsWithTooltipsAndSafeSuggestions
150150
:::
151151

152152
In the argument declaration, we've cast the command sender to a player. To ensure that the command sender is definitely a player, we'll use the `executesPlayer` command execution method in our command declaration:
153153

154154
:::tabs
155155
===Java
156-
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#tooltipsWithSafeSuggestionsExampleRegister
156+
<<< @/../reference-code/src/main/java/createcommands/arguments/suggestions/Tooltips.java#registerWarpCommand
157157
===Kotlin
158-
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#tooltipsWithSafeSuggestionsExampleRegister
158+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/suggestions/Tooltips.kt#registerWarpCommand
159159
:::
160160

161161
::::
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package createcommands.arguments.suggestions;
2+
3+
import dev.jorel.commandapi.CommandAPICommand;
4+
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
5+
import dev.jorel.commandapi.arguments.StringArgument;
6+
import dev.jorel.commandapi.arguments.TextArgument;
7+
import org.bukkit.plugin.java.JavaPlugin;
8+
9+
import java.util.concurrent.CompletableFuture;
10+
11+
class AsyncSuggestions {
12+
{
13+
JavaPlugin plugin = null;
14+
// #region asyncSuggestionsExample
15+
new CommandAPICommand("setconfig")
16+
.withArguments(new StringArgument("key")
17+
.replaceSuggestions(ArgumentSuggestions.stringsAsync(info ->
18+
CompletableFuture.supplyAsync(() ->
19+
plugin.getConfig().getKeys(false).toArray(new String[0])
20+
)
21+
))
22+
)
23+
.withArguments(new TextArgument("value"))
24+
.executes((sender, args) -> {
25+
String key = (String) args.get("key");
26+
String value = (String) args.get("value");
27+
plugin.getConfig().set(key, value);
28+
})
29+
.register();
30+
// #endregion asyncSuggestionsExample
31+
}
32+
}

0 commit comments

Comments
 (0)