Minestom/src/main/java/net/minestom/server/command/Graph.java

92 lines
3.1 KiB
Java
Raw Normal View History

2022-07-13 22:45:38 +02:00
package net.minestom.server.command;
2022-07-14 00:55:19 +02:00
import net.minestom.server.command.builder.ArgumentCallback;
2022-07-13 22:45:38 +02:00
import net.minestom.server.command.builder.Command;
2022-07-14 00:55:19 +02:00
import net.minestom.server.command.builder.CommandExecutor;
2022-07-13 22:45:38 +02:00
import net.minestom.server.command.builder.arguments.Argument;
2022-07-14 00:55:19 +02:00
import net.minestom.server.command.builder.condition.CommandCondition;
2022-07-13 22:45:38 +02:00
import org.jetbrains.annotations.NotNull;
2022-07-14 00:55:19 +02:00
import org.jetbrains.annotations.Nullable;
2022-07-13 22:45:38 +02:00
import org.jetbrains.annotations.UnknownNullability;
import java.util.Collection;
import java.util.List;
2022-07-14 00:55:19 +02:00
import java.util.Map;
2022-07-13 22:45:38 +02:00
import java.util.function.Consumer;
import java.util.function.Predicate;
2022-07-14 00:55:19 +02:00
import java.util.function.Supplier;
2022-07-13 22:45:38 +02:00
sealed interface Graph permits GraphImpl {
static @NotNull Builder builder(@NotNull Argument<?> argument) {
return new GraphImpl.BuilderImpl(argument);
}
static @NotNull Graph fromCommand(@NotNull Command command) {
return GraphImpl.fromCommand(command);
}
static @NotNull Graph merge(@NotNull Collection<@NotNull Command> commands) {
return GraphImpl.merge(commands);
}
static @NotNull Graph merge(@NotNull List<@NotNull Graph> graphs) {
return GraphImpl.merge(graphs);
}
static @NotNull Graph merge(@NotNull Graph @NotNull ... graphs) {
return merge(List.of(graphs));
}
@NotNull Node root();
boolean compare(@NotNull Graph graph, @NotNull Comparator comparator);
sealed interface Node permits GraphImpl.NodeImpl {
@NotNull Argument<?> argument();
@UnknownNullability Executor executor();
@NotNull List<@NotNull Node> next();
}
2022-07-14 00:55:19 +02:00
// TODO rename to ExecutionInformation or similar to avoid confusion
2022-07-13 22:45:38 +02:00
sealed interface Executor extends Predicate<CommandSender> permits GraphImpl.ExecutorImpl {
2022-07-14 00:55:19 +02:00
/**
* Non-null if the command has a default syntax error handler, must be present on
* declaring node and all subsequent ones, a sub command must continue with its own
* if present, otherwise the previous has to be propagated further.
*/
@Nullable ArgumentCallback syntaxErrorCallback();
/**
* Non-null if the command at this point considered executable, must be present
* on last required node and all subsequent optional nodes
*/
@Nullable CommandExecutor executor();
/**
* Non-null if the command or syntax has a condition, must be present
* only on nodes that specify it
*/
@Nullable CommandCondition condition();
/**
* Non-null if the node at this point considered executable and optional nodes are
* present after this node, this map must only contain suppliers for following nodes
*/
@Nullable Map<String, Supplier<?>> defaultValueSuppliers();
2022-07-13 22:45:38 +02:00
}
sealed interface Builder permits GraphImpl.BuilderImpl {
@NotNull Builder append(@NotNull Argument<?> argument, @NotNull Consumer<Builder> consumer);
@NotNull Builder append(@NotNull Argument<?> argument);
@NotNull Graph build();
}
enum Comparator {
TREE
}
}