diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java
index e31ef0f8..b7228e33 100644
--- a/src/api/java/baritone/api/IBaritoneProvider.java
+++ b/src/api/java/baritone/api/IBaritoneProvider.java
@@ -18,7 +18,7 @@
package baritone.api;
import baritone.api.cache.IWorldScanner;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.ICommandSystem;
import net.minecraft.client.entity.EntityPlayerSP;
@@ -77,7 +77,7 @@ public interface IBaritoneProvider {
/**
* Returns the {@link ICommandSystem} instance. This is not bound to a specific {@link IBaritone}
- * instance because {@link ICommandSystem} itself controls global behavior for {@link Command}s.
+ * instance because {@link ICommandSystem} itself controls global behavior for {@link ICommand}s.
*
* @return The {@link ICommandSystem} instance.
*/
diff --git a/src/api/java/baritone/api/command/Command.java b/src/api/java/baritone/api/command/Command.java
index 3379b67c..4db5c0f3 100644
--- a/src/api/java/baritone/api/command/Command.java
+++ b/src/api/java/baritone/api/command/Command.java
@@ -18,10 +18,7 @@
package baritone.api.command;
import baritone.api.IBaritone;
-import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
-import baritone.api.command.exception.CommandException;
-import baritone.api.command.argument.IArgConsumer;
import java.util.Collections;
import java.util.List;
@@ -29,7 +26,19 @@ import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-public abstract class Command implements Helper {
+/**
+ * A default implementation of {@link ICommand} which provides easy access to the
+ * command's bound {@link IBaritone} instance, {@link IPlayerContext} and an easy
+ * way to provide multiple valid command execution names through the default constructor.
+ *
+ * So basically, you should use it because it provides a small amount of boilerplate,
+ * but you're not forced to use it.
+ *
+ * @see ICommand
+ *
+ * @author LoganDark
+ */
+public abstract class Command implements ICommand {
protected IBaritone baritone;
protected IPlayerContext ctx;
@@ -52,34 +61,7 @@ public abstract class Command implements Helper {
this.ctx = baritone.getPlayerContext();
}
- /**
- * Called when this command is executed.
- */
- public abstract void execute(String label, IArgConsumer args) throws CommandException;
-
- /**
- * Called when the command needs to tab complete. Return a Stream representing the entries to put in the completions
- * list.
- */
- public abstract Stream tabComplete(String label, IArgConsumer args) throws CommandException;
-
- /**
- * @return A single-line string containing a short description of this command's purpose.
- */
- public abstract String getShortDesc();
-
- /**
- * @return A list of lines that will be printed by the help command when the user wishes to view them.
- */
- public abstract List getLongDesc();
-
- /**
- * @return {@code true} if this command should be hidden from the help menu
- */
- public boolean hiddenFromHelp() {
- return false;
- }
-
+ @Override
public final List getNames() {
return this.names;
}
diff --git a/src/api/java/baritone/api/command/ICommand.java b/src/api/java/baritone/api/command/ICommand.java
new file mode 100644
index 00000000..46392448
--- /dev/null
+++ b/src/api/java/baritone/api/command/ICommand.java
@@ -0,0 +1,67 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package baritone.api.command;
+
+import baritone.api.command.exception.CommandException;
+import baritone.api.command.helpers.arguments.IArgConsumer;
+import baritone.api.utils.Helper;
+
+import java.util.List;
+import java.util.stream.Stream;
+
+/**
+ * The base for a command.
+ *
+ * @author Brady
+ * @since 10/7/2019
+ */
+public interface ICommand extends Helper {
+
+ /**
+ * Called when this command is executed.
+ */
+ void execute(String label, IArgConsumer args) throws CommandException;
+
+ /**
+ * Called when the command needs to tab complete. Return a Stream representing the entries to put in the completions
+ * list.
+ */
+ Stream tabComplete(String label, IArgConsumer args) throws CommandException;
+
+ /**
+ * @return A single-line string containing a short description of this command's purpose.
+ */
+ String getShortDesc();
+
+ /**
+ * @return A list of lines that will be printed by the help command when the user wishes to view them.
+ */
+ List getLongDesc();
+
+ /**
+ * @return A list of the names that can be accepted to have arguments passed to this command
+ */
+ List getNames();
+
+ /**
+ * @return {@code true} if this command should be hidden from the help menu
+ */
+ default boolean hiddenFromHelp() {
+ return false;
+ }
+}
diff --git a/src/api/java/baritone/api/command/argument/IArgConsumer.java b/src/api/java/baritone/api/command/argument/IArgConsumer.java
index 74967311..c9212fa4 100644
--- a/src/api/java/baritone/api/command/argument/IArgConsumer.java
+++ b/src/api/java/baritone/api/command/argument/IArgConsumer.java
@@ -17,7 +17,7 @@
package baritone.api.command.argument;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.exception.CommandTooManyArgumentsException;
import baritone.api.utils.Helper;
import baritone.api.command.argparser.IArgParser;
@@ -34,7 +34,7 @@ import java.util.LinkedList;
import java.util.stream.Stream;
/**
- * The {@link IArgConsumer} is how {@link Command}s read the arguments passed to them. This class has many benefits:
+ * The {@link IArgConsumer} is how {@link ICommand}s read the arguments passed to them. This class has many benefits:
*
*
* - Mutability. The whole concept of the {@link IArgConsumer}} is to let you gradually consume arguments in any way
diff --git a/src/api/java/baritone/api/command/exception/CommandNotFoundException.java b/src/api/java/baritone/api/command/exception/CommandNotFoundException.java
index 123661c8..49ac6977 100644
--- a/src/api/java/baritone/api/command/exception/CommandNotFoundException.java
+++ b/src/api/java/baritone/api/command/exception/CommandNotFoundException.java
@@ -17,7 +17,7 @@
package baritone.api.command.exception;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import java.util.List;
@@ -34,7 +34,7 @@ public class CommandNotFoundException extends CommandException {
}
@Override
- public void handle(Command command, List args) {
+ public void handle(ICommand command, List args) {
HELPER.logDirect(getMessage());
}
}
diff --git a/src/api/java/baritone/api/command/exception/CommandUnhandledException.java b/src/api/java/baritone/api/command/exception/CommandUnhandledException.java
index 394dd65e..fe0b09fa 100644
--- a/src/api/java/baritone/api/command/exception/CommandUnhandledException.java
+++ b/src/api/java/baritone/api/command/exception/CommandUnhandledException.java
@@ -17,7 +17,7 @@
package baritone.api.command.exception;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import net.minecraft.util.text.TextFormatting;
@@ -36,7 +36,7 @@ public class CommandUnhandledException extends RuntimeException implements IComm
}
@Override
- public void handle(Command command, List args) {
+ public void handle(ICommand command, List args) {
HELPER.logDirect("An unhandled exception occurred." +
"The error is in your game's log, please report this at https://github.com/cabaletta/baritone/issues",
TextFormatting.RED);
diff --git a/src/api/java/baritone/api/command/exception/ICommandException.java b/src/api/java/baritone/api/command/exception/ICommandException.java
index 3c96cb52..58d13049 100644
--- a/src/api/java/baritone/api/command/exception/ICommandException.java
+++ b/src/api/java/baritone/api/command/exception/ICommandException.java
@@ -17,7 +17,7 @@
package baritone.api.command.exception;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import net.minecraft.util.text.TextFormatting;
@@ -27,7 +27,7 @@ import static baritone.api.utils.Helper.HELPER;
/**
* The base for a Baritone Command Exception, checked or unchecked. Provides a
- * {@link #handle(Command, List)} method that is used to provide useful output
+ * {@link #handle(ICommand, List)} method that is used to provide useful output
* to the user for diagnosing issues that may have occurred during execution.
*
* Anything implementing this interface should be assignable to {@link Exception}.
@@ -49,7 +49,7 @@ public interface ICommandException {
* @param command The command that threw it.
* @param args The arguments the command was called with.
*/
- default void handle(Command command, List args) {
+ default void handle(ICommand command, List args) {
HELPER.logDirect(this.getMessage(), TextFormatting.RED);
}
}
diff --git a/src/api/java/baritone/api/command/manager/ICommandManager.java b/src/api/java/baritone/api/command/manager/ICommandManager.java
index f74a3c26..3f2d81f2 100644
--- a/src/api/java/baritone/api/command/manager/ICommandManager.java
+++ b/src/api/java/baritone/api/command/manager/ICommandManager.java
@@ -18,7 +18,7 @@
package baritone.api.command.manager;
import baritone.api.IBaritone;
-import baritone.api.command.Command;
+import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.registry.Registry;
import net.minecraft.util.Tuple;
@@ -34,13 +34,13 @@ public interface ICommandManager {
IBaritone getBaritone();
- Registry getRegistry();
+ Registry getRegistry();
/**
* @param name The command name to search for.
* @return The command, if found.
*/
- Command getCommand(String name);
+ ICommand getCommand(String name);
boolean execute(String string);
diff --git a/src/api/java/baritone/api/utils/Helper.java b/src/api/java/baritone/api/utils/Helper.java
index 91d7890f..994d8c7b 100755
--- a/src/api/java/baritone/api/utils/Helper.java
+++ b/src/api/java/baritone/api/utils/Helper.java
@@ -27,6 +27,9 @@ import java.util.Arrays;
import java.util.stream.Stream;
/**
+ * An ease-of-access interface to provide the {@link Minecraft} game instance,
+ * chat and console logging mechanisms, and the Baritone chat prefix.
+ *
* @author Brady
* @since 8/1/2018
*/
diff --git a/src/main/java/baritone/command/defaults/DefaultCommands.java b/src/main/java/baritone/command/defaults/DefaultCommands.java
index dd1a3004..c48644e3 100644
--- a/src/main/java/baritone/command/defaults/DefaultCommands.java
+++ b/src/main/java/baritone/command/defaults/DefaultCommands.java
@@ -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 createAll(IBaritone baritone) {
+ public static List createAll(IBaritone baritone) {
Objects.requireNonNull(baritone);
- List commands = new ArrayList<>(Arrays.asList(
+ List 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"),
diff --git a/src/main/java/baritone/command/defaults/HelpCommand.java b/src/main/java/baritone/command/defaults/HelpCommand.java
index c7e40e9f..4cb5f420 100644
--- a/src/main/java/baritone/command/defaults/HelpCommand.java
+++ b/src/main/java/baritone/command/defaults/HelpCommand.java
@@ -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);
}
diff --git a/src/main/java/baritone/command/manager/CommandManager.java b/src/main/java/baritone/command/manager/CommandManager.java
index 7b488871..aba434e3 100644
--- a/src/main/java/baritone/command/manager/CommandManager.java
+++ b/src/main/java/baritone/command/manager/CommandManager.java
@@ -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 registry = new Registry<>();
+ private final Registry registry = new Registry<>();
private final Baritone baritone;
public CommandManager(Baritone baritone) {
@@ -57,13 +57,13 @@ public class CommandManager implements ICommandManager {
}
@Override
- public Registry getRegistry() {
+ public Registry 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;