diff --git a/src/main/java/net/minecraft/commands/Command.java b/src/main/java/net/minecraft/commands/Command.java new file mode 100644 index 0000000..95c518c --- /dev/null +++ b/src/main/java/net/minecraft/commands/Command.java @@ -0,0 +1,7 @@ +package net.minecraft.commands; + +import net.minecraft.commands.context.CommandContext; + +public interface Command { + void run(CommandContext context); +} diff --git a/src/main/java/net/minecraft/commands/CommandDispatcher.java b/src/main/java/net/minecraft/commands/CommandDispatcher.java index 5b7a8f3..72e29de 100644 --- a/src/main/java/net/minecraft/commands/CommandDispatcher.java +++ b/src/main/java/net/minecraft/commands/CommandDispatcher.java @@ -2,10 +2,13 @@ package net.minecraft.commands; import com.google.common.collect.Maps; import net.minecraft.commands.builder.LiteralArgumentBuilder; +import net.minecraft.commands.context.CommandContext; +import net.minecraft.commands.context.ParsedArgument; import net.minecraft.commands.exceptions.CommandException; import net.minecraft.commands.exceptions.UnknownCommandException; import net.minecraft.commands.tree.LiteralCommandNode; +import java.util.HashMap; import java.util.Map; public class CommandDispatcher { @@ -24,6 +27,6 @@ public class CommandDispatcher { throw new UnknownCommandException(); } - node.getExecutor().run(); + node.getCommand().run(new CommandContext(new HashMap>())); } } diff --git a/src/main/java/net/minecraft/commands/builder/ArgumentBuilder.java b/src/main/java/net/minecraft/commands/builder/ArgumentBuilder.java index 91588ed..6cbb402 100644 --- a/src/main/java/net/minecraft/commands/builder/ArgumentBuilder.java +++ b/src/main/java/net/minecraft/commands/builder/ArgumentBuilder.java @@ -1,13 +1,14 @@ package net.minecraft.commands.builder; import com.google.common.collect.Lists; +import net.minecraft.commands.Command; import net.minecraft.commands.tree.CommandNode; import java.util.List; public abstract class ArgumentBuilder> { private final List arguments = Lists.newArrayList(); - private Runnable executor; + private Command command; protected abstract T getThis(); @@ -20,13 +21,13 @@ public abstract class ArgumentBuilder> { return arguments; } - public T executes(Runnable executor) { - this.executor = executor; + public T executes(Command command) { + this.command = command; return getThis(); } - public Runnable getExecutor() { - return executor; + public Command getCommand() { + return command; } public abstract CommandNode build(); diff --git a/src/main/java/net/minecraft/commands/builder/LiteralArgumentBuilder.java b/src/main/java/net/minecraft/commands/builder/LiteralArgumentBuilder.java index 05ce82d..0b3a593 100644 --- a/src/main/java/net/minecraft/commands/builder/LiteralArgumentBuilder.java +++ b/src/main/java/net/minecraft/commands/builder/LiteralArgumentBuilder.java @@ -24,7 +24,7 @@ public class LiteralArgumentBuilder extends ArgumentBuilder extends ArgumentBuilder build() { - ArgumentCommandNode result = new ArgumentCommandNode(getName(), getType(), getExecutor()); + ArgumentCommandNode result = new ArgumentCommandNode(getName(), getType(), getCommand()); 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 dd583ca..0d22f32 100644 --- a/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java @@ -1,5 +1,6 @@ package net.minecraft.commands.tree; +import net.minecraft.commands.Command; import net.minecraft.commands.arguments.CommandArgumentType; import net.minecraft.commands.context.ParsedArgument; import net.minecraft.commands.exceptions.ArgumentValidationException; @@ -9,8 +10,8 @@ public class ArgumentCommandNode extends CommandNode { private final String name; private final CommandArgumentType type; - public ArgumentCommandNode(String name, CommandArgumentType type, Runnable executor) { - super(executor); + public ArgumentCommandNode(String name, CommandArgumentType type, Command command) { + super(command); 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 b8e1ae3..987d18b 100644 --- a/src/main/java/net/minecraft/commands/tree/CommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/CommandNode.java @@ -1,21 +1,22 @@ package net.minecraft.commands.tree; import com.google.common.collect.Lists; +import net.minecraft.commands.Command; import net.minecraft.commands.exceptions.ArgumentValidationException; import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; import java.util.List; public abstract class CommandNode { - private final Runnable executor; + private final Command command; private final List children = Lists.newArrayList(); - protected CommandNode(Runnable executor) { - this.executor = executor; + protected CommandNode(Command command) { + this.command = command; } - public Runnable getExecutor() { - return executor; + public Command getCommand() { + return command; } public List getChildren() { diff --git a/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java b/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java index 6e213c9..bf5a840 100644 --- a/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java @@ -1,13 +1,14 @@ package net.minecraft.commands.tree; +import net.minecraft.commands.Command; import net.minecraft.commands.exceptions.ArgumentValidationException; import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; public class LiteralCommandNode extends CommandNode { private final String literal; - public LiteralCommandNode(String literal, Runnable executor) { - super(executor); + public LiteralCommandNode(String literal, Command command) { + super(command); this.literal = literal; } diff --git a/src/main/test/net/minecraft/commands/CommandDispatcherTest.java b/src/main/test/net/minecraft/commands/CommandDispatcherTest.java index a4d13bb..108ede9 100644 --- a/src/main/test/net/minecraft/commands/CommandDispatcherTest.java +++ b/src/main/test/net/minecraft/commands/CommandDispatcherTest.java @@ -1,5 +1,6 @@ package net.minecraft.commands; +import net.minecraft.commands.context.CommandContext; import net.minecraft.commands.exceptions.UnknownCommandException; import org.junit.Before; import org.junit.Test; @@ -8,12 +9,13 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import static net.minecraft.commands.builder.LiteralArgumentBuilder.literal; +import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; @RunWith(MockitoJUnitRunner.class) public class CommandDispatcherTest { CommandDispatcher subject; - @Mock Runnable runnable; + @Mock Command command; @Before public void setUp() throws Exception { @@ -22,16 +24,16 @@ public class CommandDispatcherTest { @Test(expected = IllegalArgumentException.class) public void testDuplicateCommand() throws Exception { - subject.register(literal("foo").executes(runnable)); - subject.register(literal("foo").executes(runnable)); + subject.register(literal("foo").executes(command)); + subject.register(literal("foo").executes(command)); } @Test public void testCreateAndExecuteCommand() throws Exception { - subject.register(literal("foo").executes(runnable)); + subject.register(literal("foo").executes(command)); subject.execute("foo"); - verify(runnable).run(); + verify(command).run(any(CommandContext.class)); } @Test(expected = UnknownCommandException.class) diff --git a/src/main/test/net/minecraft/commands/builder/LiteralArgumentBuilderTest.java b/src/main/test/net/minecraft/commands/builder/LiteralArgumentBuilderTest.java index 72f72e3..e110882 100644 --- a/src/main/test/net/minecraft/commands/builder/LiteralArgumentBuilderTest.java +++ b/src/main/test/net/minecraft/commands/builder/LiteralArgumentBuilderTest.java @@ -1,5 +1,6 @@ package net.minecraft.commands.builder; +import net.minecraft.commands.Command; import net.minecraft.commands.tree.LiteralCommandNode; import org.junit.Before; import org.junit.Test; @@ -14,7 +15,7 @@ import static org.junit.Assert.assertThat; public class LiteralArgumentBuilderTest { LiteralArgumentBuilder builder; @Mock - Runnable executor; + Command command; @Before public void setUp() throws Exception { @@ -30,10 +31,10 @@ public class LiteralArgumentBuilderTest { @Test public void testBuildWithExecutor() throws Exception { - LiteralCommandNode node = builder.executes(executor).build(); + LiteralCommandNode node = builder.executes(command).build(); assertThat(node.getLiteral(), is("foo")); - assertThat(node.getExecutor(), is(executor)); + assertThat(node.getCommand(), is(command)); } @Test diff --git a/src/main/test/net/minecraft/commands/builder/RequiredArgumentBuilderTest.java b/src/main/test/net/minecraft/commands/builder/RequiredArgumentBuilderTest.java index fda5d59..437dc22 100644 --- a/src/main/test/net/minecraft/commands/builder/RequiredArgumentBuilderTest.java +++ b/src/main/test/net/minecraft/commands/builder/RequiredArgumentBuilderTest.java @@ -1,5 +1,6 @@ package net.minecraft.commands.builder; +import net.minecraft.commands.Command; import net.minecraft.commands.arguments.CommandArgumentType; import net.minecraft.commands.tree.ArgumentCommandNode; import org.junit.Before; @@ -15,7 +16,8 @@ import static org.junit.Assert.assertThat; public class RequiredArgumentBuilderTest { @Mock CommandArgumentType type; RequiredArgumentBuilder builder; - @Mock Runnable executor; + @Mock + Command command; @Before public void setUp() throws Exception { @@ -32,11 +34,11 @@ public class RequiredArgumentBuilderTest { @Test public void testBuildWithExecutor() throws Exception { - ArgumentCommandNode node = builder.executes(executor).build(); + ArgumentCommandNode node = builder.executes(command).build(); assertThat(node.getName(), is("foo")); assertThat(node.getType(), is(type)); - assertThat(node.getExecutor(), is(executor)); + assertThat(node.getCommand(), is(command)); } @Test