mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
Improve parsing from registries.
If multiple namespaces are present, suggestions will first suggest a namespace, then once a namespace is selected, keys within that namespace. Starting an argument with ":" will instead search across all namespaces for matching keys.
This commit is contained in:
@ -20,8 +20,8 @@
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.registry.Keyed;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.registry.Registry;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
@ -45,8 +45,7 @@ import org.enginehub.piston.inject.Key;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
import static org.enginehub.piston.converter.SuggestionHelper.limitByPrefix;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class RegistryConverter<V extends Keyed> implements ArgumentConverter<V> {
|
||||
|
||||
@ -85,12 +84,10 @@ public final class RegistryConverter<V extends Keyed> implements ArgumentConvert
|
||||
|
||||
private final Registry<V> registry;
|
||||
private final TextComponent choices;
|
||||
private final boolean namespaced;
|
||||
|
||||
private RegistryConverter(Registry<V> registry) {
|
||||
this.registry = registry;
|
||||
this.choices = TextComponent.of("any " + registry.getName());
|
||||
this.namespaced = registry instanceof NamespacedRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -109,9 +106,6 @@ public final class RegistryConverter<V extends Keyed> implements ArgumentConvert
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(String input) {
|
||||
if (namespaced && input.indexOf(':') < 0) {
|
||||
input = "minecraft:" + input;
|
||||
}
|
||||
return limitByPrefix(registry.keySet().stream(), input);
|
||||
return SuggestionHelper.getRegistrySuggestions(registry, input).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user