You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes, you want to send your own suggestions to users. For this, you can use the `RequiredArgumentBuilder#suggests(SuggestionProvider)` method.
11
+
Sometimes, you want to send your own suggestions to users. For this, you can use the `suggests(SuggestionProvider<CommandSourceStack>)` method when declaring
12
+
arguments.
12
13
13
-
## Examining the `SuggestionProvider<S>` method
14
+
## Examining `SuggestionProvider<S>`
14
15
The `SuggestionProvider<S>` interface is defined as follows:
15
16
16
17
```java title="SuggestionProvider.java"
@@ -20,26 +21,25 @@ public interface SuggestionProvider<S> {
20
21
}
21
22
```
22
23
23
-
Similar to other classes or interfaces with a `<S>` generic parameter, for Paper, this usually is a `CommandSourceStack`. Furthermore, similar to the `Command<S>` interface,
24
+
Similar to other classes or interfaces with a `<S>` generic parameter, for Paper, this is usually a `CommandSourceStack`. Furthermore, similar to the `Command<S>` interface,
24
25
this is a functional interface, which means that instead of passing in a class which implements this interface, we can just pass a lambda statement or a method reference.
25
26
26
-
Our lambda/method requires two parameters, `CommandContext<S>` and `SuggestionsBuilder`, returning a `CompletableFuture<Suggestions>`.
27
-
In order to retrieve our return value, we can just run `SuggestionsBuilder#buildFuture()` (or `SuggestionsBuilder#build()`, if we already are inside a CompletableFuture).
27
+
Our lambda consists of two parameters, `CommandContext<S>` and `SuggestionsBuilder`, and expects to have a `CompletableFuture<Suggestions>` returned.
28
28
29
29
A very simple lambda for our `suggests` method might look like this:
There are two methods we can use to build our suggestions. The only difference between the both are that one directly returns the finished `Suggestions` object,
76
+
There are two methods we can use to build our `Suggestions` object. The only difference between those is that one directly returns the finished `Suggestions` object,
78
77
whilst the other one returns a `CompletableFuture<Suggestions>`.
79
78
80
-
The reason for these two methods is that the `SuggestionProvider`'s method requires the return value to be a`CompletableFuture<Suggestions>`. This for once
81
-
allows for constructing your suggestions asynchronously inside a `CompletableFuture.supplyAsync(Supplier<Suggestions>)` or synchronously directly inside our
82
-
lambda/method and only returning the final `Suggestions` object asynchronously.
79
+
The reason for these two methods is that `SuggestionProvider` expects the return value to be `CompletableFuture<Suggestions>`. This for once
80
+
allows for constructing your suggestions asynchronously inside a `CompletableFuture.supplyAsync(Supplier<Suggestions>)`statement, or synchronously directly inside our
81
+
lambda and returning the final `Suggestions` object asynchronously.
83
82
84
83
Here are the same suggestions declared in the two different ways mentioned above:
In commands where you give players certain items, you oftentimes include an amount argument. We could suggest `1`, `16`, `32`, and `64` as common amounts for
104
+
## Example: Suggesting amounts in a give item command
105
+
In commands, where you give players items, you oftentimes include an amount argument. We could suggest `1`, `16`, `32`, and `64` as common amounts for
107
106
items given. The command implementation could look like this:
108
107
109
108
```java
@@ -196,5 +195,5 @@ public static LiteralCommandNode<CommandSourceStack> constructStringSuggestionsC
196
195
}
197
196
```
198
197
199
-
And as you can see in the preview below, this simple setup filters suggestions by user input, providing a smooth user experience when using your command:
198
+
This simple setup filters suggestions by user input, providing a smooth user experience when running the command:
0 commit comments