diff --git a/src/main/java/net/minecraft/commands/builder/RequiredArgumentBuilder.java b/src/main/java/net/minecraft/commands/builder/RequiredArgumentBuilder.java index 651ddd5..808914c 100644 --- a/src/main/java/net/minecraft/commands/builder/RequiredArgumentBuilder.java +++ b/src/main/java/net/minecraft/commands/builder/RequiredArgumentBuilder.java @@ -30,7 +30,7 @@ public class RequiredArgumentBuilder extends ArgumentBuilder build() { - ArgumentCommandNode result = new ArgumentCommandNode(getName(), getType()); + ArgumentCommandNode result = new ArgumentCommandNode(getName(), getType(), getExecutor()); for (ArgumentBuilder argument : getArguments()) { result.addChild(argument.build()); diff --git a/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java b/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java index 55a5f18..4d8af85 100644 --- a/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java @@ -8,7 +8,8 @@ public class ArgumentCommandNode extends CommandNode { private final String name; private final CommandArgumentType type; - public ArgumentCommandNode(String name, CommandArgumentType type) { + public ArgumentCommandNode(String name, CommandArgumentType type, Runnable executor) { + super(executor); this.name = name; this.type = type; } diff --git a/src/main/java/net/minecraft/commands/tree/CommandNode.java b/src/main/java/net/minecraft/commands/tree/CommandNode.java index fa0f360..b8e1ae3 100644 --- a/src/main/java/net/minecraft/commands/tree/CommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/CommandNode.java @@ -7,8 +7,17 @@ import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; import java.util.List; public abstract class CommandNode { + private final Runnable executor; private final List children = Lists.newArrayList(); + protected CommandNode(Runnable executor) { + this.executor = executor; + } + + public Runnable getExecutor() { + return executor; + } + public List getChildren() { return children; } diff --git a/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java b/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java index f1f9ed3..6e213c9 100644 --- a/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java @@ -5,21 +5,16 @@ import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; public class LiteralCommandNode extends CommandNode { private final String literal; - private final Runnable executor; public LiteralCommandNode(String literal, Runnable executor) { + super(executor); this.literal = literal; - this.executor = executor; } public String getLiteral() { return literal; } - public Runnable getExecutor() { - return executor; - } - @Override public CommandNode parse(String command) throws IllegalArgumentSyntaxException, ArgumentValidationException { if (command.startsWith(literal)) { diff --git a/src/main/test/net/minecraft/commands/builder/LiteralArgumentBuilderTest.java b/src/main/test/net/minecraft/commands/builder/LiteralArgumentBuilderTest.java index a9cf096..72f72e3 100644 --- a/src/main/test/net/minecraft/commands/builder/LiteralArgumentBuilderTest.java +++ b/src/main/test/net/minecraft/commands/builder/LiteralArgumentBuilderTest.java @@ -3,6 +3,7 @@ package net.minecraft.commands.builder; import net.minecraft.commands.tree.LiteralCommandNode; import org.junit.Before; import org.junit.Test; +import org.mockito.Mock; import static net.minecraft.commands.arguments.IntegerArgumentType.integer; import static net.minecraft.commands.builder.RequiredArgumentBuilder.argument; @@ -12,6 +13,8 @@ import static org.junit.Assert.assertThat; public class LiteralArgumentBuilderTest { LiteralArgumentBuilder builder; + @Mock + Runnable executor; @Before public void setUp() throws Exception { @@ -25,6 +28,14 @@ public class LiteralArgumentBuilderTest { assertThat(node.getLiteral(), is("foo")); } + @Test + public void testBuildWithExecutor() throws Exception { + LiteralCommandNode node = builder.executes(executor).build(); + + assertThat(node.getLiteral(), is("foo")); + assertThat(node.getExecutor(), is(executor)); + } + @Test public void testBuildWithChildren() throws Exception { builder.then(argument("bar", integer())); diff --git a/src/main/test/net/minecraft/commands/builder/RequiredArgumentBuilderTest.java b/src/main/test/net/minecraft/commands/builder/RequiredArgumentBuilderTest.java index 5c5e1b6..fda5d59 100644 --- a/src/main/test/net/minecraft/commands/builder/RequiredArgumentBuilderTest.java +++ b/src/main/test/net/minecraft/commands/builder/RequiredArgumentBuilderTest.java @@ -15,6 +15,7 @@ import static org.junit.Assert.assertThat; public class RequiredArgumentBuilderTest { @Mock CommandArgumentType type; RequiredArgumentBuilder builder; + @Mock Runnable executor; @Before public void setUp() throws Exception { @@ -29,6 +30,15 @@ public class RequiredArgumentBuilderTest { assertThat(node.getType(), is(type)); } + @Test + public void testBuildWithExecutor() throws Exception { + ArgumentCommandNode node = builder.executes(executor).build(); + + assertThat(node.getName(), is("foo")); + assertThat(node.getType(), is(type)); + assertThat(node.getExecutor(), is(executor)); + } + @Test public void testBuildWithChildren() throws Exception { builder.then(argument("bar", integer()));