mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-13 21:13:53 +00:00
Created an Item Registry Test (non-functional)
This commit is contained in:
@ -21,7 +21,6 @@ package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.registry.IRegistry;
|
||||
import com.sk89q.worldedit.registry.Keyed;
|
||||
import com.sk89q.worldedit.registry.Registry;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
@ -29,7 +28,6 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockCategory;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.fluid.FluidCategory;
|
||||
import com.sk89q.worldedit.world.fluid.FluidType;
|
||||
@ -75,7 +73,7 @@ public final class RegistryConverter<V extends Keyed> implements ArgumentConvert
|
||||
private static <V extends Keyed> RegistryConverter<V> from(Class<Keyed> registryType) {
|
||||
try {
|
||||
Field registryField = registryType.getDeclaredField("REGISTRY");
|
||||
IRegistry<V> registry = (IRegistry<V>) registryField.get(null);
|
||||
Registry<V> registry = (Registry<V>) registryField.get(null);
|
||||
return new RegistryConverter<>(registry);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new IllegalArgumentException("Not a registry-backed type: " + registryType.getName());
|
||||
@ -84,10 +82,10 @@ public final class RegistryConverter<V extends Keyed> implements ArgumentConvert
|
||||
}
|
||||
}
|
||||
|
||||
private final IRegistry<V> registry;
|
||||
private final Registry<V> registry;
|
||||
private final TextComponent choices;
|
||||
|
||||
private RegistryConverter(IRegistry<V> registry) {
|
||||
private RegistryConverter(Registry<V> registry) {
|
||||
this.registry = registry;
|
||||
this.choices = TextComponent.of("any " + registry.getName());
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.command.util;
|
||||
|
||||
import com.sk89q.worldedit.registry.IRegistry;
|
||||
import com.sk89q.worldedit.registry.Keyed;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.registry.Registry;
|
||||
@ -139,7 +138,7 @@ public final class SuggestionHelper {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
public static <V extends Keyed> Stream<String> getRegistrySuggestions(IRegistry<V> registry, String input) {
|
||||
public static <V extends Keyed> Stream<String> getRegistrySuggestions(Registry<V> registry, String input) {
|
||||
if (registry instanceof NamespacedRegistry) {
|
||||
return getNamespacedRegistrySuggestions(((NamespacedRegistry<?>) registry), input);
|
||||
}
|
||||
@ -172,4 +171,4 @@ public final class SuggestionHelper {
|
||||
Predicate<String> search = byPrefix(input.toLowerCase(Locale.ROOT));
|
||||
return registry.keySet().stream().filter(search);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
package com.sk89q.worldedit.registry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.enginehub.piston.converter.SuggestionHelper.limitByPrefix;
|
||||
|
||||
public interface IRegistry<V> extends Iterable<V> {
|
||||
String getName();
|
||||
|
||||
V get(final String key);
|
||||
|
||||
Set<String> keySet();
|
||||
|
||||
Collection<V> values();
|
||||
|
||||
@Override
|
||||
default Iterator<V> iterator() {
|
||||
return values().iterator();
|
||||
}
|
||||
|
||||
default <V extends Keyed> Stream<String> getSuggestions(String input) {
|
||||
return limitByPrefix(keySet().stream(), input).stream();
|
||||
}
|
||||
}
|
@ -19,8 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.registry;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.enginehub.piston.converter.SuggestionHelper.byPrefix;
|
||||
@ -30,7 +28,6 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
@ -43,20 +40,12 @@ public final class NamespacedRegistry<V extends Keyed> extends Registry<V> {
|
||||
private final List<V> values = new ArrayList<>();
|
||||
private int lastInternalId = 0;
|
||||
|
||||
public NamespacedRegistry(final String name, Map<String, V> map) {
|
||||
this(name, map, MINECRAFT_NAMESPACE);
|
||||
}
|
||||
|
||||
public NamespacedRegistry(final String name) {
|
||||
this(name, MINECRAFT_NAMESPACE);
|
||||
}
|
||||
|
||||
public NamespacedRegistry(final String name, final String defaultNamespace) {
|
||||
this(name, Maps.newHashMap(), defaultNamespace);
|
||||
}
|
||||
|
||||
public NamespacedRegistry(final String name, Map<String, V> map, final String defaultNamespace) {
|
||||
super(name, map);
|
||||
super(name);
|
||||
this.defaultNamespace = defaultNamespace;
|
||||
}
|
||||
|
||||
@ -71,19 +60,13 @@ public final class NamespacedRegistry<V extends Keyed> extends Registry<V> {
|
||||
requireNonNull(key, "key");
|
||||
final int i = key.indexOf(':');
|
||||
checkState(i > 0, "key is not namespaced");
|
||||
final V existing = super.get(key);
|
||||
if (existing != null) {
|
||||
throw new UnsupportedOperationException("Replacing existing registrations is not supported");
|
||||
}
|
||||
if (value instanceof RegistryItem) {
|
||||
((RegistryItem) value).setInternalId(lastInternalId++);
|
||||
}
|
||||
values.add(value);
|
||||
super.register(key, value);
|
||||
if (key.startsWith(defaultNamespace)) {
|
||||
super.register(key.substring(i + 1), value);
|
||||
}
|
||||
return value;
|
||||
final V registered = super.register(key, value);
|
||||
knownNamespaces.add(key.substring(0, i));
|
||||
return registered;
|
||||
}
|
||||
|
||||
public V getByInternalId(int index) {
|
||||
@ -123,7 +106,6 @@ public final class NamespacedRegistry<V extends Keyed> extends Registry<V> {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V1 extends Keyed> Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty() || input.equals(":")) {
|
||||
final Set<String> namespaces = getKnownNamespaces();
|
||||
|
@ -19,29 +19,24 @@
|
||||
|
||||
package com.sk89q.worldedit.registry;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class Registry<V extends Keyed> implements IRegistry<V> {
|
||||
private final Map<String, V> map;
|
||||
public class Registry<V extends Keyed> implements Iterable<V> {
|
||||
private final Map<String, V> map = new HashMap<>();
|
||||
private final String name;
|
||||
|
||||
public Registry(String name, Map<String, V> map) {
|
||||
this.name = name;
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public Registry(final String name) {
|
||||
this(name, Maps.newHashMap());
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -75,4 +70,9 @@ public class Registry<V extends Keyed> implements IRegistry<V> {
|
||||
return Collections.unmodifiableCollection(this.map.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<V> iterator() {
|
||||
return this.map.values().iterator();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,9 +27,6 @@ import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.registry.IRegistry;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.registry.Registry;
|
||||
import com.sk89q.worldedit.registry.state.AbstractProperty;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
@ -49,7 +46,6 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
Reference in New Issue
Block a user