getFromID -> getByID

This commit is contained in:
dfsek
2021-12-25 01:10:49 -07:00
parent dc688e49ce
commit 46e7bd917a
10 changed files with 20 additions and 20 deletions
@@ -24,7 +24,7 @@ public class BiomeDelegateLoader implements TypeLoader<BiomeDelegate> {
public BiomeDelegate load(@NotNull AnnotatedType t, @NotNull Object c, @NotNull ConfigLoader loader) throws LoadException { public BiomeDelegate load(@NotNull AnnotatedType t, @NotNull Object c, @NotNull ConfigLoader loader) throws LoadException {
if(c.equals("SELF")) return BiomeDelegate.self(); if(c.equals("SELF")) return BiomeDelegate.self();
return biomeRegistry return biomeRegistry
.getFromID((String) c) .getByID((String) c)
.map(BiomeDelegate::from) .map(BiomeDelegate::from)
.orElseGet(() -> BiomeDelegate.ephemeral((String) c)); .orElseGet(() -> BiomeDelegate.ephemeral((String) c));
} }
@@ -68,7 +68,7 @@ public class StructureFunction implements Function<Boolean> {
String app = id.apply(implementationArguments, variableMap); String app = id.apply(implementationArguments, variableMap);
return registry.getFromID(app).map(script -> { return registry.getByID(app).map(script -> {
Rotation rotation1; Rotation rotation1;
String rotString = rotations.get(arguments.getRandom().nextInt(rotations.size())).apply(implementationArguments, variableMap); String rotString = rotations.get(arguments.getRandom().nextInt(rotations.size())).apply(implementationArguments, variableMap);
try { try {
@@ -79,8 +79,8 @@ public interface Registry<T> extends TypeLoader<T> {
TypeKey<T> getType(); TypeKey<T> getType();
default Optional<T> getFromID(String id) { default Optional<T> getByID(String id) {
return getFromID(id, map -> { return getByID(id, map -> {
if(map.isEmpty()) return Optional.empty(); if(map.isEmpty()) return Optional.empty();
if(map.size() == 1) { if(map.size() == 1) {
return map.values().stream().findFirst(); // only one value. return map.values().stream().findFirst(); // only one value.
@@ -93,12 +93,12 @@ public interface Registry<T> extends TypeLoader<T> {
}); });
} }
Map<RegistryKey, T> getIDMatches(String id); Map<RegistryKey, T> getMatches(String id);
default Optional<T> getFromID(String attempt, Function<Map<RegistryKey, T>, Optional<T>> reduction) { default Optional<T> getByID(String attempt, Function<Map<RegistryKey, T>, Optional<T>> reduction) {
if(attempt.contains(":")) { if(attempt.contains(":")) {
return get(RegistryKey.parse(attempt)); return get(RegistryKey.parse(attempt));
} }
return reduction.apply(getIDMatches(attempt)); return reduction.apply(getMatches(attempt));
} }
} }
@@ -46,7 +46,7 @@ public class GenericTemplateSupplierLoader<T> implements TypeLoader<T> {
Map<String, Object> map = (Map<String, Object>) c; Map<String, Object> map = (Map<String, Object>) c;
try { try {
return loader return loader
.load(registry.getFromID(((String) map.get("type"))) .load(registry.getByID(((String) map.get("type")))
.orElseThrow(() -> new LoadException("No such entry: " + map.get("type"))) .orElseThrow(() -> new LoadException("No such entry: " + map.get("type")))
.get(), new MapConfiguration(map)).get(); .get(), new MapConfiguration(map)).get();
} catch(ConfigException e) { } catch(ConfigException e) {
@@ -97,8 +97,8 @@ public class CheckedRegistryImpl<T> implements CheckedRegistry<T> {
} }
@Override @Override
public Map<RegistryKey, T> getIDMatches(String id) { public Map<RegistryKey, T> getMatches(String id) {
return registry.getIDMatches(id); return registry.getMatches(id);
} }
@Override @Override
@@ -84,8 +84,8 @@ public class LockedRegistryImpl<T> implements Registry<T> {
} }
@Override @Override
public Map<RegistryKey, T> getIDMatches(String id) { public Map<RegistryKey, T> getMatches(String id) {
return registry.getIDMatches(id); return registry.getMatches(id);
} }
@Override @Override
@@ -66,9 +66,9 @@ public class OpenRegistryImpl<T> implements OpenRegistry<T> {
@Override @Override
public T load(@NotNull AnnotatedType type, @NotNull Object o, @NotNull ConfigLoader configLoader) throws LoadException { public T load(@NotNull AnnotatedType type, @NotNull Object o, @NotNull ConfigLoader configLoader) throws LoadException {
return getFromID((String) o).orElseThrow(() -> new LoadException("No such " + type.getType().getTypeName() + " matching \"" + o + return getByID((String) o).orElseThrow(() -> new LoadException("No such " + type.getType().getTypeName() + " matching \"" + o +
"\" was found in this registry. Registry contains items: " + "\" was found in this registry. Registry contains items: " +
getItemsFormatted())); getItemsFormatted()));
} }
private String getItemsFormatted() { private String getItemsFormatted() {
@@ -144,7 +144,7 @@ public class OpenRegistryImpl<T> implements OpenRegistry<T> {
} }
@Override @Override
public Map<RegistryKey, T> getIDMatches(String id) { public Map<RegistryKey, T> getMatches(String id) {
return objectIDs return objectIDs
.get(id) .get(id)
.stream() .stream()
@@ -214,9 +214,9 @@ public class TerraBukkitPlugin extends JavaPlugin {
public @Nullable public @Nullable
ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String id) { ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String id) {
return new BukkitChunkGeneratorWrapper(generatorMap.computeIfAbsent(worldName, name -> { return new BukkitChunkGeneratorWrapper(generatorMap.computeIfAbsent(worldName, name -> {
ConfigPack pack = platform.getConfigRegistry().getIDMatches(id).orElseThrow( ConfigPack pack = platform.getConfigRegistry().getByID(id).orElseThrow(
() -> new IllegalArgumentException("No such config pack \"" + id + "\"")); () -> new IllegalArgumentException("No such config pack \"" + id + "\""));
return pack.getGeneratorProvider().newInstance(pack); return pack.getGeneratorProvider().newInstance(pack);
}), platform.getRawConfigRegistry().getIDMatches(id).orElseThrow(), platform.getWorldHandle().air()); }), platform.getRawConfigRegistry().getByID(id).orElseThrow(), platform.getWorldHandle().air());
} }
} }
@@ -22,7 +22,7 @@ public final class TerraCLI {
CLIPlatform platform = new CLIPlatform(); CLIPlatform platform = new CLIPlatform();
platform.getEventManager().callEvent(new PlatformInitializationEvent()); platform.getEventManager().callEvent(new PlatformInitializationEvent());
ConfigPack generate = platform.getConfigRegistry().getIDMatches("OVERWORLD").orElseThrow(); // TODO: make this a cli argument ConfigPack generate = platform.getConfigRegistry().getByID("OVERWORLD").orElseThrow(); // TODO: make this a cli argument
CLIWorld world = new CLIWorld(2, 2, 384, -64, generate); CLIWorld world = new CLIWorld(2, 2, 384, -64, generate);
@@ -83,7 +83,7 @@ public abstract class GeneratorOptionsMixin {
prop = prop.substring(prop.indexOf(":") + 1); prop = prop.substring(prop.indexOf(":") + 1);
String finalProp = prop; String finalProp = prop;
ConfigPack config = main.getConfigRegistry().getFromID(prop).orElseThrow(() -> new IllegalArgumentException( ConfigPack config = main.getConfigRegistry().getByID(prop).orElseThrow(() -> new IllegalArgumentException(
"No such pack " + finalProp)); "No such pack " + finalProp));
cir.setReturnValue( cir.setReturnValue(