/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.base.CharMatcher * com.google.common.base.Strings * com.google.common.collect.Lists * com.mojang.brigadier.Message * com.mojang.brigadier.context.CommandContext * com.mojang.brigadier.suggestion.Suggestions * com.mojang.brigadier.suggestion.SuggestionsBuilder */ package net.minecraft.commands; import com.google.common.base.CharMatcher; import com.google.common.base.Strings; import com.google.common.collect.Lists; import com.mojang.brigadier.Message; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Locale; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Stream; import net.minecraft.core.HolderLookup; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; import net.minecraft.resources.Identifier; import net.minecraft.resources.ResourceKey; import net.minecraft.server.permissions.PermissionSetSupplier; import net.minecraft.tags.TagKey; import net.minecraft.world.flag.FeatureFlagSet; import net.minecraft.world.level.Level; public interface SharedSuggestionProvider extends PermissionSetSupplier { public static final CharMatcher MATCH_SPLITTER = CharMatcher.anyOf((CharSequence)"._/"); public Collection getOnlinePlayerNames(); default public Collection getCustomTabSugggestions() { return this.getOnlinePlayerNames(); } default public Collection getSelectedEntities() { return Collections.emptyList(); } public Collection getAllTeams(); public Stream getAvailableSounds(); public CompletableFuture customSuggestion(CommandContext var1); default public Collection getRelevantCoordinates() { return Collections.singleton(TextCoordinates.DEFAULT_GLOBAL); } default public Collection getAbsoluteCoordinates() { return Collections.singleton(TextCoordinates.DEFAULT_GLOBAL); } public Set> levels(); public RegistryAccess registryAccess(); public FeatureFlagSet enabledFeatures(); default public void suggestRegistryElements(HolderLookup registry, ElementSuggestionType elements, SuggestionsBuilder builder) { if (elements.shouldSuggestTags()) { SharedSuggestionProvider.suggestResource(registry.listTagIds().map(TagKey::location), builder, "#"); } if (elements.shouldSuggestElements()) { SharedSuggestionProvider.suggestResource(registry.listElementIds().map(ResourceKey::identifier), builder); } } public static CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder, ResourceKey> registryKey, ElementSuggestionType type) { Object object = context.getSource(); if (object instanceof SharedSuggestionProvider) { SharedSuggestionProvider suggestionProvider = (SharedSuggestionProvider)object; return suggestionProvider.suggestRegistryElements(registryKey, type, builder, context); } return builder.buildFuture(); } public CompletableFuture suggestRegistryElements(ResourceKey> var1, ElementSuggestionType var2, SuggestionsBuilder var3, CommandContext var4); public static void filterResources(Iterable values, String contents, Function converter, Consumer consumer) { boolean hasNamespace = contents.indexOf(58) > -1; for (T value : values) { Identifier id = converter.apply(value); if (hasNamespace) { String name = id.toString(); if (!SharedSuggestionProvider.matchesSubStr(contents, name)) continue; consumer.accept(value); continue; } if (!SharedSuggestionProvider.matchesSubStr(contents, id.getNamespace()) && !SharedSuggestionProvider.matchesSubStr(contents, id.getPath())) continue; consumer.accept(value); } } public static void filterResources(Iterable values, String contents, String prefix, Function converter, Consumer consumer) { if (contents.isEmpty()) { values.forEach(consumer); } else { String commonPrefix = Strings.commonPrefix((CharSequence)contents, (CharSequence)prefix); if (!commonPrefix.isEmpty()) { String strippedContents = contents.substring(commonPrefix.length()); SharedSuggestionProvider.filterResources(values, strippedContents, converter, consumer); } } } public static CompletableFuture suggestResource(Iterable values, SuggestionsBuilder builder, String prefix) { String contents = builder.getRemaining().toLowerCase(Locale.ROOT); SharedSuggestionProvider.filterResources(values, contents, prefix, t -> t, v -> builder.suggest(prefix + String.valueOf(v))); return builder.buildFuture(); } public static CompletableFuture suggestResource(Stream values, SuggestionsBuilder builder, String prefix) { return SharedSuggestionProvider.suggestResource(values::iterator, builder, prefix); } public static CompletableFuture suggestResource(Iterable values, SuggestionsBuilder builder) { String contents = builder.getRemaining().toLowerCase(Locale.ROOT); SharedSuggestionProvider.filterResources(values, contents, t -> t, v -> builder.suggest(v.toString())); return builder.buildFuture(); } public static CompletableFuture suggestResource(Iterable values, SuggestionsBuilder builder, Function id, Function tooltip) { String contents = builder.getRemaining().toLowerCase(Locale.ROOT); SharedSuggestionProvider.filterResources(values, contents, id, v -> builder.suggest(((Identifier)id.apply(v)).toString(), (Message)tooltip.apply(v))); return builder.buildFuture(); } public static CompletableFuture suggestResource(Stream values, SuggestionsBuilder builder) { return SharedSuggestionProvider.suggestResource(values::iterator, builder); } public static CompletableFuture suggestResource(Stream values, SuggestionsBuilder builder, Function id, Function tooltip) { return SharedSuggestionProvider.suggestResource(values::iterator, builder, id, tooltip); } public static CompletableFuture suggestCoordinates(String currentInput, Collection allSuggestions, SuggestionsBuilder builder, Predicate validator) { ArrayList result; block4: { String[] fields; block5: { block3: { result = Lists.newArrayList(); if (!Strings.isNullOrEmpty((String)currentInput)) break block3; for (TextCoordinates coordinate : allSuggestions) { String fullValue = coordinate.x + " " + coordinate.y + " " + coordinate.z; if (!validator.test(fullValue)) continue; result.add(coordinate.x); result.add(coordinate.x + " " + coordinate.y); result.add(fullValue); } break block4; } fields = currentInput.split(" "); if (fields.length != 1) break block5; for (TextCoordinates coordinate : allSuggestions) { String fullValue = fields[0] + " " + coordinate.y + " " + coordinate.z; if (!validator.test(fullValue)) continue; result.add(fields[0] + " " + coordinate.y); result.add(fullValue); } break block4; } if (fields.length != 2) break block4; for (TextCoordinates coordinate : allSuggestions) { String fullValue = fields[0] + " " + fields[1] + " " + coordinate.z; if (!validator.test(fullValue)) continue; result.add(fullValue); } } return SharedSuggestionProvider.suggest(result, builder); } public static CompletableFuture suggest2DCoordinates(String currentInput, Collection allSuggestions, SuggestionsBuilder builder, Predicate validator) { ArrayList result; block3: { block2: { result = Lists.newArrayList(); if (!Strings.isNullOrEmpty((String)currentInput)) break block2; for (TextCoordinates coordinate : allSuggestions) { String fullValue = coordinate.x + " " + coordinate.z; if (!validator.test(fullValue)) continue; result.add(coordinate.x); result.add(fullValue); } break block3; } String[] fields = currentInput.split(" "); if (fields.length != 1) break block3; for (TextCoordinates coordinate : allSuggestions) { String fullValue = fields[0] + " " + coordinate.z; if (!validator.test(fullValue)) continue; result.add(fullValue); } } return SharedSuggestionProvider.suggest(result, builder); } public static CompletableFuture suggest(Iterable values, SuggestionsBuilder builder) { String lowerPrefix = builder.getRemaining().toLowerCase(Locale.ROOT); for (String name : values) { if (!SharedSuggestionProvider.matchesSubStr(lowerPrefix, name.toLowerCase(Locale.ROOT))) continue; builder.suggest(name); } return builder.buildFuture(); } public static CompletableFuture suggest(Stream values, SuggestionsBuilder builder) { String lowerPrefix = builder.getRemaining().toLowerCase(Locale.ROOT); values.filter(v -> SharedSuggestionProvider.matchesSubStr(lowerPrefix, v.toLowerCase(Locale.ROOT))).forEach(arg_0 -> ((SuggestionsBuilder)builder).suggest(arg_0)); return builder.buildFuture(); } public static CompletableFuture suggest(String[] values, SuggestionsBuilder builder) { String lowerPrefix = builder.getRemaining().toLowerCase(Locale.ROOT); for (String name : values) { if (!SharedSuggestionProvider.matchesSubStr(lowerPrefix, name.toLowerCase(Locale.ROOT))) continue; builder.suggest(name); } return builder.buildFuture(); } public static CompletableFuture suggest(Iterable values, SuggestionsBuilder builder, Function toString, Function tooltip) { String lowerPrefix = builder.getRemaining().toLowerCase(Locale.ROOT); for (T value : values) { String name = toString.apply(value); if (!SharedSuggestionProvider.matchesSubStr(lowerPrefix, name.toLowerCase(Locale.ROOT))) continue; builder.suggest(name, tooltip.apply(value)); } return builder.buildFuture(); } public static boolean matchesSubStr(String pattern, String input) { int index = 0; while (!input.startsWith(pattern, index)) { int indexOfSplitter = MATCH_SPLITTER.indexIn((CharSequence)input, index); if (indexOfSplitter < 0) { return false; } index = indexOfSplitter + 1; } return true; } public static class TextCoordinates { public static final TextCoordinates DEFAULT_LOCAL = new TextCoordinates("^", "^", "^"); public static final TextCoordinates DEFAULT_GLOBAL = new TextCoordinates("~", "~", "~"); public final String x; public final String y; public final String z; public TextCoordinates(String x, String y, String z) { this.x = x; this.y = y; this.z = z; } } public static enum ElementSuggestionType { TAGS, ELEMENTS, ALL; public boolean shouldSuggestTags() { return this == TAGS || this == ALL; } public boolean shouldSuggestElements() { return this == ELEMENTS || this == ALL; } } }