SharedSuggestionProvider.java
net.minecraft.commands.SharedSuggestionProvider
信息
- 全限定名:net.minecraft.commands.SharedSuggestionProvider
- 类型:public interface
- 包:net.minecraft.commands
- 源码路径:src/main/java/net/minecraft/commands/SharedSuggestionProvider.java
- 起始行号:L30
- 继承:PermissionSetSupplier
- 职责:
TODO
字段/常量
MATCH_SPLITTER- 类型:
CharMatcher - 修饰符:
package-private - 源码定位:
L31 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.commands.SharedSuggestionProvider.ElementSuggestionType- 类型:
enum - 修饰符:
public static - 源码定位:
L276 - 说明:
TODO
- 类型:
-
net.minecraft.commands.SharedSuggestionProvider.TextCoordinates- 类型:
class - 修饰符:
public static - 源码定位:
L290 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
Collection<String> getOnlinePlayerNames() @ L33
- 方法名:getOnlinePlayerNames
- 源码定位:L33
- 返回类型:Collection
- 修饰符:package-private
参数:
- 无
说明:
TODO
default Collection<String> getCustomTabSuggestions() @ L35
- 方法名:getCustomTabSuggestions
- 源码定位:L35
- 返回类型:Collection
- 修饰符:default
参数:
- 无
说明:
TODO
default Collection<String> getSelectedEntities() @ L39
- 方法名:getSelectedEntities
- 源码定位:L39
- 返回类型:Collection
- 修饰符:default
参数:
- 无
说明:
TODO
Collection<String> getAllTeams() @ L43
- 方法名:getAllTeams
- 源码定位:L43
- 返回类型:Collection
- 修饰符:package-private
参数:
- 无
说明:
TODO
Stream<Identifier> getAvailableSounds() @ L45
- 方法名:getAvailableSounds
- 源码定位:L45
- 返回类型:Stream
- 修饰符:package-private
参数:
- 无
说明:
TODO
CompletableFuture<Suggestions> customSuggestion(CommandContext<?> context) @ L47
- 方法名:customSuggestion
- 源码定位:L47
- 返回类型:CompletableFuture
- 修饰符:package-private
参数:
- context: CommandContext<?>
说明:
TODO
default Collection<SharedSuggestionProvider.TextCoordinates> getRelevantCoordinates() @ L49
- 方法名:getRelevantCoordinates
- 源码定位:L49
- 返回类型:Collection<SharedSuggestionProvider.TextCoordinates>
- 修饰符:default
参数:
- 无
说明:
TODO
default Collection<SharedSuggestionProvider.TextCoordinates> getAbsoluteCoordinates() @ L53
- 方法名:getAbsoluteCoordinates
- 源码定位:L53
- 返回类型:Collection<SharedSuggestionProvider.TextCoordinates>
- 修饰符:default
参数:
- 无
说明:
TODO
Set<ResourceKey<Level>> levels() @ L57
- 方法名:levels
- 源码定位:L57
- 返回类型:Set<ResourceKey
> - 修饰符:package-private
参数:
- 无
说明:
TODO
RegistryAccess registryAccess() @ L59
- 方法名:registryAccess
- 源码定位:L59
- 返回类型:RegistryAccess
- 修饰符:package-private
参数:
- 无
说明:
TODO
FeatureFlagSet enabledFeatures() @ L61
- 方法名:enabledFeatures
- 源码定位:L61
- 返回类型:FeatureFlagSet
- 修饰符:package-private
参数:
- 无
说明:
TODO
default void suggestRegistryElements(HolderLookup<?> registry, SharedSuggestionProvider.ElementSuggestionType elements, SuggestionsBuilder builder) @ L63
- 方法名:suggestRegistryElements
- 源码定位:L63
- 返回类型:void
- 修饰符:default
参数:
- registry: HolderLookup<?>
- elements: SharedSuggestionProvider.ElementSuggestionType
- builder: SuggestionsBuilder
说明:
TODO
static <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder, ResourceKey<?extends Registry<?>> registryKey, SharedSuggestionProvider.ElementSuggestionType type) @ L73
- 方法名:listSuggestions
- 源码定位:L73
- 返回类型:
CompletableFuture - 修饰符:static
参数:
- context: CommandContext
- builder: SuggestionsBuilder
- registryKey: ResourceKey>
- type: SharedSuggestionProvider.ElementSuggestionType
说明:
TODO
CompletableFuture<Suggestions> suggestRegistryElements(ResourceKey<?extends Registry<?>> key, SharedSuggestionProvider.ElementSuggestionType elements, SuggestionsBuilder builder, CommandContext<?> context) @ L84
- 方法名:suggestRegistryElements
- 源码定位:L84
- 返回类型:CompletableFuture
- 修饰符:package-private
参数:
- key: ResourceKey>
- elements: SharedSuggestionProvider.ElementSuggestionType
- builder: SuggestionsBuilder
- context: CommandContext<?>
说明:
TODO
static <T> void filterResources(Iterable<T> values, String contents, Function<T,Identifier> converter, Consumer<T> consumer) @ L91
- 方法名:filterResources
- 源码定位:L91
- 返回类型:
void - 修饰符:static
参数:
- values: Iterable
- contents: String
- converter: Function<T,Identifier>
- consumer: Consumer
说明:
TODO
static <T> void filterResources(Iterable<T> values, String contents, String prefix, Function<T,Identifier> converter, Consumer<T> consumer) @ L107
- 方法名:filterResources
- 源码定位:L107
- 返回类型:
void - 修饰符:static
参数:
- values: Iterable
- contents: String
- prefix: String
- converter: Function<T,Identifier>
- consumer: Consumer
说明:
TODO
static CompletableFuture<Suggestions> suggestResource(Iterable<Identifier> values, SuggestionsBuilder builder, String prefix) @ L119
- 方法名:suggestResource
- 源码定位:L119
- 返回类型:CompletableFuture
- 修饰符:static
参数:
- values: Iterable
- builder: SuggestionsBuilder
- prefix: String
说明:
TODO
static CompletableFuture<Suggestions> suggestResource(Stream<Identifier> values, SuggestionsBuilder builder, String prefix) @ L125
- 方法名:suggestResource
- 源码定位:L125
- 返回类型:CompletableFuture
- 修饰符:static
参数:
- values: Stream
- builder: SuggestionsBuilder
- prefix: String
说明:
TODO
static CompletableFuture<Suggestions> suggestResource(Iterable<Identifier> values, SuggestionsBuilder builder) @ L129
- 方法名:suggestResource
- 源码定位:L129
- 返回类型:CompletableFuture
- 修饰符:static
参数:
- values: Iterable
- builder: SuggestionsBuilder
说明:
TODO
static <T> CompletableFuture<Suggestions> suggestResource(Iterable<T> values, SuggestionsBuilder builder, Function<T,Identifier> id, Function<T,Message> tooltip) @ L135
- 方法名:suggestResource
- 源码定位:L135
- 返回类型:
CompletableFuture - 修饰符:static
参数:
- values: Iterable
- builder: SuggestionsBuilder
- id: Function<T,Identifier>
- tooltip: Function<T,Message>
说明:
TODO
static CompletableFuture<Suggestions> suggestResource(Stream<Identifier> values, SuggestionsBuilder builder) @ L143
- 方法名:suggestResource
- 源码定位:L143
- 返回类型:CompletableFuture
- 修饰符:static
参数:
- values: Stream
- builder: SuggestionsBuilder
说明:
TODO
static <T> CompletableFuture<Suggestions> suggestResource(Stream<T> values, SuggestionsBuilder builder, Function<T,Identifier> id, Function<T,Message> tooltip) @ L147
- 方法名:suggestResource
- 源码定位:L147
- 返回类型:
CompletableFuture - 修饰符:static
参数:
- values: Stream
- builder: SuggestionsBuilder
- id: Function<T,Identifier>
- tooltip: Function<T,Message>
说明:
TODO
static CompletableFuture<Suggestions> suggestCoordinates(String currentInput, Collection<SharedSuggestionProvider.TextCoordinates> allSuggestions, SuggestionsBuilder builder, Predicate<String> validator) @ L153
- 方法名:suggestCoordinates
- 源码定位:L153
- 返回类型:CompletableFuture
- 修饰符:static
参数:
- currentInput: String
- allSuggestions: Collection<SharedSuggestionProvider.TextCoordinates>
- builder: SuggestionsBuilder
- validator: Predicate
说明:
TODO
static CompletableFuture<Suggestions> suggest2DCoordinates(String currentInput, Collection<SharedSuggestionProvider.TextCoordinates> allSuggestions, SuggestionsBuilder builder, Predicate<String> validator) @ L189
- 方法名:suggest2DCoordinates
- 源码定位:L189
- 返回类型:CompletableFuture
- 修饰符:static
参数:
- currentInput: String
- allSuggestions: Collection<SharedSuggestionProvider.TextCoordinates>
- builder: SuggestionsBuilder
- validator: Predicate
说明:
TODO
static CompletableFuture<Suggestions> suggest(Iterable<String> values, SuggestionsBuilder builder) @ L216
- 方法名:suggest
- 源码定位:L216
- 返回类型:CompletableFuture
- 修饰符:static
参数:
- values: Iterable
- builder: SuggestionsBuilder
说明:
TODO
static CompletableFuture<Suggestions> suggest(Stream<String> values, SuggestionsBuilder builder) @ L228
- 方法名:suggest
- 源码定位:L228
- 返回类型:CompletableFuture
- 修饰符:static
参数:
- values: Stream
- builder: SuggestionsBuilder
说明:
TODO
static CompletableFuture<Suggestions> suggest(String[] values, SuggestionsBuilder builder) @ L234
- 方法名:suggest
- 源码定位:L234
- 返回类型:CompletableFuture
- 修饰符:static
参数:
- values: String[]
- builder: SuggestionsBuilder
说明:
TODO
static <T> CompletableFuture<Suggestions> suggest(Iterable<T> values, SuggestionsBuilder builder, Function<T,String> toString, Function<T,Message> tooltip) @ L246
- 方法名:suggest
- 源码定位:L246
- 返回类型:
CompletableFuture - 修饰符:static
参数:
- values: Iterable
- builder: SuggestionsBuilder
- toString: Function<T,String>
- tooltip: Function<T,Message>
说明:
TODO
static boolean matchesSubStr(String pattern, String input) @ L261
- 方法名:matchesSubStr
- 源码定位:L261
- 返回类型:boolean
- 修饰符:static
参数:
- pattern: String
- input: String
说明:
TODO
代码
public interface SharedSuggestionProvider extends PermissionSetSupplier {
CharMatcher MATCH_SPLITTER = CharMatcher.anyOf("._/");
Collection<String> getOnlinePlayerNames();
default Collection<String> getCustomTabSuggestions() {
return this.getOnlinePlayerNames();
}
default Collection<String> getSelectedEntities() {
return Collections.emptyList();
}
Collection<String> getAllTeams();
Stream<Identifier> getAvailableSounds();
CompletableFuture<Suggestions> customSuggestion(CommandContext<?> context);
default Collection<SharedSuggestionProvider.TextCoordinates> getRelevantCoordinates() {
return Collections.singleton(SharedSuggestionProvider.TextCoordinates.DEFAULT_GLOBAL);
}
default Collection<SharedSuggestionProvider.TextCoordinates> getAbsoluteCoordinates() {
return Collections.singleton(SharedSuggestionProvider.TextCoordinates.DEFAULT_GLOBAL);
}
Set<ResourceKey<Level>> levels();
RegistryAccess registryAccess();
FeatureFlagSet enabledFeatures();
default void suggestRegistryElements(HolderLookup<?> registry, SharedSuggestionProvider.ElementSuggestionType elements, SuggestionsBuilder builder) {
if (elements.shouldSuggestTags()) {
suggestResource(registry.listTagIds().map(TagKey::location), builder, "#");
}
if (elements.shouldSuggestElements()) {
suggestResource(registry.listElementIds().map(ResourceKey::identifier), builder);
}
}
static <S> CompletableFuture<Suggestions> listSuggestions(
CommandContext<S> context,
SuggestionsBuilder builder,
ResourceKey<? extends Registry<?>> registryKey,
SharedSuggestionProvider.ElementSuggestionType type
) {
return context.getSource() instanceof SharedSuggestionProvider suggestionProvider
? suggestionProvider.suggestRegistryElements(registryKey, type, builder, context)
: builder.buildFuture();
}
CompletableFuture<Suggestions> suggestRegistryElements(
final ResourceKey<? extends Registry<?>> key,
final SharedSuggestionProvider.ElementSuggestionType elements,
final SuggestionsBuilder builder,
final CommandContext<?> context
);
static <T> void filterResources(Iterable<T> values, String contents, Function<T, Identifier> converter, Consumer<T> consumer) {
boolean hasNamespace = contents.indexOf(58) > -1;
for (T value : values) {
Identifier id = converter.apply(value);
if (hasNamespace) {
String name = id.toString();
if (matchesSubStr(contents, name)) {
consumer.accept(value);
}
} else if (matchesSubStr(contents, id.getNamespace()) || matchesSubStr(contents, id.getPath())) {
consumer.accept(value);
}
}
}
static <T> void filterResources(Iterable<T> values, String contents, String prefix, Function<T, Identifier> converter, Consumer<T> consumer) {
if (contents.isEmpty()) {
values.forEach(consumer);
} else {
String commonPrefix = Strings.commonPrefix(contents, prefix);
if (!commonPrefix.isEmpty()) {
String strippedContents = contents.substring(commonPrefix.length());
filterResources(values, strippedContents, converter, consumer);
}
}
}
static CompletableFuture<Suggestions> suggestResource(Iterable<Identifier> values, SuggestionsBuilder builder, String prefix) {
String contents = builder.getRemaining().toLowerCase(Locale.ROOT);
filterResources(values, contents, prefix, t -> t, v -> builder.suggest(prefix + v));
return builder.buildFuture();
}
static CompletableFuture<Suggestions> suggestResource(Stream<Identifier> values, SuggestionsBuilder builder, String prefix) {
return suggestResource(values::iterator, builder, prefix);
}
static CompletableFuture<Suggestions> suggestResource(Iterable<Identifier> values, SuggestionsBuilder builder) {
String contents = builder.getRemaining().toLowerCase(Locale.ROOT);
filterResources(values, contents, t -> t, v -> builder.suggest(v.toString()));
return builder.buildFuture();
}
static <T> CompletableFuture<Suggestions> suggestResource(
Iterable<T> values, SuggestionsBuilder builder, Function<T, Identifier> id, Function<T, Message> tooltip
) {
String contents = builder.getRemaining().toLowerCase(Locale.ROOT);
filterResources(values, contents, id, v -> builder.suggest(id.apply(v).toString(), tooltip.apply(v)));
return builder.buildFuture();
}
static CompletableFuture<Suggestions> suggestResource(Stream<Identifier> values, SuggestionsBuilder builder) {
return suggestResource(values::iterator, builder);
}
static <T> CompletableFuture<Suggestions> suggestResource(
Stream<T> values, SuggestionsBuilder builder, Function<T, Identifier> id, Function<T, Message> tooltip
) {
return suggestResource(values::iterator, builder, id, tooltip);
}
static CompletableFuture<Suggestions> suggestCoordinates(
String currentInput, Collection<SharedSuggestionProvider.TextCoordinates> allSuggestions, SuggestionsBuilder builder, Predicate<String> validator
) {
List<String> result = Lists.newArrayList();
if (Strings.isNullOrEmpty(currentInput)) {
for (SharedSuggestionProvider.TextCoordinates coordinate : allSuggestions) {
String fullValue = coordinate.x + " " + coordinate.y + " " + coordinate.z;
if (validator.test(fullValue)) {
result.add(coordinate.x);
result.add(coordinate.x + " " + coordinate.y);
result.add(fullValue);
}
}
} else {
String[] fields = currentInput.split(" ");
if (fields.length == 1) {
for (SharedSuggestionProvider.TextCoordinates coordinatex : allSuggestions) {
String fullValue = fields[0] + " " + coordinatex.y + " " + coordinatex.z;
if (validator.test(fullValue)) {
result.add(fields[0] + " " + coordinatex.y);
result.add(fullValue);
}
}
} else if (fields.length == 2) {
for (SharedSuggestionProvider.TextCoordinates coordinatexx : allSuggestions) {
String fullValue = fields[0] + " " + fields[1] + " " + coordinatexx.z;
if (validator.test(fullValue)) {
result.add(fullValue);
}
}
}
}
return suggest(result, builder);
}
static CompletableFuture<Suggestions> suggest2DCoordinates(
String currentInput, Collection<SharedSuggestionProvider.TextCoordinates> allSuggestions, SuggestionsBuilder builder, Predicate<String> validator
) {
List<String> result = Lists.newArrayList();
if (Strings.isNullOrEmpty(currentInput)) {
for (SharedSuggestionProvider.TextCoordinates coordinate : allSuggestions) {
String fullValue = coordinate.x + " " + coordinate.z;
if (validator.test(fullValue)) {
result.add(coordinate.x);
result.add(fullValue);
}
}
} else {
String[] fields = currentInput.split(" ");
if (fields.length == 1) {
for (SharedSuggestionProvider.TextCoordinates coordinatex : allSuggestions) {
String fullValue = fields[0] + " " + coordinatex.z;
if (validator.test(fullValue)) {
result.add(fullValue);
}
}
}
}
return suggest(result, builder);
}
static CompletableFuture<Suggestions> suggest(Iterable<String> values, SuggestionsBuilder builder) {
String lowerPrefix = builder.getRemaining().toLowerCase(Locale.ROOT);
for (String name : values) {
if (matchesSubStr(lowerPrefix, name.toLowerCase(Locale.ROOT))) {
builder.suggest(name);
}
}
return builder.buildFuture();
}
static CompletableFuture<Suggestions> suggest(Stream<String> values, SuggestionsBuilder builder) {
String lowerPrefix = builder.getRemaining().toLowerCase(Locale.ROOT);
values.filter(v -> matchesSubStr(lowerPrefix, v.toLowerCase(Locale.ROOT))).forEach(builder::suggest);
return builder.buildFuture();
}
static CompletableFuture<Suggestions> suggest(String[] values, SuggestionsBuilder builder) {
String lowerPrefix = builder.getRemaining().toLowerCase(Locale.ROOT);
for (String name : values) {
if (matchesSubStr(lowerPrefix, name.toLowerCase(Locale.ROOT))) {
builder.suggest(name);
}
}
return builder.buildFuture();
}
static <T> CompletableFuture<Suggestions> suggest(
Iterable<T> values, SuggestionsBuilder builder, Function<T, String> toString, Function<T, Message> tooltip
) {
String lowerPrefix = builder.getRemaining().toLowerCase(Locale.ROOT);
for (T value : values) {
String name = toString.apply(value);
if (matchesSubStr(lowerPrefix, name.toLowerCase(Locale.ROOT))) {
builder.suggest(name, tooltip.apply(value));
}
}
return builder.buildFuture();
}
static boolean matchesSubStr(String pattern, String input) {
int index = 0;
while (!input.startsWith(pattern, index)) {
int indexOfSplitter = MATCH_SPLITTER.indexIn(input, index);
if (indexOfSplitter < 0) {
return false;
}
index = indexOfSplitter + 1;
}
return true;
}
public static enum ElementSuggestionType {
TAGS,
ELEMENTS,
ALL;
public boolean shouldSuggestTags() {
return this == TAGS || this == ALL;
}
public boolean shouldSuggestElements() {
return this == ELEMENTS || this == ALL;
}
}
public static class TextCoordinates {
public static final SharedSuggestionProvider.TextCoordinates DEFAULT_LOCAL = new SharedSuggestionProvider.TextCoordinates("^", "^", "^");
public static final SharedSuggestionProvider.TextCoordinates DEFAULT_GLOBAL = new SharedSuggestionProvider.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;
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
返回值
- 引用位置: