Renamed CommandBuilder to LiteralArgumentBuilder
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package net.minecraft.commands;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.commands.builder.CommandBuilder;
|
||||
import net.minecraft.commands.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.commands.exceptions.CommandException;
|
||||
import net.minecraft.commands.exceptions.UnknownCommandException;
|
||||
import net.minecraft.commands.tree.LiteralCommandNode;
|
||||
@@ -11,11 +11,11 @@ import java.util.Map;
|
||||
public class CommandDispatcher {
|
||||
private final Map<String, LiteralCommandNode> commands = Maps.newHashMap();
|
||||
|
||||
public void register(CommandBuilder command) {
|
||||
if (commands.containsKey(command.getName())) {
|
||||
throw new IllegalArgumentException("New command " + command.getName() + " conflicts with existing command " + command.getName());
|
||||
public void register(LiteralArgumentBuilder command) {
|
||||
if (commands.containsKey(command.getLiteral())) {
|
||||
throw new IllegalArgumentException("New command " + command.getLiteral() + " conflicts with existing command " + command.getLiteral());
|
||||
}
|
||||
commands.put(command.getName(), command.build());
|
||||
commands.put(command.getLiteral(), command.build());
|
||||
}
|
||||
|
||||
public void execute(String command) throws CommandException {
|
||||
|
||||
@@ -5,17 +5,29 @@ import net.minecraft.commands.tree.CommandNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ArgumentBuilder {
|
||||
public abstract class ArgumentBuilder<T extends ArgumentBuilder<?>> {
|
||||
private final List<ArgumentBuilder> arguments = Lists.newArrayList();
|
||||
private Runnable executor;
|
||||
|
||||
public ArgumentBuilder then(ArgumentBuilder argument) {
|
||||
protected abstract T getThis();
|
||||
|
||||
public T then(ArgumentBuilder argument) {
|
||||
arguments.add(argument);
|
||||
return this;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public List<ArgumentBuilder> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public T executes(Runnable executor) {
|
||||
this.executor = executor;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public Runnable getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
public abstract CommandNode build();
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package net.minecraft.commands.builder;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.commands.tree.LiteralCommandNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandBuilder {
|
||||
private final String name;
|
||||
private final List<ArgumentBuilder> arguments = Lists.newArrayList();
|
||||
private Runnable executor;
|
||||
|
||||
protected CommandBuilder(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static CommandBuilder command(String name) {
|
||||
return new CommandBuilder(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CommandBuilder executes(Runnable executor) {
|
||||
this.executor = executor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Runnable getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
public CommandBuilder then(ArgumentBuilder argument) {
|
||||
arguments.add(argument);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<ArgumentBuilder> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public LiteralCommandNode build() {
|
||||
LiteralCommandNode result = new LiteralCommandNode(getName(), getExecutor());
|
||||
|
||||
for (ArgumentBuilder argument : arguments) {
|
||||
result.addChild(argument.build());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.minecraft.commands.builder;
|
||||
|
||||
import net.minecraft.commands.tree.LiteralCommandNode;
|
||||
|
||||
public class LiteralArgumentBuilder extends ArgumentBuilder<LiteralArgumentBuilder> {
|
||||
private final String literal;
|
||||
|
||||
protected LiteralArgumentBuilder(String literal) {
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
public static LiteralArgumentBuilder literal(String name) {
|
||||
return new LiteralArgumentBuilder(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LiteralArgumentBuilder getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getLiteral() {
|
||||
return literal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode build() {
|
||||
LiteralCommandNode result = new LiteralCommandNode(getLiteral(), getExecutor());
|
||||
|
||||
for (ArgumentBuilder argument : getArguments()) {
|
||||
result.addChild(argument.build());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package net.minecraft.commands.builder;
|
||||
import net.minecraft.commands.arguments.CommandArgumentType;
|
||||
import net.minecraft.commands.tree.ArgumentCommandNode;
|
||||
|
||||
public class RequiredArgumentBuilder<T> extends ArgumentBuilder {
|
||||
public class RequiredArgumentBuilder<T> extends ArgumentBuilder<RequiredArgumentBuilder<T>> {
|
||||
private final String name;
|
||||
private final CommandArgumentType<T> type;
|
||||
|
||||
@@ -16,6 +16,11 @@ public class RequiredArgumentBuilder<T> extends ArgumentBuilder {
|
||||
return new RequiredArgumentBuilder<T>(name, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RequiredArgumentBuilder<T> getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandArgumentType<T> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user