Just use a regular builder
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user