/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.gson.JsonPrimitive * com.mojang.brigadier.ImmutableStringReader * com.mojang.brigadier.StringReader * com.mojang.brigadier.arguments.ArgumentType * com.mojang.brigadier.context.CommandContext * com.mojang.brigadier.exceptions.CommandSyntaxException * com.mojang.brigadier.exceptions.DynamicCommandExceptionType * com.mojang.brigadier.suggestion.Suggestions * com.mojang.brigadier.suggestion.SuggestionsBuilder * com.mojang.serialization.Codec * com.mojang.serialization.DynamicOps * com.mojang.serialization.JsonOps */ package net.minecraft.commands.arguments; import com.google.gson.JsonPrimitive; import com.mojang.brigadier.ImmutableStringReader; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import com.mojang.serialization.Codec; import com.mojang.serialization.DynamicOps; import com.mojang.serialization.JsonOps; import java.util.Arrays; import java.util.Collection; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; import java.util.stream.Collectors; import net.minecraft.commands.SharedSuggestionProvider; import net.minecraft.network.chat.Component; import net.minecraft.util.StringRepresentable; public class StringRepresentableArgument> implements ArgumentType { private static final DynamicCommandExceptionType ERROR_INVALID_VALUE = new DynamicCommandExceptionType(value -> Component.translatableEscape("argument.enum.invalid", value)); private final Codec codec; private final Supplier values; protected StringRepresentableArgument(Codec codec, Supplier values) { this.codec = codec; this.values = values; } public T parse(StringReader reader) throws CommandSyntaxException { String id = reader.readUnquotedString(); return (T)((Enum)this.codec.parse((DynamicOps)JsonOps.INSTANCE, (Object)new JsonPrimitive(id)).result().orElseThrow(() -> ERROR_INVALID_VALUE.createWithContext((ImmutableStringReader)reader, (Object)id))); } public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { return SharedSuggestionProvider.suggest(Arrays.stream((Enum[])this.values.get()).map(rec$ -> ((StringRepresentable)rec$).getSerializedName()).map(this::convertId).collect(Collectors.toList()), builder); } public Collection getExamples() { return Arrays.stream((Enum[])this.values.get()).map(rec$ -> ((StringRepresentable)rec$).getSerializedName()).map(this::convertId).limit(2L).collect(Collectors.toList()); } protected String convertId(String id) { return id; } }