mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 19:59:42 +00:00
Fix EnumArgument to use enum names for suggestions (#8728)
Previously, the suggestions used the string representation of the enum through Enum#toString, which can differ from the name of the enum as required by Enum#valueOf, causing invalid suggestions (both in gui and through the error message).
This commit is contained in:
1 parent
5979636ee5
commit
915d570b17
1 file changed
+3
-3
@@ -43,18 +43,18 @@ public class EnumArgument<T extends Enum<T>> implements ArgumentType<T> {
|
||||
try {
|
||||
return Enum.valueOf(enumClass, name);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw INVALID_ENUM.createWithContext(reader, name, Arrays.toString(enumClass.getEnumConstants()));
|
||||
throw INVALID_ENUM.createWithContext(reader, name, Arrays.toString(Arrays.stream(enumClass.getEnumConstants()).map(Enum::name).toArray()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder) {
|
||||
return SharedSuggestionProvider.suggest(Stream.of(enumClass.getEnumConstants()).map(Object::toString), builder);
|
||||
return SharedSuggestionProvider.suggest(Stream.of(enumClass.getEnumConstants()).map(Enum::name), builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getExamples() {
|
||||
return Stream.of(enumClass.getEnumConstants()).map(Object::toString).collect(Collectors.toList());
|
||||
return Stream.of(enumClass.getEnumConstants()).map(Enum::name).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static class Info<T extends Enum<T>> implements ArgumentTypeInfo<EnumArgument<T>, Info<T>.Template>
|
||||
|
||||
Reference in new issue
Block a user