mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
tinker with cloud
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user