brigadier: Fix MappedArgumentParsers always mapping to string
This commit is contained in:
parent
31d1f85830
commit
2659eac93b
1 changed files with 4 additions and 7 deletions
|
|
@ -385,23 +385,22 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
private <T, K extends ArgumentParser<C, ?>> @Nullable Pair<@NonNull ArgumentType<?>, @Nullable SuggestionProvider<S>> getArgument(
|
private <T, K extends ArgumentParser<C, ?>> @Nullable Pair<@NonNull ArgumentType<?>, @Nullable SuggestionProvider<S>> getArgument(
|
||||||
final @NonNull TypeToken<?> valueType,
|
final @NonNull TypeToken<?> valueType,
|
||||||
final @NonNull TypeToken<T> argumentType,
|
final @NonNull K argumentParser
|
||||||
final @NonNull K argument
|
|
||||||
) {
|
) {
|
||||||
/* Unwrap mapped arguments */
|
/* Unwrap mapped arguments */
|
||||||
ArgumentParser<C, ?> commandArgument = (ArgumentParser<C, ?>) argument;
|
ArgumentParser<C, ?> commandArgument = (ArgumentParser<C, ?>) argumentParser;
|
||||||
while (commandArgument instanceof MappedArgumentParser<?, ?, ?>) {
|
while (commandArgument instanceof MappedArgumentParser<?, ?, ?>) {
|
||||||
commandArgument = ((MappedArgumentParser<C, ?, ?>) commandArgument).getBaseParser();
|
commandArgument = ((MappedArgumentParser<C, ?, ?>) commandArgument).getBaseParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
final BrigadierMapping<C, K, S> mapping = (BrigadierMapping<C, K, S>) this.mappers
|
final BrigadierMapping<C, K, S> mapping = (BrigadierMapping<C, K, S>) this.mappers
|
||||||
.get(GenericTypeReflector.erase(argumentType.getType()));
|
.get(commandArgument.getClass());
|
||||||
if (mapping == null || mapping.getMapper() == null) {
|
if (mapping == null || mapping.getMapper() == null) {
|
||||||
return this.createDefaultMapper(valueType);
|
return this.createDefaultMapper(valueType);
|
||||||
}
|
}
|
||||||
return Pair.of(
|
return Pair.of(
|
||||||
(ArgumentType<?>) ((Function) mapping.getMapper()).apply(commandArgument),
|
(ArgumentType<?>) ((Function) mapping.getMapper()).apply(commandArgument),
|
||||||
mapping.makeSuggestionProvider(argument)
|
mapping.makeSuggestionProvider(argumentParser)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -527,7 +526,6 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
@SuppressWarnings("unchecked") final ArgumentParser<C, ?> parser = (ArgumentParser<C, ?>) parsers[i];
|
@SuppressWarnings("unchecked") final ArgumentParser<C, ?> parser = (ArgumentParser<C, ?>) parsers[i];
|
||||||
final Pair<ArgumentType<?>, SuggestionProvider<S>> pair = this.getArgument(
|
final Pair<ArgumentType<?>, SuggestionProvider<S>> pair = this.getArgument(
|
||||||
TypeToken.get((Class<?>) types[i]),
|
TypeToken.get((Class<?>) types[i]),
|
||||||
TypeToken.get(parser.getClass()),
|
|
||||||
parser
|
parser
|
||||||
);
|
);
|
||||||
final SuggestionProvider<S> provider = pair.getSecond() == delegateSuggestions() ? suggestionProvider
|
final SuggestionProvider<S> provider = pair.getSecond() == delegateSuggestions() ? suggestionProvider
|
||||||
|
|
@ -576,7 +574,6 @@ public final class CloudBrigadierManager<C, S> {
|
||||||
// Register argument
|
// Register argument
|
||||||
final Pair<ArgumentType<?>, SuggestionProvider<S>> pair = this.getArgument(
|
final Pair<ArgumentType<?>, SuggestionProvider<S>> pair = this.getArgument(
|
||||||
root.getValue().getValueType(),
|
root.getValue().getValueType(),
|
||||||
TypeToken.get(root.getValue().getParser().getClass()),
|
|
||||||
root.getValue().getParser()
|
root.getValue().getParser()
|
||||||
);
|
);
|
||||||
final SuggestionProvider<S> provider = pair.getSecond() == delegateSuggestions()
|
final SuggestionProvider<S> provider = pair.getSecond() == delegateSuggestions()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue