diff --git a/src/main/java/net/minestom/server/command/Graph.java b/src/main/java/net/minestom/server/command/Graph.java index 1e0a3a11a..01b9e16d2 100644 --- a/src/main/java/net/minestom/server/command/Graph.java +++ b/src/main/java/net/minestom/server/command/Graph.java @@ -38,12 +38,12 @@ sealed interface Graph permits GraphImpl { sealed interface Node permits GraphImpl.NodeImpl { @NotNull Argument argument(); - @UnknownNullability Executor executor(); + @UnknownNullability Execution execution(); @NotNull List<@NotNull Node> next(); } - sealed interface Executor extends Predicate permits GraphImpl.ExecutorImpl { + sealed interface Execution extends Predicate permits GraphImpl.ExecutionImpl { // TODO execute the node } diff --git a/src/main/java/net/minestom/server/command/GraphConverter.java b/src/main/java/net/minestom/server/command/GraphConverter.java index a9424257a..9f1c37c6a 100644 --- a/src/main/java/net/minestom/server/command/GraphConverter.java +++ b/src/main/java/net/minestom/server/command/GraphConverter.java @@ -32,9 +32,9 @@ final class GraphConverter { private static int[] append(Graph.Node graphNode, List to, List> rootRedirect, AtomicInteger id, @Nullable AtomicInteger redirect, List redirectSetters, @Nullable Player player) { - final Graph.Executor executor = graphNode.executor(); - if (player != null && executor != null) { - if (!executor.test(player)) return new int[0]; + final Graph.Execution execution = graphNode.execution(); + if (player != null && execution != null) { + if (!execution.test(player)) return new int[0]; } final Argument argument = graphNode.argument(); diff --git a/src/main/java/net/minestom/server/command/GraphImpl.java b/src/main/java/net/minestom/server/command/GraphImpl.java index b22692ee0..5cb464202 100644 --- a/src/main/java/net/minestom/server/command/GraphImpl.java +++ b/src/main/java/net/minestom/server/command/GraphImpl.java @@ -57,7 +57,7 @@ record GraphImpl(NodeImpl root) implements Graph { } } - record NodeImpl(Argument argument, ExecutorImpl executor, List next) implements Graph.Node { + record NodeImpl(Argument argument, ExecutionImpl execution, List next) implements Graph.Node { static NodeImpl fromBuilder(BuilderImpl builder) { final List children = builder.children; Node[] nodes = new NodeImpl[children.size()]; @@ -74,47 +74,47 @@ record GraphImpl(NodeImpl root) implements Graph { } } - record ExecutorImpl(Predicate predicate) implements Graph.Executor { + record ExecutionImpl(Predicate predicate) implements Execution { @Override public boolean test(CommandSender commandSender) { return predicate.test(commandSender); } - static ExecutorImpl fromCommand(Command command) { + static ExecutionImpl fromCommand(Command command) { final CommandCondition condition = command.getCondition(); if (condition == null) return null; - return new ExecutorImpl(commandSender -> condition.canUse(commandSender, null)); + return new ExecutionImpl(commandSender -> condition.canUse(commandSender, null)); } - static ExecutorImpl fromSyntax(CommandSyntax syntax) { + static ExecutionImpl fromSyntax(CommandSyntax syntax) { final CommandCondition condition = syntax.getCommandCondition(); if (condition == null) return null; - return new ExecutorImpl(commandSender -> condition.canUse(commandSender, null)); + return new ExecutionImpl(commandSender -> condition.canUse(commandSender, null)); } } - private record ConversionNode(Argument argument, ExecutorImpl executor, + private record ConversionNode(Argument argument, ExecutionImpl execution, Map, ConversionNode> nextMap) { - ConversionNode(Argument argument, ExecutorImpl executor) { - this(argument, executor, new LinkedHashMap<>()); + ConversionNode(Argument argument, ExecutionImpl execution) { + this(argument, execution, new LinkedHashMap<>()); } private NodeImpl toNode() { Node[] nodes = new NodeImpl[nextMap.size()]; int i = 0; for (var entry : nextMap.values()) nodes[i++] = entry.toNode(); - return new NodeImpl(argument, executor, List.of(nodes)); + return new NodeImpl(argument, execution, List.of(nodes)); } static ConversionNode fromCommand(Command command) { - ConversionNode root = new ConversionNode(Literal(command.getName()), ExecutorImpl.fromCommand(command)); + ConversionNode root = new ConversionNode(Literal(command.getName()), ExecutionImpl.fromCommand(command)); // Syntaxes for (CommandSyntax syntax : command.getSyntaxes()) { ConversionNode syntaxNode = root; for (Argument arg : syntax.getArguments()) { boolean last = arg == syntax.getArguments()[syntax.getArguments().length - 1]; syntaxNode = syntaxNode.nextMap.computeIfAbsent(arg, argument -> { - var ex = last ? ExecutorImpl.fromSyntax(syntax) : null; + var ex = last ? ExecutionImpl.fromSyntax(syntax) : null; return new ConversionNode(argument, ex); }); } diff --git a/src/test/java/net/minestom/server/command/GraphConversionExecutorTest.java b/src/test/java/net/minestom/server/command/GraphConversionExecutorTest.java index f1f6f67de..06d4f3c6e 100644 --- a/src/test/java/net/minestom/server/command/GraphConversionExecutorTest.java +++ b/src/test/java/net/minestom/server/command/GraphConversionExecutorTest.java @@ -12,7 +12,7 @@ public class GraphConversionExecutorTest { public void empty() { final Command foo = new Command("foo"); var graph = Graph.fromCommand(foo); - assertNull(graph.root().executor()); + assertNull(graph.root().execution()); } @Test @@ -22,17 +22,17 @@ public class GraphConversionExecutorTest { { foo.setCondition((sender, commandString) -> true); var graph = Graph.fromCommand(foo); - var executor = graph.root().executor(); - assertNotNull(executor); - assertTrue(executor.test(null)); + var execution = graph.root().execution(); + assertNotNull(execution); + assertTrue(execution.test(null)); } // Constant false { foo.setCondition((sender, commandString) -> false); var graph = Graph.fromCommand(foo); - var executor = graph.root().executor(); - assertNotNull(executor); - assertFalse(executor.test(null)); + var execution = graph.root().execution(); + assertNotNull(execution); + assertFalse(execution.test(null)); } } @@ -43,7 +43,7 @@ public class GraphConversionExecutorTest { var graph = Graph.fromCommand(foo); assertEquals(1, graph.root().next().size()); - assertNull(graph.root().next().get(0).executor()); + assertNull(graph.root().next().get(0).execution()); } @Test @@ -54,9 +54,9 @@ public class GraphConversionExecutorTest { var graph = Graph.fromCommand(foo); assertEquals(1, graph.root().next().size()); - var executor = graph.root().next().get(0).executor(); - assertNotNull(executor); - assertTrue(executor.test(null)); + var execution = graph.root().next().get(0).execution(); + assertNotNull(execution); + assertTrue(execution.test(null)); } @Test @@ -67,9 +67,9 @@ public class GraphConversionExecutorTest { var graph = Graph.fromCommand(foo); assertEquals(1, graph.root().next().size()); - var executor = graph.root().next().get(0).executor(); - assertNotNull(executor); - assertFalse(executor.test(null)); + var execution = graph.root().next().get(0).execution(); + assertNotNull(execution); + assertFalse(execution.test(null)); } private static void dummyExecutor(CommandSender sender, CommandContext context) {