diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java index e31ef0f8e..b7228e33b 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 cd8fa5de3..4db5c0f3f 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.helpers.arguments.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 000000000..792de7c73 --- /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.argument.IArgConsumer; +import baritone.api.command.exception.CommandException; +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/argparser/IArgParserManager.java b/src/api/java/baritone/api/command/argparser/IArgParserManager.java index fe819150a..f38b4624d 100644 --- a/src/api/java/baritone/api/command/argparser/IArgParserManager.java +++ b/src/api/java/baritone/api/command/argparser/IArgParserManager.java @@ -22,6 +22,10 @@ import baritone.api.command.exception.CommandInvalidTypeException; import baritone.api.command.registry.Registry; /** + * Used to retrieve {@link IArgParser} instances from the registry, by their target class. + * It can be assumed that a {@link IArgParser} exists for {@link Integer}, {@link Long}, + * {@link Float}, {@link Double} and {@link Boolean}. + * * @author Brady * @since 10/4/2019 */ diff --git a/src/api/java/baritone/api/command/helpers/arguments/IArgConsumer.java b/src/api/java/baritone/api/command/argument/IArgConsumer.java similarity index 99% rename from src/api/java/baritone/api/command/helpers/arguments/IArgConsumer.java rename to src/api/java/baritone/api/command/argument/IArgConsumer.java index c185c1f7f..c9212fa41 100644 --- a/src/api/java/baritone/api/command/helpers/arguments/IArgConsumer.java +++ b/src/api/java/baritone/api/command/argument/IArgConsumer.java @@ -15,13 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.api.command.helpers.arguments; +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; -import baritone.api.command.argument.ICommandArgument; import baritone.api.command.datatypes.IDatatype; import baritone.api.command.datatypes.IDatatypeFor; import baritone.api.command.datatypes.IDatatypePost; @@ -35,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: * *