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
Copy file name to clipboardExpand all lines: docs/paper/dev/api/command-api/basics/argument-suggestions.mdx
+29-20Lines changed: 29 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,22 +20,19 @@ public interface SuggestionProvider<S> {
20
20
}
21
21
```
22
22
23
-
Similar to the `Command<S>`interface, this is a functional interface, which means that instead of passing in a class which implements this interface,
24
-
we can just pass a lambda statement or a method reference.
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
+
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
25
26
-
Our lambda/method requires two parameters: `CommandContext<S>` and `SuggestionsBuilder`. The lambda/method has to return 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 completeable
28
-
future).
29
-
30
-
Similar to other classes or interfaces with a `<S>` generic parameter, for Paper, this usually is a `CommandSourceStack`.
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).
31
28
32
29
A very simple lambda for our `suggests` method might look like this:
In commands where you give players certain items, you oftentimes include an amount argument. We could suggest `1`, `32`, and `64` as common amounts for
107
-
items given. This could look like this:
103
+
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
+
items given. The command implementation could look like this:
108
105
109
106
```java
110
107
@NullMarked
@@ -113,22 +110,29 @@ public class SuggestionsTest {
0 commit comments