Create ICommand to go alongside Command default implementation

This commit is contained in:
Brady
2019-10-07 16:46:21 -05:00
parent c908552174
commit 4d05b152f0
12 changed files with 111 additions and 58 deletions

View File

@@ -18,7 +18,7 @@
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.ICommand;
import java.util.*;
@@ -26,9 +26,9 @@ public final class DefaultCommands {
private DefaultCommands() {}
public static List<Command> createAll(IBaritone baritone) {
public static List<ICommand> createAll(IBaritone baritone) {
Objects.requireNonNull(baritone);
List<Command> commands = new ArrayList<>(Arrays.asList(
List<ICommand> commands = new ArrayList<>(Arrays.asList(
new HelpCommand(baritone),
new SetCommand(baritone),
new CommandAlias(baritone, Arrays.asList("modified", "mod", "baritone", "modifiedsettings"), "List modified settings", "set modified"),

View File

@@ -19,6 +19,7 @@ package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.ICommand;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandNotFoundException;
import baritone.api.command.argument.IArgConsumer;
@@ -79,7 +80,7 @@ public class HelpCommand extends Command {
);
} else {
String commandName = args.getString().toLowerCase();
Command command = this.baritone.getCommandManager().getCommand(commandName);
ICommand command = this.baritone.getCommandManager().getCommand(commandName);
if (command == null) {
throw new CommandNotFoundException(commandName);
}

View File

@@ -19,7 +19,7 @@ package baritone.command.manager;
import baritone.Baritone;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.exception.CommandUnhandledException;
import baritone.api.command.exception.ICommandException;
@@ -43,7 +43,7 @@ import java.util.stream.Stream;
*/
public class CommandManager implements ICommandManager {
private final Registry<Command> registry = new Registry<>();
private final Registry<ICommand> registry = new Registry<>();
private final Baritone baritone;
public CommandManager(Baritone baritone) {
@@ -57,13 +57,13 @@ public class CommandManager implements ICommandManager {
}
@Override
public Registry<Command> getRegistry() {
public Registry<ICommand> getRegistry() {
return this.registry;
}
@Override
public Command getCommand(String name) {
for (Command command : this.registry.entries) {
public ICommand getCommand(String name) {
for (ICommand command : this.registry.entries) {
if (command.getNames().contains(name.toLowerCase(Locale.US))) {
return command;
}
@@ -110,7 +110,7 @@ public class CommandManager implements ICommandManager {
String label = expanded.getFirst();
ArgConsumer args = new ArgConsumer(this, expanded.getSecond());
Command command = this.getCommand(label);
ICommand command = this.getCommand(label);
return command == null ? null : new ExecutionWrapper(command, label, args);
}
@@ -125,11 +125,11 @@ public class CommandManager implements ICommandManager {
}
private static final class ExecutionWrapper {
private Command command;
private ICommand command;
private String label;
private ArgConsumer args;
private ExecutionWrapper(Command command, String label, ArgConsumer args) {
private ExecutionWrapper(ICommand command, String label, ArgConsumer args) {
this.command = command;
this.label = label;
this.args = args;