/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.brigadier.context.CommandContext * com.mojang.brigadier.exceptions.CommandSyntaxException * com.mojang.brigadier.suggestion.SuggestionProvider * com.mojang.brigadier.suggestion.Suggestions * com.mojang.brigadier.suggestion.SuggestionsBuilder */ package net.minecraft.commands.synchronization; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; import net.minecraft.commands.SharedSuggestionProvider; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.Identifier; import net.minecraft.world.entity.EntityType; public class SuggestionProviders { private static final Map> PROVIDERS_BY_NAME = new HashMap>(); private static final Identifier ID_ASK_SERVER = Identifier.withDefaultNamespace("ask_server"); public static final SuggestionProvider ASK_SERVER = SuggestionProviders.register(ID_ASK_SERVER, (SuggestionProvider)((SuggestionProvider)(c, p) -> ((SharedSuggestionProvider)c.getSource()).customSuggestion(c))); public static final SuggestionProvider AVAILABLE_SOUNDS = SuggestionProviders.register(Identifier.withDefaultNamespace("available_sounds"), (SuggestionProvider)((SuggestionProvider)(c, p) -> SharedSuggestionProvider.suggestResource(((SharedSuggestionProvider)c.getSource()).getAvailableSounds(), p))); public static final SuggestionProvider SUMMONABLE_ENTITIES = SuggestionProviders.register(Identifier.withDefaultNamespace("summonable_entities"), (SuggestionProvider)((SuggestionProvider)(c, p) -> SharedSuggestionProvider.suggestResource(BuiltInRegistries.ENTITY_TYPE.stream().filter(entityType -> entityType.isEnabled(((SharedSuggestionProvider)c.getSource()).enabledFeatures()) && entityType.canSummon()), p, EntityType::getKey, EntityType::getDescription))); public static SuggestionProvider register(Identifier name, SuggestionProvider provider) { SuggestionProvider previous = PROVIDERS_BY_NAME.putIfAbsent(name, provider); if (previous != null) { throw new IllegalArgumentException("A command suggestion provider is already registered with the name '" + String.valueOf(name) + "'"); } return new RegisteredSuggestion(name, provider); } public static SuggestionProvider cast(SuggestionProvider provider) { return provider; } public static SuggestionProvider getProvider(Identifier name) { return SuggestionProviders.cast(PROVIDERS_BY_NAME.getOrDefault(name, ASK_SERVER)); } public static Identifier getName(SuggestionProvider provider) { Identifier identifier; if (provider instanceof RegisteredSuggestion) { RegisteredSuggestion registeredProvider = (RegisteredSuggestion)provider; identifier = registeredProvider.name; } else { identifier = ID_ASK_SERVER; } return identifier; } private record RegisteredSuggestion(Identifier name, SuggestionProvider delegate) implements SuggestionProvider { public CompletableFuture getSuggestions(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { return this.delegate.getSuggestions(context, builder); } } }