Made ArgumentBuilders use a RootCommandNode to hold their arguments

This commit is contained in:
Nathan Adams 2014-09-25 16:36:45 +02:00
parent 5760f94009
commit d8c9e15a1c
4 changed files with 12 additions and 10 deletions

View file

@ -1,24 +1,24 @@
package net.minecraft.commands.builder; package net.minecraft.commands.builder;
import com.google.common.collect.Lists;
import net.minecraft.commands.Command; import net.minecraft.commands.Command;
import net.minecraft.commands.tree.CommandNode; import net.minecraft.commands.tree.CommandNode;
import net.minecraft.commands.tree.RootCommandNode;
import java.util.List; import java.util.List;
public abstract class ArgumentBuilder<T extends ArgumentBuilder<?>> { public abstract class ArgumentBuilder<T extends ArgumentBuilder<?>> {
private final List<ArgumentBuilder> arguments = Lists.newArrayList(); private final RootCommandNode arguments = new RootCommandNode();
private Command command; private Command command;
protected abstract T getThis(); protected abstract T getThis();
public T then(ArgumentBuilder argument) { public T then(ArgumentBuilder argument) {
arguments.add(argument); arguments.addChild(argument.build());
return getThis(); return getThis();
} }
public List<ArgumentBuilder> getArguments() { public List<CommandNode> getArguments() {
return arguments; return arguments.getChildren();
} }
public T executes(Command command) { public T executes(Command command) {

View file

@ -1,5 +1,6 @@
package net.minecraft.commands.builder; package net.minecraft.commands.builder;
import net.minecraft.commands.tree.CommandNode;
import net.minecraft.commands.tree.LiteralCommandNode; import net.minecraft.commands.tree.LiteralCommandNode;
public class LiteralArgumentBuilder extends ArgumentBuilder<LiteralArgumentBuilder> { public class LiteralArgumentBuilder extends ArgumentBuilder<LiteralArgumentBuilder> {
@ -26,8 +27,8 @@ public class LiteralArgumentBuilder extends ArgumentBuilder<LiteralArgumentBuild
public LiteralCommandNode build() { public LiteralCommandNode build() {
LiteralCommandNode result = new LiteralCommandNode(getLiteral(), getCommand()); LiteralCommandNode result = new LiteralCommandNode(getLiteral(), getCommand());
for (ArgumentBuilder argument : getArguments()) { for (CommandNode argument : getArguments()) {
result.addChild(argument.build()); result.addChild(argument);
} }
return result; return result;

View file

@ -2,6 +2,7 @@ package net.minecraft.commands.builder;
import net.minecraft.commands.arguments.CommandArgumentType; import net.minecraft.commands.arguments.CommandArgumentType;
import net.minecraft.commands.tree.ArgumentCommandNode; import net.minecraft.commands.tree.ArgumentCommandNode;
import net.minecraft.commands.tree.CommandNode;
public class RequiredArgumentBuilder<T> extends ArgumentBuilder<RequiredArgumentBuilder<T>> { public class RequiredArgumentBuilder<T> extends ArgumentBuilder<RequiredArgumentBuilder<T>> {
private final String name; private final String name;
@ -32,8 +33,8 @@ public class RequiredArgumentBuilder<T> extends ArgumentBuilder<RequiredArgument
public ArgumentCommandNode<T> build() { public ArgumentCommandNode<T> build() {
ArgumentCommandNode<T> result = new ArgumentCommandNode<T>(getName(), getType(), getCommand()); ArgumentCommandNode<T> result = new ArgumentCommandNode<T>(getName(), getType(), getCommand());
for (ArgumentBuilder argument : getArguments()) { for (CommandNode argument : getArguments()) {
result.addChild(argument.build()); result.addChild(argument);
} }
return result; return result;

View file

@ -25,7 +25,7 @@ public class ArgumentBuilderTest {
builder.then(argument); builder.then(argument);
assertThat(builder.getArguments(), hasSize(1)); assertThat(builder.getArguments(), hasSize(1));
assertThat(builder.getArguments(), hasItems((ArgumentBuilder) argument)); assertThat(builder.getArguments(), hasItems((CommandNode) argument.build()));
} }
private static class TestableArgumentBuilder extends ArgumentBuilder<TestableArgumentBuilder> { private static class TestableArgumentBuilder extends ArgumentBuilder<TestableArgumentBuilder> {