Skip to content

Commit

Permalink
Add ArgumentType.parse() overload that can accept source context
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Aug 7, 2024
1 parent b92c420 commit b5419b1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
majorMinor: 1.2
majorMinor: 1.3
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
public interface ArgumentType<T> {
T parse(StringReader reader) throws CommandSyntaxException;

default <S> T parse(final StringReader reader, final S source) throws CommandSyntaxException {
return parse(reader);
}

default <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder) {
return Suggestions.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public SuggestionProvider<S> getCustomSuggestions() {
@Override
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
final int start = reader.getCursor();
final T result = type.parse(reader);
final T result = type.parse(reader, contextBuilder.getSource());
final ParsedArgument<S, T> parsed = new ParsedArgument<>(start, reader.getCursor(), result);

contextBuilder.withArgument(name, parsed);
Expand Down

0 comments on commit b5419b1

Please sign in to comment.