Just use a regular builder

This commit is contained in:
Nathan Adams
2014-09-16 14:47:19 +02:00
parent c73607ba36
commit dadedbb322
4 changed files with 28 additions and 72 deletions
@@ -10,16 +10,11 @@ import java.util.Map;
public class CommandDispatcher {
private final Map<String, Runnable> commands = Maps.newHashMap();
public CommandBuilder createCommand(final String name) {
return new CommandBuilder() {
@Override
public void onFinish() {
if (commands.containsKey(name)) {
throw new IllegalArgumentException("New command " + name + " conflicts with existing command " + name);
}
commands.put(name, getCommandExecutor());
}
};
public void register(CommandBuilder command) {
if (commands.containsKey(command.getName())) {
throw new IllegalArgumentException("New command " + command.getName() + " conflicts with existing command " + command.getName());
}
commands.put(command.getName(), command.getExecutor());
}
public void execute(String command) throws CommandException {
@@ -1,28 +1,27 @@
package net.minecraft.commands.builder;
public abstract class CommandBuilder {
private boolean finished;
private Runnable commandExecutor;
public class CommandBuilder {
private final String name;
private Runnable executor;
public void finish() {
if (finished) {
throw new IllegalStateException("Cannot finish() multiple times!");
}
if (commandExecutor == null) {
throw new IllegalStateException("Cannot finish() without a command executor!");
}
onFinish();
finished = true;
protected CommandBuilder(String name) {
this.name = name;
}
protected abstract void onFinish();
public static CommandBuilder command(String name) {
return new CommandBuilder(name);
}
public CommandBuilder executes(Runnable runnable) {
this.commandExecutor = runnable;
public String getName() {
return name;
}
public CommandBuilder executes(Runnable executor) {
this.executor = executor;
return this;
}
public Runnable getCommandExecutor() {
return commandExecutor;
public Runnable getExecutor() {
return executor;
}
}