tinker with cloud

This commit is contained in:
dfsek
2025-12-30 01:43:13 -07:00
parent 998b6478f3
commit 2215ea8336
2 changed files with 16 additions and 15 deletions

View File

@@ -12,6 +12,7 @@ import org.incendo.cloud.parser.ParserDescriptor;
import org.incendo.cloud.suggestion.Suggestion;
import org.incendo.cloud.suggestion.SuggestionProvider;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -21,8 +22,12 @@ import com.dfsek.terra.api.registry.exception.NoSuchEntryException;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.util.reflection.TypeKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RegistryArgument {
private static final Logger logger = LoggerFactory.getLogger(RegistryArgument.class);
public static <T, R> Builder<T, R> builder(String name, Registry<R> registry) {
return new Builder<>(name, registry);
@@ -100,19 +105,15 @@ public class RegistryArgument {
Registry<R> registry = registryFunction.apply(commandContext);
String finalInput = input;
try {
return registry.get(RegistryKey.parse(input))
return RegistryKey.parse(finalInput)
.bind(registry::getEither)
.map(ArgumentParseResult::success)
.orJust(() ->
registry.getByID(finalInput).collect(
.collect(l -> registry
.getByID(finalInput)
.collect(
left -> ArgumentParseResult.failure(left.toIllegal()),
ArgumentParseResult::success
))
.get(() -> ArgumentParseResult.failure(new NoSuchEntryException("No such entry: " + finalInput)));
} catch(IllegalArgumentException e) {
return ArgumentParseResult.failure(e);
}
), Function.identity());
}
@Override

View File

@@ -43,7 +43,7 @@ public interface Registry<T> extends TypeLoader<T> {
Maybe<T> get(@NotNull RegistryKey key);
default Either<Invalid, T> getEither(@NotNull RegistryKey key) {
return get(key).toEither(new NoSuchElement("No such element " + key.toString()));
return get(key).toEither(new NoSuchElement("No such element " + key));
}
/**
@@ -96,7 +96,7 @@ public interface Registry<T> extends TypeLoader<T> {
default Either<Invalid, T> getByID(String id) {
return getByID(id, map -> {
if(map.isEmpty()) return Either.left(new NoSuchElement("No such value + \"" + id + "\""));
if(map.isEmpty()) return Either.left(new NoSuchElement("No such value \"" + id + "\""));
if(map.size() == 1) {
return Either.right(map.values().stream().findFirst().get()); // only one value.
}