Skip to content

Commit ffbc2ac

Browse files
Apply suggestions from code review
Co-authored-by: Matouš Kučera <mk@kcra.me>
1 parent c895bf7 commit ffbc2ac

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

docs/paper/dev/api/command-api/basics/custom-arguments.mdx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public final class OppedPlayerArgument implements CustomArgumentType<Player, Pla
5555
@Override
5656
public <S> Player parse(StringReader reader, S source) throws CommandSyntaxException {
5757
if (!(source instanceof CommandSourceStack stack)) {
58-
final Message message = MessageComponentSerializer.message().serialize(text("The source needs to be a CommandSourceStack!"));
58+
final Message message = MessageComponentSerializer.message().serialize(Component.text("The source needs to be a CommandSourceStack!"));
5959
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
6060
}
6161

6262
final Player player = getNativeType().parse(reader).resolve(stack).getFirst();
6363
if (!player.isOp()) {
64-
final Message message = MessageComponentSerializer.message().serialize(text(player.getName() + " is not a server operator!"));
64+
final Message message = MessageComponentSerializer.message().serialize(Component.text(player.getName() + " is not a server operator!"));
6565
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
6666
}
6767

@@ -100,7 +100,7 @@ Commands.argument("player", new OppedPlayerArgument())
100100
})
101101
```
102102

103-
This is way more readable and easy to understand than without custom argument. And it is reusable! Hopefully, you now have a basic grasp of **why** you should use custom arguments.
103+
This is way more readable and easy to understand when using a custom argument. And it is reusable! Hopefully, you now have a basic grasp of **why** you should use custom arguments.
104104

105105
## Examining the `CustomArgumentType` interface
106106
The interface is declared as follows:
@@ -136,18 +136,18 @@ public interface CustomArgumentType<T, N> extends ArgumentType<T> {
136136

137137
### Generic types
138138
There are three generic types present in the interface:
139-
- `T`: This is the type of the class that is returned when `CommandContext#getArgument` is called on this argument
140-
- `N`: The native type of the class which this custom argument extends. Used as the "underlying" argument
139+
- `T`: This is the type of the class that is returned when `CommandContext#getArgument` is called on this argument.
140+
- `N`: The native type of the class which this custom argument extends. Used as the "underlying" argument.
141141
- `S`: A generic type for the command source. Will usually be a `CommandSourceStack`.
142142

143143
### Methods
144144
| Method declaration | Description |
145145
|---------------------------------------------------------------------------------------------------------------------------------|--------------|
146-
| `ArgumentType<N> getNativeType()` | Here, you declare the underlying argument type which is used as a base for clientside argument validation |
147-
| `T parse(final StringReader reader) throws CommandSyntaxException` | This method is used if `T parse(StringReader, S)` was not overwritten. In here you can run conversion and validation logic. |
148-
| `default <S> T parse(final StringReader reader, final S source)` | If overwritten, this method will be preferred to `T parse(StringReader)`. It serves the same purpose, but allows to also include the source in the parsing logic.
149-
| `default Collection<String> getExamples()` | This method should **not** be extended. It is used internally to differentiate certain argument types while parsing. |
150-
| `default <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder)` | This method is the equivalent of `RequiredArgumentBuilder#suggests(SuggestionProvider<S>)`. You can overwrite this method in order to send your own suggestions to the client. |
146+
| `ArgumentType<N> getNativeType()` | Here, you declare the underlying argument type, which is used as a base for client-side argument validation. |
147+
| `T parse(final StringReader reader) throws CommandSyntaxException` | This method is used if `T parse(StringReader, S)` is not overridden. In here, you can run conversion and validation logic. |
148+
| `default <S> T parse(final StringReader reader, final S source)` | If overridden, this method will be preferred to `T parse(StringReader)`. It serves the same purpose, but allows including the source in the parsing logic.
149+
| `default Collection<String> getExamples()` | This method should **not** be overridden. It is used internally to differentiate certain argument types while parsing. |
150+
| `default <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder)` | This method is the equivalent of `RequiredArgumentBuilder#suggests(SuggestionProvider<S>)`. You can override this method in order to send your own suggestions to the client. |
151151

152152
### A very basic implementation
153153
```java
@@ -179,7 +179,7 @@ you can also manually read input. Here, we read an unquoted string, the same as
179179

180180
## `CustomArgumentType.Converted<T, N>`
181181
In case that you need to parse the native type to your new type, you can instead use the `CustomArgumentType.Converted` interface.
182-
This interface is an extension to the `CustomArgumentType` interface, which adds two new, overwritable methods:
182+
This interface is an extension to the `CustomArgumentType` interface, which adds two new, overridable methods:
183183

184184
```java
185185
T convert(N nativeType) throws CommandSyntaxException;

0 commit comments

Comments
 (0)