diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java index 8c5de47ab..64c4a2918 100644 --- a/src/api/java/baritone/api/IBaritone.java +++ b/src/api/java/baritone/api/IBaritone.java @@ -26,7 +26,7 @@ import baritone.api.process.*; import baritone.api.selection.ISelectionManager; import baritone.api.utils.IInputOverrideHandler; import baritone.api.utils.IPlayerContext; -import baritone.api.utils.command.manager.ICommandManager; +import baritone.api.command.manager.ICommandManager; /** * @author Brady diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java index bdefb66f1..e31ef0f8e 100644 --- a/src/api/java/baritone/api/IBaritoneProvider.java +++ b/src/api/java/baritone/api/IBaritoneProvider.java @@ -18,12 +18,15 @@ package baritone.api; import baritone.api.cache.IWorldScanner; +import baritone.api.command.Command; +import baritone.api.command.ICommandSystem; import net.minecraft.client.entity.EntityPlayerSP; import java.util.List; +import java.util.Objects; /** - * Provides the present {@link IBaritone} instances + * Provides the present {@link IBaritone} instances, as well as non-baritone instance related APIs. * * @author leijurv */ @@ -57,7 +60,7 @@ public interface IBaritoneProvider { */ default IBaritone getBaritoneForPlayer(EntityPlayerSP player) { for (IBaritone baritone : getAllBaritones()) { - if (player.equals(baritone.getPlayerContext().player())) { + if (Objects.equals(player, baritone.getPlayerContext().player())) { return baritone; } } @@ -71,4 +74,12 @@ public interface IBaritoneProvider { * @return The {@link IWorldScanner} instance. */ IWorldScanner getWorldScanner(); + + /** + * 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. + * + * @return The {@link ICommandSystem} instance. + */ + ICommandSystem getCommandSystem(); } diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index d1bb68679..dac5f23f6 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -802,6 +802,14 @@ public final class Settings { */ public final Setting mineScanDroppedItems = new Setting<>(true); + /** + * While mining, wait this number of milliseconds after mining an ore to see if it will drop an item + * instead of immediately going onto the next one + *

+ * Thanks Louca + */ + public final Setting mineDropLoiterDurationMSThanksLouca = new Setting<>(250L); + /** * Trim incorrect positions too far away, helps performance but hurts reliability in very large schematics */ diff --git a/src/api/java/baritone/api/utils/command/Command.java b/src/api/java/baritone/api/command/Command.java similarity index 56% rename from src/api/java/baritone/api/utils/command/Command.java rename to src/api/java/baritone/api/command/Command.java index e83d6c50b..cd8fa5de3 100644 --- a/src/api/java/baritone/api/utils/command/Command.java +++ b/src/api/java/baritone/api/command/Command.java @@ -15,14 +15,13 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command; +package baritone.api.command; import baritone.api.IBaritone; import baritone.api.utils.Helper; import baritone.api.utils.IPlayerContext; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.execution.ICommandExecution; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Collections; import java.util.List; @@ -38,60 +37,31 @@ public abstract class Command implements Helper { /** * The names of this command. This is what you put after the command prefix. */ - public final List names; + protected final List names; /** * Creates a new Baritone control command. * * @param names The names of this command. This is what you put after the command prefix. */ - protected Command(IBaritone baritone, List names) { - this.names = names.stream() + protected Command(IBaritone baritone, String... names) { + this.names = Collections.unmodifiableList(Stream.of(names) .map(s -> s.toLowerCase(Locale.US)) - .collect(Collectors.toList()); + .collect(Collectors.toList())); this.baritone = baritone; this.ctx = baritone.getPlayerContext(); } - protected Command(IBaritone baritone, String name) { - this(baritone, Collections.singletonList(name)); - } - - /** - * Executes this command with the specified arguments. - * - * @param execution The command execution to execute this command with - */ - public final void execute(ICommandExecution execution) throws CommandException { - this.executed(execution.getLabel(), execution.getArguments()); - } - - /** - * Tab completes this command with the specified arguments. Any exception that is thrown by - * {@link #tabCompleted(String, ArgConsumer)} will be caught by this method, and then {@link Stream#empty()} - * will be returned. - * - * @param execution The command execution to tab complete - * @return The list of completions. - */ - public final Stream tabComplete(ICommandExecution execution) { - try { - return this.tabCompleted(execution.getLabel(), execution.getArguments()); - } catch (Throwable t) { - return Stream.empty(); - } - } - /** * Called when this command is executed. */ - protected abstract void executed(String label, ArgConsumer args) throws CommandException; + 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. */ - protected abstract Stream tabCompleted(String label, ArgConsumer args) throws CommandException; + public abstract Stream tabComplete(String label, IArgConsumer args) throws CommandException; /** * @return A single-line string containing a short description of this command's purpose. @@ -109,4 +79,8 @@ public abstract class Command implements Helper { public boolean hiddenFromHelp() { return false; } + + public final List getNames() { + return this.names; + } } diff --git a/src/api/java/baritone/api/utils/command/IBaritoneChatControl.java b/src/api/java/baritone/api/command/IBaritoneChatControl.java similarity index 98% rename from src/api/java/baritone/api/utils/command/IBaritoneChatControl.java rename to src/api/java/baritone/api/command/IBaritoneChatControl.java index 63b6a4458..5009f3f02 100644 --- a/src/api/java/baritone/api/utils/command/IBaritoneChatControl.java +++ b/src/api/java/baritone/api/command/IBaritoneChatControl.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command; +package baritone.api.command; import baritone.api.Settings; diff --git a/src/api/java/baritone/api/command/ICommandSystem.java b/src/api/java/baritone/api/command/ICommandSystem.java new file mode 100644 index 000000000..98e8ed9c6 --- /dev/null +++ b/src/api/java/baritone/api/command/ICommandSystem.java @@ -0,0 +1,29 @@ +/* + * 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.argparser.IArgParserManager; + +/** + * @author Brady + * @since 10/4/2019 + */ +public interface ICommandSystem { + + IArgParserManager getParserManager(); +} diff --git a/src/api/java/baritone/api/utils/command/argparser/IArgParser.java b/src/api/java/baritone/api/command/argparser/IArgParser.java similarity index 81% rename from src/api/java/baritone/api/utils/command/argparser/IArgParser.java rename to src/api/java/baritone/api/command/argparser/IArgParser.java index 09e2aa2ea..868ad6963 100644 --- a/src/api/java/baritone/api/utils/command/argparser/IArgParser.java +++ b/src/api/java/baritone/api/command/argparser/IArgParser.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.argparser; +package baritone.api.command.argparser; -import baritone.api.utils.command.argument.CommandArgument; +import baritone.api.command.argument.ICommandArgument; public interface IArgParser { @@ -27,9 +27,7 @@ public interface IArgParser { Class getTarget(); /** - * A stateless argument parser is just that. It takes a {@link CommandArgument} and outputs its type. - * - * @see ArgParserManager#REGISTRY + * A stateless argument parser is just that. It takes a {@link ICommandArgument} and outputs its type. */ interface Stateless extends IArgParser { @@ -39,14 +37,12 @@ public interface IArgParser { * @throws RuntimeException if you want the parsing to fail. The exception will be caught and turned into an * appropriate error. */ - T parseArg(CommandArgument arg) throws Exception; + T parseArg(ICommandArgument arg) throws Exception; } /** - * A stated argument parser is similar to a stateless one. It also takes a {@link CommandArgument}, but it also + * A stated argument parser is similar to a stateless one. It also takes a {@link ICommandArgument}, but it also * takes a second argument that can be any type, referred to as the state. - * - * @see ArgParserManager#REGISTRY */ interface Stated extends IArgParser { @@ -59,6 +55,6 @@ public interface IArgParser { * @throws RuntimeException if you want the parsing to fail. The exception will be caught and turned into an * appropriate error. */ - T parseArg(CommandArgument arg, S state) throws Exception; + T parseArg(ICommandArgument arg, S state) throws Exception; } } diff --git a/src/api/java/baritone/api/command/argparser/IArgParserManager.java b/src/api/java/baritone/api/command/argparser/IArgParserManager.java new file mode 100644 index 000000000..fe819150a --- /dev/null +++ b/src/api/java/baritone/api/command/argparser/IArgParserManager.java @@ -0,0 +1,65 @@ +/* + * 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.argparser; + +import baritone.api.command.argument.ICommandArgument; +import baritone.api.command.exception.CommandInvalidTypeException; +import baritone.api.command.registry.Registry; + +/** + * @author Brady + * @since 10/4/2019 + */ +public interface IArgParserManager { + + /** + * @param type The type trying to be parsed + * @return A parser that can parse arguments into this class, if found. + */ + IArgParser.Stateless getParserStateless(Class type); + + /** + * @param type The type trying to be parsed + * @return A parser that can parse arguments into this class, if found. + */ + IArgParser.Stated getParserStated(Class type, Class stateKlass); + + /** + * Attempt to parse the specified argument with a stateless {@link IArgParser} that outputs the specified class. + * + * @param type The type to try and parse the argument into. + * @param arg The argument to parse. + * @return An instance of the specified class. + * @throws CommandInvalidTypeException If the parsing failed + */ + T parseStateless(Class type, ICommandArgument arg) throws CommandInvalidTypeException; + + /** + * Attempt to parse the specified argument with a stated {@link IArgParser} that outputs the specified class. + * + * @param type The type to try and parse the argument into. + * @param arg The argument to parse. + * @param state The state to pass to the {@link IArgParser.Stated}. + * @return An instance of the specified class. + * @throws CommandInvalidTypeException If the parsing failed + * @see IArgParser.Stated + */ + T parseStated(Class type, Class stateKlass, ICommandArgument arg, S state) throws CommandInvalidTypeException; + + Registry getRegistry(); +} diff --git a/src/api/java/baritone/api/command/argument/ICommandArgument.java b/src/api/java/baritone/api/command/argument/ICommandArgument.java new file mode 100644 index 000000000..ab912d00c --- /dev/null +++ b/src/api/java/baritone/api/command/argument/ICommandArgument.java @@ -0,0 +1,102 @@ +/* + * 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.argument; + +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.command.argparser.IArgParser; +import baritone.api.command.exception.CommandInvalidTypeException; +import net.minecraft.util.EnumFacing; + +/** + * A {@link ICommandArgument} is an immutable object representing one command argument. It contains data on the index of + * that argument, its value, and the rest of the string that argument was found in + *

+ * You're recommended to use {@link IArgConsumer}}s to handle these. + * + * @author Brady + * @since 10/2/2019 + */ +public interface ICommandArgument { + + /** + * @return The index of this command argument in the list of command arguments generated + */ + int getIndex(); + + /** + * @return The raw value of just this argument + */ + String getValue(); + + /** + * @return The raw value of the remaining arguments after this one was captured + */ + String getRawRest(); + + /** + * Gets an enum value from the enum class with the same name as this argument's value + *

+ * For example if you getEnum as an {@link EnumFacing}, and this argument's value is "up", it will return {@link + * EnumFacing#UP} + * + * @param enumClass The enum class to search + * @return An enum constant of that class with the same name as this argument's value + * @throws CommandInvalidTypeException If the constant couldn't be found + * @see IArgConsumer#peekEnum(Class) + * @see IArgConsumer#peekEnum(Class, int) + * @see IArgConsumer#peekEnumOrNull(Class) + * @see IArgConsumer#peekEnumOrNull(Class, int) + * @see IArgConsumer#getEnum(Class) + * @see IArgConsumer#getEnumOrNull(Class) + */ + > E getEnum(Class enumClass) throws CommandInvalidTypeException; + + /** + * Tries to use a stateless {@link IArgParser} to parse this argument into the specified class + * + * @param type The class to parse this argument into + * @return An instance of the specified type + * @throws CommandInvalidTypeException If the parsing failed + */ + T getAs(Class type) throws CommandInvalidTypeException; + + /** + * Tries to use a stateless {@link IArgParser} to parse this argument into the specified class + * + * @param type The class to parse this argument into + * @return If the parser succeeded + */ + boolean is(Class type); + + /** + * Tries to use a stated {@link IArgParser} to parse this argument into the specified class + * + * @param type The class to parse this argument into + * @return An instance of the specified type + * @throws CommandInvalidTypeException If the parsing failed + */ + T getAs(Class type, Class stateType, S state) throws CommandInvalidTypeException; + + /** + * Tries to use a stated {@link IArgParser} to parse this argument into the specified class + * + * @param type The class to parse this argument into + * @return If the parser succeeded + */ + boolean is(Class type, Class stateType, S state); +} diff --git a/src/api/java/baritone/api/utils/command/datatypes/BlockById.java b/src/api/java/baritone/api/command/datatypes/BlockById.java similarity index 90% rename from src/api/java/baritone/api/utils/command/datatypes/BlockById.java rename to src/api/java/baritone/api/command/datatypes/BlockById.java index 750ff545d..8f14380e2 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/BlockById.java +++ b/src/api/java/baritone/api/command/datatypes/BlockById.java @@ -15,10 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.exception.CommandException; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.util.ResourceLocation; diff --git a/src/api/java/baritone/api/utils/command/datatypes/EntityClassById.java b/src/api/java/baritone/api/command/datatypes/EntityClassById.java similarity index 90% rename from src/api/java/baritone/api/utils/command/datatypes/EntityClassById.java rename to src/api/java/baritone/api/command/datatypes/EntityClassById.java index 87e58e509..5bf7379ce 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/EntityClassById.java +++ b/src/api/java/baritone/api/command/datatypes/EntityClassById.java @@ -15,10 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import net.minecraft.entity.EntityType; import net.minecraft.util.ResourceLocation; import net.minecraft.util.registry.IRegistry; diff --git a/src/api/java/baritone/api/utils/command/datatypes/ForBlockOptionalMeta.java b/src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java similarity index 91% rename from src/api/java/baritone/api/utils/command/datatypes/ForBlockOptionalMeta.java rename to src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java index f36826c6c..29dc5f0b7 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/ForBlockOptionalMeta.java +++ b/src/api/java/baritone/api/command/datatypes/ForBlockOptionalMeta.java @@ -15,10 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; import baritone.api.utils.BlockOptionalMeta; -import baritone.api.utils.command.exception.CommandException; +import baritone.api.command.exception.CommandException; import java.util.stream.Stream; diff --git a/src/api/java/baritone/api/utils/command/datatypes/ForEnumFacing.java b/src/api/java/baritone/api/command/datatypes/ForEnumFacing.java similarity index 88% rename from src/api/java/baritone/api/utils/command/datatypes/ForEnumFacing.java rename to src/api/java/baritone/api/command/datatypes/ForEnumFacing.java index ed6dce31b..23f8617c1 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/ForEnumFacing.java +++ b/src/api/java/baritone/api/command/datatypes/ForEnumFacing.java @@ -15,10 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.exception.CommandException; import net.minecraft.util.EnumFacing; import java.util.Locale; diff --git a/src/api/java/baritone/api/utils/command/datatypes/ForWaypoints.java b/src/api/java/baritone/api/command/datatypes/ForWaypoints.java similarity index 94% rename from src/api/java/baritone/api/utils/command/datatypes/ForWaypoints.java rename to src/api/java/baritone/api/command/datatypes/ForWaypoints.java index e60ff0c6a..db5068392 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/ForWaypoints.java +++ b/src/api/java/baritone/api/command/datatypes/ForWaypoints.java @@ -15,13 +15,13 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; import baritone.api.IBaritone; import baritone.api.cache.IWaypoint; import baritone.api.cache.IWaypointCollection; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.exception.CommandException; import java.util.Comparator; import java.util.stream.Stream; diff --git a/src/api/java/baritone/api/utils/command/datatypes/IDatatype.java b/src/api/java/baritone/api/command/datatypes/IDatatype.java similarity index 87% rename from src/api/java/baritone/api/utils/command/datatypes/IDatatype.java rename to src/api/java/baritone/api/command/datatypes/IDatatype.java index 8c155fb68..385154bc4 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/IDatatype.java +++ b/src/api/java/baritone/api/command/datatypes/IDatatype.java @@ -15,11 +15,11 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; -import baritone.api.utils.command.argparser.IArgParser; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.argparser.IArgParser; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.command.exception.CommandException; import java.util.stream.Stream; @@ -41,7 +41,7 @@ import java.util.stream.Stream; public interface IDatatype { /** - * Attempts to complete missing or partial input provided through the {@link ArgConsumer} provided by + * Attempts to complete missing or partial input provided through the {@link IArgConsumer}} provided by * {@link IDatatypeContext#getConsumer()} in order to aide the user in executing commands. *

* One benefit over datatypes over {@link IArgParser}s is that instead of each command trying to guess what values @@ -50,7 +50,7 @@ public interface IDatatype { * * @param ctx The argument consumer to tab complete * @return A stream representing the strings that can be tab completed. DO NOT INCLUDE SPACES IN ANY STRINGS. - * @see ArgConsumer#tabCompleteDatatype(IDatatype) + * @see IArgConsumer#tabCompleteDatatype(IDatatype) */ Stream tabComplete(IDatatypeContext ctx) throws CommandException; } diff --git a/src/api/java/baritone/api/utils/command/datatypes/IDatatypeContext.java b/src/api/java/baritone/api/command/datatypes/IDatatypeContext.java similarity index 82% rename from src/api/java/baritone/api/utils/command/datatypes/IDatatypeContext.java rename to src/api/java/baritone/api/command/datatypes/IDatatypeContext.java index 1452bf4ab..4b8269c3c 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/IDatatypeContext.java +++ b/src/api/java/baritone/api/command/datatypes/IDatatypeContext.java @@ -15,10 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; import baritone.api.IBaritone; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.helpers.arguments.IArgConsumer; /** * Provides an {@link IDatatype} with contextual information so @@ -39,9 +39,9 @@ public interface IDatatypeContext { IBaritone getBaritone(); /** - * Provides the {@link ArgConsumer} to fetch input information from. + * Provides the {@link IArgConsumer}} to fetch input information from. * - * @return The context {@link ArgConsumer}. + * @return The context {@link IArgConsumer}}. */ - ArgConsumer getConsumer(); + IArgConsumer getConsumer(); } diff --git a/src/api/java/baritone/api/utils/command/datatypes/IDatatypeFor.java b/src/api/java/baritone/api/command/datatypes/IDatatypeFor.java similarity index 94% rename from src/api/java/baritone/api/utils/command/datatypes/IDatatypeFor.java rename to src/api/java/baritone/api/command/datatypes/IDatatypeFor.java index 4f0f42006..2f0a9c140 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/IDatatypeFor.java +++ b/src/api/java/baritone/api/command/datatypes/IDatatypeFor.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; -import baritone.api.utils.command.exception.CommandException; +import baritone.api.command.exception.CommandException; import java.util.function.Supplier; diff --git a/src/api/java/baritone/api/utils/command/datatypes/IDatatypePost.java b/src/api/java/baritone/api/command/datatypes/IDatatypePost.java similarity index 93% rename from src/api/java/baritone/api/utils/command/datatypes/IDatatypePost.java rename to src/api/java/baritone/api/command/datatypes/IDatatypePost.java index 2e4cc47af..aa5b261da 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/IDatatypePost.java +++ b/src/api/java/baritone/api/command/datatypes/IDatatypePost.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; -import baritone.api.utils.command.exception.CommandException; +import baritone.api.command.exception.CommandException; import java.util.function.Function; diff --git a/src/api/java/baritone/api/utils/command/datatypes/IDatatypePostFunction.java b/src/api/java/baritone/api/command/datatypes/IDatatypePostFunction.java similarity index 88% rename from src/api/java/baritone/api/utils/command/datatypes/IDatatypePostFunction.java rename to src/api/java/baritone/api/command/datatypes/IDatatypePostFunction.java index a3de089e0..fe79d6a6d 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/IDatatypePostFunction.java +++ b/src/api/java/baritone/api/command/datatypes/IDatatypePostFunction.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; -import baritone.api.utils.command.exception.CommandException; +import baritone.api.command.exception.CommandException; /** * @author Brady diff --git a/src/api/java/baritone/api/utils/command/datatypes/NearbyPlayer.java b/src/api/java/baritone/api/command/datatypes/NearbyPlayer.java similarity index 91% rename from src/api/java/baritone/api/utils/command/datatypes/NearbyPlayer.java rename to src/api/java/baritone/api/command/datatypes/NearbyPlayer.java index 4b91453d2..8fcb6354b 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/NearbyPlayer.java +++ b/src/api/java/baritone/api/command/datatypes/NearbyPlayer.java @@ -15,11 +15,11 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; import baritone.api.IBaritone; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.exception.CommandException; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.text.ITextComponent; diff --git a/src/api/java/baritone/api/utils/command/datatypes/RelativeBlockPos.java b/src/api/java/baritone/api/command/datatypes/RelativeBlockPos.java similarity index 86% rename from src/api/java/baritone/api/utils/command/datatypes/RelativeBlockPos.java rename to src/api/java/baritone/api/command/datatypes/RelativeBlockPos.java index 8459db88d..513ef41f3 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/RelativeBlockPos.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeBlockPos.java @@ -15,11 +15,11 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; +import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.exception.CommandException; import java.util.stream.Stream; @@ -32,7 +32,7 @@ public enum RelativeBlockPos implements IDatatypePost tabComplete(IDatatypeContext ctx) throws CommandException { - final ArgConsumer consumer = ctx.getConsumer(); + final IArgConsumer consumer = ctx.getConsumer(); if (consumer.hasAny() && !consumer.has(4)) { while (consumer.has(2)) { if (consumer.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) == null) { diff --git a/src/api/java/baritone/api/utils/command/datatypes/RelativeCoordinate.java b/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java similarity index 82% rename from src/api/java/baritone/api/utils/command/datatypes/RelativeCoordinate.java rename to src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java index 84a29f63d..dc4d56304 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/RelativeCoordinate.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java @@ -15,10 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.command.exception.CommandException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -26,8 +26,7 @@ import java.util.stream.Stream; public enum RelativeCoordinate implements IDatatypePost { INSTANCE; - - private static Pattern PATTERN = Pattern.compile("^(~?)([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)|)$"); + private static Pattern PATTERN = Pattern.compile("^(~?)([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)([k-k]?)|)$"); @Override public Double apply(IDatatypeContext ctx, Double origin) throws CommandException { @@ -41,7 +40,12 @@ public enum RelativeCoordinate implements IDatatypePost { } boolean isRelative = !matcher.group(1).isEmpty(); - double offset = matcher.group(2).isEmpty() ? 0 : Double.parseDouble(matcher.group(2)); + + double offset = matcher.group(2).isEmpty() ? 0 : Double.parseDouble(matcher.group(2).replaceAll("k", "")); + + if (matcher.group(2).contains("k")) { + offset *= 1000; + } if (isRelative) { return origin + offset; @@ -51,7 +55,7 @@ public enum RelativeCoordinate implements IDatatypePost { @Override public Stream tabComplete(IDatatypeContext ctx) throws CommandException { - final ArgConsumer consumer = ctx.getConsumer(); + final IArgConsumer consumer = ctx.getConsumer(); if (!consumer.has(2) && consumer.getString().matches("^(~|$)")) { return Stream.of("~"); } diff --git a/src/api/java/baritone/api/utils/command/datatypes/RelativeFile.java b/src/api/java/baritone/api/command/datatypes/RelativeFile.java similarity index 92% rename from src/api/java/baritone/api/utils/command/datatypes/RelativeFile.java rename to src/api/java/baritone/api/command/datatypes/RelativeFile.java index 71a9ca58c..f886a1c65 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/RelativeFile.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeFile.java @@ -15,10 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.command.exception.CommandException; import java.io.File; import java.io.IOException; @@ -70,7 +70,7 @@ public enum RelativeFile implements IDatatypePost { } } - public static Stream tabComplete(ArgConsumer consumer, File base0) throws CommandException { + public static Stream tabComplete(IArgConsumer consumer, File base0) throws CommandException { // I will not make the caller deal with this, seriously // Tab complete code is beautiful and I'm not going to bloat it with dumb ass checked exception bullshit -LoganDark diff --git a/src/api/java/baritone/api/utils/command/datatypes/RelativeGoal.java b/src/api/java/baritone/api/command/datatypes/RelativeGoal.java similarity index 89% rename from src/api/java/baritone/api/utils/command/datatypes/RelativeGoal.java rename to src/api/java/baritone/api/command/datatypes/RelativeGoal.java index d47e05ce4..73bc6e0d3 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/RelativeGoal.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeGoal.java @@ -15,15 +15,15 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; +import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalBlock; import baritone.api.pathing.goals.GoalXZ; import baritone.api.pathing.goals.GoalYLevel; import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.exception.CommandException; import net.minecraft.util.math.MathHelper; import java.util.ArrayList; @@ -38,10 +38,10 @@ public enum RelativeGoal implements IDatatypePost { if (origin == null) { origin = BetterBlockPos.ORIGIN; } - final ArgConsumer consumer = ctx.getConsumer(); + final IArgConsumer consumer = ctx.getConsumer(); List> coords = new ArrayList<>(); - final ArgConsumer copy = consumer.copy(); // This is a hack and should be fixed in the future probably + final IArgConsumer copy = consumer.copy(); // This is a hack and should be fixed in the future probably for (int i = 0; i < 3; i++) { if (copy.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) { coords.add(o -> consumer.getDatatypePost(RelativeCoordinate.INSTANCE, o)); diff --git a/src/api/java/baritone/api/utils/command/datatypes/RelativeGoalBlock.java b/src/api/java/baritone/api/command/datatypes/RelativeGoalBlock.java similarity index 86% rename from src/api/java/baritone/api/utils/command/datatypes/RelativeGoalBlock.java rename to src/api/java/baritone/api/command/datatypes/RelativeGoalBlock.java index cd1c0be10..19621b952 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/RelativeGoalBlock.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeGoalBlock.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; +import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.pathing.goals.GoalBlock; import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.exception.CommandException; import net.minecraft.util.math.MathHelper; import java.util.stream.Stream; @@ -34,7 +34,7 @@ public enum RelativeGoalBlock implements IDatatypePost tabComplete(IDatatypeContext ctx) { - final ArgConsumer consumer = ctx.getConsumer(); + final IArgConsumer consumer = ctx.getConsumer(); if (consumer.hasAtMost(3)) { return consumer.tabCompleteDatatype(RelativeCoordinate.INSTANCE); } diff --git a/src/api/java/baritone/api/utils/command/datatypes/RelativeGoalXZ.java b/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java similarity index 85% rename from src/api/java/baritone/api/utils/command/datatypes/RelativeGoalXZ.java rename to src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java index b8bd0cd62..83d52de86 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/RelativeGoalXZ.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; +import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.pathing.goals.GoalXZ; import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.exception.CommandException; import net.minecraft.util.math.MathHelper; import java.util.stream.Stream; @@ -34,7 +34,7 @@ public enum RelativeGoalXZ implements IDatatypePost { origin = BetterBlockPos.ORIGIN; } - final ArgConsumer consumer = ctx.getConsumer(); + final IArgConsumer consumer = ctx.getConsumer(); return new GoalXZ( MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.x)), MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.y)) @@ -43,7 +43,7 @@ public enum RelativeGoalXZ implements IDatatypePost { @Override public Stream tabComplete(IDatatypeContext ctx) { - final ArgConsumer consumer = ctx.getConsumer(); + final IArgConsumer consumer = ctx.getConsumer(); if (consumer.hasAtMost(2)) { return consumer.tabCompleteDatatype(RelativeCoordinate.INSTANCE); } diff --git a/src/api/java/baritone/api/utils/command/datatypes/RelativeGoalYLevel.java b/src/api/java/baritone/api/command/datatypes/RelativeGoalYLevel.java similarity index 87% rename from src/api/java/baritone/api/utils/command/datatypes/RelativeGoalYLevel.java rename to src/api/java/baritone/api/command/datatypes/RelativeGoalYLevel.java index a8a9b232e..4dd195a4d 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/RelativeGoalYLevel.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeGoalYLevel.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.datatypes; +package baritone.api.command.datatypes; +import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.api.pathing.goals.GoalYLevel; import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.exception.CommandException; import net.minecraft.util.math.MathHelper; import java.util.stream.Stream; @@ -41,7 +41,7 @@ public enum RelativeGoalYLevel implements IDatatypePost tabComplete(IDatatypeContext ctx) { - final ArgConsumer consumer = ctx.getConsumer(); + final IArgConsumer consumer = ctx.getConsumer(); if (consumer.hasAtMost(1)) { return consumer.tabCompleteDatatype(RelativeCoordinate.INSTANCE); } diff --git a/src/api/java/baritone/api/utils/command/exception/CommandErrorMessageException.java b/src/api/java/baritone/api/command/exception/CommandErrorMessageException.java similarity index 94% rename from src/api/java/baritone/api/utils/command/exception/CommandErrorMessageException.java rename to src/api/java/baritone/api/command/exception/CommandErrorMessageException.java index 002d328e1..4a21bede7 100644 --- a/src/api/java/baritone/api/utils/command/exception/CommandErrorMessageException.java +++ b/src/api/java/baritone/api/command/exception/CommandErrorMessageException.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.exception; +package baritone.api.command.exception; public abstract class CommandErrorMessageException extends CommandException { diff --git a/src/api/java/baritone/api/utils/command/exception/CommandException.java b/src/api/java/baritone/api/command/exception/CommandException.java similarity index 94% rename from src/api/java/baritone/api/utils/command/exception/CommandException.java rename to src/api/java/baritone/api/command/exception/CommandException.java index 9fdc3f735..b8962c159 100644 --- a/src/api/java/baritone/api/utils/command/exception/CommandException.java +++ b/src/api/java/baritone/api/command/exception/CommandException.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.exception; +package baritone.api.command.exception; public abstract class CommandException extends Exception implements ICommandException { diff --git a/src/api/java/baritone/api/utils/command/exception/CommandInvalidArgumentException.java b/src/api/java/baritone/api/command/exception/CommandInvalidArgumentException.java similarity index 75% rename from src/api/java/baritone/api/utils/command/exception/CommandInvalidArgumentException.java rename to src/api/java/baritone/api/command/exception/CommandInvalidArgumentException.java index 627067051..1902d7355 100644 --- a/src/api/java/baritone/api/utils/command/exception/CommandInvalidArgumentException.java +++ b/src/api/java/baritone/api/command/exception/CommandInvalidArgumentException.java @@ -15,18 +15,18 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.exception; +package baritone.api.command.exception; -import baritone.api.utils.command.argument.CommandArgument; +import baritone.api.command.argument.ICommandArgument; public abstract class CommandInvalidArgumentException extends CommandErrorMessageException { - public final CommandArgument arg; + public final ICommandArgument arg; - protected CommandInvalidArgumentException(CommandArgument arg, String reason) { + protected CommandInvalidArgumentException(ICommandArgument arg, String reason) { super(String.format( "Error at argument #%s: %s", - arg.index == -1 ? "" : Integer.toString(arg.index + 1), + arg.getIndex() == -1 ? "" : Integer.toString(arg.getIndex() + 1), reason )); this.arg = arg; diff --git a/src/api/java/baritone/api/utils/command/exception/CommandInvalidStateException.java b/src/api/java/baritone/api/command/exception/CommandInvalidStateException.java similarity index 94% rename from src/api/java/baritone/api/utils/command/exception/CommandInvalidStateException.java rename to src/api/java/baritone/api/command/exception/CommandInvalidStateException.java index 4e00c1f7f..0fa22fcbb 100644 --- a/src/api/java/baritone/api/utils/command/exception/CommandInvalidStateException.java +++ b/src/api/java/baritone/api/command/exception/CommandInvalidStateException.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.exception; +package baritone.api.command.exception; public class CommandInvalidStateException extends CommandErrorMessageException { diff --git a/src/api/java/baritone/api/utils/command/exception/CommandInvalidTypeException.java b/src/api/java/baritone/api/command/exception/CommandInvalidTypeException.java similarity index 71% rename from src/api/java/baritone/api/utils/command/exception/CommandInvalidTypeException.java rename to src/api/java/baritone/api/command/exception/CommandInvalidTypeException.java index 5e5b81cdd..516fd308f 100644 --- a/src/api/java/baritone/api/utils/command/exception/CommandInvalidTypeException.java +++ b/src/api/java/baritone/api/command/exception/CommandInvalidTypeException.java @@ -15,25 +15,25 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.exception; +package baritone.api.command.exception; -import baritone.api.utils.command.argument.CommandArgument; +import baritone.api.command.argument.ICommandArgument; public class CommandInvalidTypeException extends CommandInvalidArgumentException { - public CommandInvalidTypeException(CommandArgument arg, String expected) { + public CommandInvalidTypeException(ICommandArgument arg, String expected) { super(arg, String.format("Expected %s", expected)); } - public CommandInvalidTypeException(CommandArgument arg, String expected, Throwable cause) { + public CommandInvalidTypeException(ICommandArgument arg, String expected, Throwable cause) { super(arg, String.format("Expected %s.\nMore details: %s", expected, cause.getMessage())); } - public CommandInvalidTypeException(CommandArgument arg, String expected, String got) { + public CommandInvalidTypeException(ICommandArgument arg, String expected, String got) { super(arg, String.format("Expected %s, but got %s instead", expected, got)); } - public CommandInvalidTypeException(CommandArgument arg, String expected, String got, Throwable cause) { + public CommandInvalidTypeException(ICommandArgument arg, String expected, String got, Throwable cause) { super(arg, String.format("Expected %s, but got %s instead.\nMore details: %s", expected, got, cause.getMessage())); } } diff --git a/src/api/java/baritone/api/utils/command/exception/CommandNoParserForTypeException.java b/src/api/java/baritone/api/command/exception/CommandNoParserForTypeException.java similarity index 95% rename from src/api/java/baritone/api/utils/command/exception/CommandNoParserForTypeException.java rename to src/api/java/baritone/api/command/exception/CommandNoParserForTypeException.java index f4f2d8181..4bf7a1ac7 100644 --- a/src/api/java/baritone/api/utils/command/exception/CommandNoParserForTypeException.java +++ b/src/api/java/baritone/api/command/exception/CommandNoParserForTypeException.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.exception; +package baritone.api.command.exception; public class CommandNoParserForTypeException extends CommandUnhandledException { diff --git a/src/api/java/baritone/api/utils/command/exception/CommandNotEnoughArgumentsException.java b/src/api/java/baritone/api/command/exception/CommandNotEnoughArgumentsException.java similarity index 95% rename from src/api/java/baritone/api/utils/command/exception/CommandNotEnoughArgumentsException.java rename to src/api/java/baritone/api/command/exception/CommandNotEnoughArgumentsException.java index 655652d6c..e2e05cfbf 100644 --- a/src/api/java/baritone/api/utils/command/exception/CommandNotEnoughArgumentsException.java +++ b/src/api/java/baritone/api/command/exception/CommandNotEnoughArgumentsException.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.exception; +package baritone.api.command.exception; public class CommandNotEnoughArgumentsException extends CommandErrorMessageException { diff --git a/src/api/java/baritone/api/utils/command/exception/CommandNotFoundException.java b/src/api/java/baritone/api/command/exception/CommandNotFoundException.java similarity index 83% rename from src/api/java/baritone/api/utils/command/exception/CommandNotFoundException.java rename to src/api/java/baritone/api/command/exception/CommandNotFoundException.java index e8904cbc8..123661c83 100644 --- a/src/api/java/baritone/api/utils/command/exception/CommandNotFoundException.java +++ b/src/api/java/baritone/api/command/exception/CommandNotFoundException.java @@ -15,10 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.exception; +package baritone.api.command.exception; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.argument.CommandArgument; +import baritone.api.command.Command; +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(Command command, List args) { HELPER.logDirect(getMessage()); } } diff --git a/src/api/java/baritone/api/utils/command/exception/CommandTooManyArgumentsException.java b/src/api/java/baritone/api/command/exception/CommandTooManyArgumentsException.java similarity index 95% rename from src/api/java/baritone/api/utils/command/exception/CommandTooManyArgumentsException.java rename to src/api/java/baritone/api/command/exception/CommandTooManyArgumentsException.java index 24fc799fe..9aec48ea9 100644 --- a/src/api/java/baritone/api/utils/command/exception/CommandTooManyArgumentsException.java +++ b/src/api/java/baritone/api/command/exception/CommandTooManyArgumentsException.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.exception; +package baritone.api.command.exception; public class CommandTooManyArgumentsException extends CommandErrorMessageException { diff --git a/src/api/java/baritone/api/utils/command/exception/CommandUnhandledException.java b/src/api/java/baritone/api/command/exception/CommandUnhandledException.java similarity index 86% rename from src/api/java/baritone/api/utils/command/exception/CommandUnhandledException.java rename to src/api/java/baritone/api/command/exception/CommandUnhandledException.java index 6d647a201..394dd65e9 100644 --- a/src/api/java/baritone/api/utils/command/exception/CommandUnhandledException.java +++ b/src/api/java/baritone/api/command/exception/CommandUnhandledException.java @@ -15,10 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.exception; +package baritone.api.command.exception; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.argument.CommandArgument; +import baritone.api.command.Command; +import baritone.api.command.argument.ICommandArgument; import net.minecraft.util.text.TextFormatting; import java.util.List; @@ -36,7 +36,7 @@ public class CommandUnhandledException extends RuntimeException implements IComm } @Override - public void handle(Command command, List args) { + public void handle(Command 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/utils/command/exception/ICommandException.java b/src/api/java/baritone/api/command/exception/ICommandException.java similarity index 88% rename from src/api/java/baritone/api/utils/command/exception/ICommandException.java rename to src/api/java/baritone/api/command/exception/ICommandException.java index 379e97b7f..3c96cb520 100644 --- a/src/api/java/baritone/api/utils/command/exception/ICommandException.java +++ b/src/api/java/baritone/api/command/exception/ICommandException.java @@ -15,10 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.exception; +package baritone.api.command.exception; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.argument.CommandArgument; +import baritone.api.command.Command; +import baritone.api.command.argument.ICommandArgument; import net.minecraft.util.text.TextFormatting; import java.util.List; @@ -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(Command command, List args) { HELPER.logDirect(this.getMessage(), TextFormatting.RED); } } diff --git a/src/api/java/baritone/api/utils/command/helpers/arguments/ArgConsumer.java b/src/api/java/baritone/api/command/helpers/arguments/IArgConsumer.java similarity index 56% rename from src/api/java/baritone/api/utils/command/helpers/arguments/ArgConsumer.java rename to src/api/java/baritone/api/command/helpers/arguments/IArgConsumer.java index e92855d1d..c185c1f7f 100644 --- a/src/api/java/baritone/api/utils/command/helpers/arguments/ArgConsumer.java +++ b/src/api/java/baritone/api/command/helpers/arguments/IArgConsumer.java @@ -15,173 +15,120 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.helpers.arguments; +package baritone.api.command.helpers.arguments; -import baritone.api.IBaritone; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandTooManyArgumentsException; import baritone.api.utils.Helper; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.argparser.IArgParser; -import baritone.api.utils.command.argument.CommandArgument; -import baritone.api.utils.command.datatypes.IDatatype; -import baritone.api.utils.command.datatypes.IDatatypeContext; -import baritone.api.utils.command.datatypes.IDatatypeFor; -import baritone.api.utils.command.datatypes.IDatatypePost; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidTypeException; -import baritone.api.utils.command.exception.CommandNotEnoughArgumentsException; -import baritone.api.utils.command.exception.CommandTooManyArgumentsException; -import baritone.api.utils.command.manager.ICommandManager; +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; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidTypeException; +import baritone.api.command.exception.CommandNotEnoughArgumentsException; import net.minecraft.util.EnumFacing; -import java.util.ArrayList; import java.util.Deque; import java.util.LinkedList; -import java.util.List; import java.util.stream.Stream; /** - * The {@link ArgConsumer} is how {@link Command}s read the arguments passed to them. This class has many benefits: + * The {@link IArgConsumer} is how {@link Command}s read the arguments passed to them. This class has many benefits: * *

*/ -public class ArgConsumer { +public interface IArgConsumer { - /** - * The parent {@link ICommandManager} for this {@link ArgConsumer}. Used by {@link #context}. - */ - private final ICommandManager manager; + LinkedList getArgs(); - /** - * The {@link IDatatypeContext} instance for this {@link ArgConsumer}, passed to - * datatypes when an operation is performed upon them. - * - * @see IDatatype - * @see IDatatypeContext - */ - private final IDatatypeContext context; - - /** - * The list of arguments in this ArgConsumer - */ - public final LinkedList args; - - /** - * The list of consumed arguments for this ArgConsumer. The most recently consumed argument is the last one - */ - public final Deque consumed; - - private ArgConsumer(ICommandManager manager, Deque args, Deque consumed) { - this.manager = manager; - this.context = this.new Context(); - this.args = new LinkedList<>(args); - this.consumed = new LinkedList<>(consumed); - } - - public ArgConsumer(ICommandManager manager, List args) { - this(manager, new LinkedList<>(args), new LinkedList<>()); - } + Deque getConsumed(); /** * @param num The number of arguments to check for - * @return {@code true} if there are at least {@code num} arguments left in this {@link ArgConsumer} + * @return {@code true} if there are at least {@code num} arguments left in this {@link IArgConsumer}} * @see #hasAny() * @see #hasAtMost(int) * @see #hasExactly(int) */ - public boolean has(int num) { - return args.size() >= num; - } + boolean has(int num); /** - * @return {@code true} if there is at least 1 argument left in this {@link ArgConsumer} + * @return {@code true} if there is at least 1 argument left in this {@link IArgConsumer}} * @see #has(int) * @see #hasAtMostOne() * @see #hasExactlyOne() */ - public boolean hasAny() { - return has(1); - } + boolean hasAny(); /** * @param num The number of arguments to check for - * @return {@code true} if there are at most {@code num} arguments left in this {@link ArgConsumer} + * @return {@code true} if there are at most {@code num} arguments left in this {@link IArgConsumer}} * @see #has(int) * @see #hasAtMost(int) * @see #hasExactly(int) */ - public boolean hasAtMost(int num) { - return args.size() <= num; - } + boolean hasAtMost(int num); /** - * @return {@code true} if there is at most 1 argument left in this {@link ArgConsumer} + * @return {@code true} if there is at most 1 argument left in this {@link IArgConsumer}} * @see #hasAny() * @see #hasAtMostOne() * @see #hasExactlyOne() */ - public boolean hasAtMostOne() { - return hasAtMost(1); - } + boolean hasAtMostOne(); /** * @param num The number of arguments to check for - * @return {@code true} if there are exactly {@code num} arguments left in this {@link ArgConsumer} + * @return {@code true} if there are exactly {@code num} arguments left in this {@link IArgConsumer}} * @see #has(int) * @see #hasAtMost(int) */ - public boolean hasExactly(int num) { - return args.size() == num; - } + boolean hasExactly(int num); /** - * @return {@code true} if there is exactly 1 argument left in this {@link ArgConsumer} + * @return {@code true} if there is exactly 1 argument left in this {@link IArgConsumer}} * @see #hasAny() * @see #hasAtMostOne() */ - public boolean hasExactlyOne() { - return hasExactly(1); - } + boolean hasExactlyOne(); /** * @param index The index to peek - * @return The argument at index {@code index} in this {@link ArgConsumer}, with 0 being the next one. This does not - * mutate the {@link ArgConsumer} + * @return The argument at index {@code index} in this {@link IArgConsumer}}, with 0 being the next one. This does not + * mutate the {@link IArgConsumer}} * @throws CommandNotEnoughArgumentsException If there is less than {@code index + 1} arguments left * @see #peek() * @see #peekString(int) * @see #peekAs(Class, int) * @see #get() */ - public CommandArgument peek(int index) throws CommandNotEnoughArgumentsException { - requireMin(index + 1); - return args.get(index); - } + ICommandArgument peek(int index) throws CommandNotEnoughArgumentsException; /** - * @return The next argument in this {@link ArgConsumer}. This does not mutate the {@link ArgConsumer} + * @return The next argument in this {@link IArgConsumer}}. This does not mutate the {@link IArgConsumer}} * @throws CommandNotEnoughArgumentsException If there is less than one argument left * @see #peek(int) * @see #peekString() * @see #peekAs(Class) * @see #get() */ - public CommandArgument peek() throws CommandNotEnoughArgumentsException { - return peek(0); - } + ICommandArgument peek() throws CommandNotEnoughArgumentsException; /** * @param index The index to peek @@ -192,9 +139,7 @@ public class ArgConsumer { * @see #peek() * @see #getAs(Class) */ - public boolean is(Class type, int index) throws CommandNotEnoughArgumentsException { - return peek(index).is(type); - } + boolean is(Class type, int index) throws CommandNotEnoughArgumentsException; /** * @param type The type to check for @@ -204,31 +149,25 @@ public class ArgConsumer { * @see #peek() * @see #getAs(Class) */ - public boolean is(Class type) throws CommandNotEnoughArgumentsException { - return is(type, 0); - } + boolean is(Class type) throws CommandNotEnoughArgumentsException; /** * @param index The index to peek - * @return The value of the argument at index {@code index} in this {@link ArgConsumer}, with 0 being the next one - * This does not mutate the {@link ArgConsumer} + * @return The value of the argument at index {@code index} in this {@link IArgConsumer}}, with 0 being the next one + * This does not mutate the {@link IArgConsumer}} * @throws CommandNotEnoughArgumentsException If there is less than {@code index + 1} arguments left * @see #peek() * @see #peekString() */ - public String peekString(int index) throws CommandNotEnoughArgumentsException { - return peek(index).value; - } + String peekString(int index) throws CommandNotEnoughArgumentsException; /** - * @return The value of the next argument in this {@link ArgConsumer}. This does not mutate the {@link ArgConsumer} + * @return The value of the next argument in this {@link IArgConsumer}}. This does not mutate the {@link IArgConsumer}} * @throws CommandNotEnoughArgumentsException If there is less than one argument left * @see #peekString(int) * @see #getString() */ - public String peekString() throws CommandNotEnoughArgumentsException { - return peekString(0); - } + String peekString() throws CommandNotEnoughArgumentsException; /** * @param index The index to peek @@ -238,11 +177,9 @@ public class ArgConsumer { * @throws java.util.NoSuchElementException If the constant couldn't be found * @see #peekEnumOrNull(Class) * @see #getEnum(Class) - * @see CommandArgument#getEnum(Class) + * @see ICommandArgument#getEnum(Class) */ - public > E peekEnum(Class enumClass, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { - return peek(index).getEnum(enumClass); - } + > E peekEnum(Class enumClass, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; /** * @param enumClass The class to search @@ -251,11 +188,9 @@ public class ArgConsumer { * @throws CommandInvalidTypeException If the constant couldn't be found * @see #peekEnumOrNull(Class) * @see #getEnum(Class) - * @see CommandArgument#getEnum(Class) + * @see ICommandArgument#getEnum(Class) */ - public > E peekEnum(Class enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { - return peekEnum(enumClass, 0); - } + > E peekEnum(Class enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; /** * @param index The index to peek @@ -264,15 +199,9 @@ public class ArgConsumer { * next argument's value. If no constant could be found, null * @see #peekEnum(Class) * @see #getEnumOrNull(Class) - * @see CommandArgument#getEnum(Class) + * @see ICommandArgument#getEnum(Class) */ - public > E peekEnumOrNull(Class enumClass, int index) throws CommandNotEnoughArgumentsException { - try { - return peekEnum(enumClass, index); - } catch (CommandInvalidTypeException e) { - return null; - } - } + > E peekEnumOrNull(Class enumClass, int index) throws CommandNotEnoughArgumentsException; /** * @param enumClass The class to search @@ -280,11 +209,9 @@ public class ArgConsumer { * next argument's value. If no constant could be found, null * @see #peekEnum(Class) * @see #getEnumOrNull(Class) - * @see CommandArgument#getEnum(Class) + * @see ICommandArgument#getEnum(Class) */ - public > E peekEnumOrNull(Class enumClass) throws CommandNotEnoughArgumentsException { - return peekEnumOrNull(enumClass, 0); - } + > E peekEnumOrNull(Class enumClass) throws CommandNotEnoughArgumentsException; /** * Tries to use a stateless {@link IArgParser} to parse the argument at the specified index into the specified @@ -292,7 +219,7 @@ public class ArgConsumer { *

* A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire - * {@link ArgConsumer}. + * {@link IArgConsumer}}. * * @param type The type to peek as * @param index The index to peek @@ -303,16 +230,14 @@ public class ArgConsumer { * @see #peekAsOrDefault(Class, Object, int) * @see #peekAsOrNull(Class, int) */ - public T peekAs(Class type, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { - return peek(index).getAs(type); - } + T peekAs(Class type, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; /** * Tries to use a stateless {@link IArgParser} to parse the next argument into the specified class *

* A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire - * {@link ArgConsumer}. + * {@link IArgConsumer}}. * * @param type The type to peek as * @return An instance of the specified type @@ -322,9 +247,7 @@ public class ArgConsumer { * @see #peekAsOrDefault(Class, Object) * @see #peekAsOrNull(Class) */ - public T peekAs(Class type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { - return peekAs(type, 0); - } + T peekAs(Class type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; /** * Tries to use a stateless {@link IArgParser} to parse the argument at the specified index into the specified @@ -332,7 +255,7 @@ public class ArgConsumer { *

* A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire - * {@link ArgConsumer}. + * {@link IArgConsumer}}. * * @param type The type to peek as * @param def The value to return if the argument can't be parsed @@ -343,20 +266,14 @@ public class ArgConsumer { * @see #peekAs(Class, int) * @see #peekAsOrNull(Class, int) */ - public T peekAsOrDefault(Class type, T def, int index) throws CommandNotEnoughArgumentsException { - try { - return peekAs(type, index); - } catch (CommandInvalidTypeException e) { - return def; - } - } + T peekAsOrDefault(Class type, T def, int index) throws CommandNotEnoughArgumentsException; /** * Tries to use a stateless {@link IArgParser} to parse the next argument into the specified class *

* A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire - * {@link ArgConsumer}. + * {@link IArgConsumer}}. * * @param type The type to peek as * @param def The value to return if the argument can't be parsed @@ -366,9 +283,7 @@ public class ArgConsumer { * @see #peekAs(Class) * @see #peekAsOrNull(Class) */ - public T peekAsOrDefault(Class type, T def) throws CommandNotEnoughArgumentsException { - return peekAsOrDefault(type, def, 0); - } + T peekAsOrDefault(Class type, T def) throws CommandNotEnoughArgumentsException; /** * Tries to use a stateless {@link IArgParser} to parse the argument at the specified index into the specified @@ -376,7 +291,7 @@ public class ArgConsumer { *

* A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire - * {@link ArgConsumer}. + * {@link IArgConsumer}}. * * @param type The type to peek as * @param index The index to peek @@ -386,16 +301,14 @@ public class ArgConsumer { * @see #peekAs(Class, int) * @see #peekAsOrDefault(Class, Object, int) */ - public T peekAsOrNull(Class type, int index) throws CommandNotEnoughArgumentsException { - return peekAsOrDefault(type, null, index); - } + T peekAsOrNull(Class type, int index) throws CommandNotEnoughArgumentsException; /** * Tries to use a stateless {@link IArgParser} to parse the next argument into the specified class *

* A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire - * {@link ArgConsumer}. + * {@link IArgConsumer}}. * * @param type The type to peek as * @return An instance of the specified type, or {@code null} if it couldn't be parsed @@ -404,48 +317,30 @@ public class ArgConsumer { * @see #peekAs(Class) * @see #peekAsOrDefault(Class, Object) */ - public T peekAsOrNull(Class type) throws CommandNotEnoughArgumentsException { - return peekAsOrNull(type, 0); - } + T peekAsOrNull(Class type) throws CommandNotEnoughArgumentsException; - public T peekDatatype(IDatatypeFor datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { - return copy().getDatatypeFor(datatype); - } + T peekDatatype(IDatatypeFor datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; - public T peekDatatype(IDatatypePost datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { - return this.peekDatatype(datatype, null); - } + T peekDatatype(IDatatypePost datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; - public T peekDatatype(IDatatypePost datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { - return copy().getDatatypePost(datatype, original); - } + T peekDatatype(IDatatypePost datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; - public T peekDatatypeOrNull(IDatatypeFor datatype) { - return copy().getDatatypeForOrNull(datatype); - } + T peekDatatypeOrNull(IDatatypeFor datatype); - public T peekDatatypeOrNull(IDatatypePost datatype) { - return copy().getDatatypePostOrNull(datatype, null); - } + T peekDatatypeOrNull(IDatatypePost datatype); - public > T peekDatatypePost(D datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { - return copy().getDatatypePost(datatype, original); - } + > T peekDatatypePost(D datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; - public > T peekDatatypePostOrDefault(D datatype, O original, T def) { - return copy().getDatatypePostOrDefault(datatype, original, def); - } + > T peekDatatypePostOrDefault(D datatype, O original, T def); - public > T peekDatatypePostOrNull(D datatype, O original) { - return peekDatatypePostOrDefault(datatype, original, null); - } + > T peekDatatypePostOrNull(D datatype, O original); /** * Attempts to get the specified {@link IDatatypeFor} from this ArgConsumer *

* A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire - * {@link ArgConsumer}. + * {@link IArgConsumer}}. *

* Since this is a peek operation, this ArgConsumer will not be mutated by any call to this method. * @@ -454,16 +349,14 @@ public class ArgConsumer { * @see IDatatype * @see IDatatypeFor */ - public > T peekDatatypeFor(Class datatype) { - return copy().peekDatatypeFor(datatype); - } + > T peekDatatypeFor(Class datatype); /** * Attempts to get the specified {@link IDatatypeFor} from this ArgConsumer *

* A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire - * {@link ArgConsumer}. + * {@link IArgConsumer}}. *

* Since this is a peek operation, this ArgConsumer will not be mutated by any call to this method. * @@ -473,16 +366,14 @@ public class ArgConsumer { * @see IDatatype * @see IDatatypeFor */ - public > T peekDatatypeForOrDefault(Class datatype, T def) { - return copy().peekDatatypeForOrDefault(datatype, def); - } + > T peekDatatypeForOrDefault(Class datatype, T def); /** * Attempts to get the specified {@link IDatatypeFor} from this ArgConsumer *

* A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire - * {@link ArgConsumer}. + * {@link IArgConsumer}}. *

* Since this is a peek operation, this ArgConsumer will not be mutated by any call to this method. * @@ -491,9 +382,7 @@ public class ArgConsumer { * @see IDatatype * @see IDatatypeFor */ - public > T peekDatatypeForOrNull(Class datatype) { - return peekDatatypeForOrDefault(datatype, null); - } + > T peekDatatypeForOrNull(Class datatype); /** * Gets the next argument and returns it. This consumes the first argument so that subsequent calls will return @@ -502,12 +391,7 @@ public class ArgConsumer { * @return The next argument * @throws CommandNotEnoughArgumentsException If there's less than one argument left */ - public CommandArgument get() throws CommandNotEnoughArgumentsException { - requireMin(1); - CommandArgument arg = args.removeFirst(); - consumed.add(arg); - return arg; - } + ICommandArgument get() throws CommandNotEnoughArgumentsException; /** * Gets the value of the next argument and returns it. This consumes the first argument so that subsequent calls @@ -516,9 +400,7 @@ public class ArgConsumer { * @return The value of the next argument * @throws CommandNotEnoughArgumentsException If there's less than one argument left */ - public String getString() throws CommandNotEnoughArgumentsException { - return get().value; - } + String getString() throws CommandNotEnoughArgumentsException; /** * Gets an enum value from the enum class with the same name as the next argument's value @@ -531,11 +413,9 @@ public class ArgConsumer { * @throws CommandInvalidTypeException If the constant couldn't be found * @see #peekEnum(Class) * @see #getEnumOrNull(Class) - * @see CommandArgument#getEnum(Class) + * @see ICommandArgument#getEnum(Class) */ - public > E getEnum(Class enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { - return get().getEnum(enumClass); - } + > E getEnum(Class enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; /** * Gets an enum value from the enum class with the same name as the next argument's value @@ -550,16 +430,9 @@ public class ArgConsumer { * @see #getEnum(Class) * @see #getEnumOrNull(Class) * @see #peekEnumOrNull(Class) - * @see CommandArgument#getEnum(Class) + * @see ICommandArgument#getEnum(Class) */ - public > E getEnumOrDefault(Class enumClass, E def) throws CommandNotEnoughArgumentsException { - try { - peekEnum(enumClass); - return getEnum(enumClass); - } catch (CommandInvalidTypeException e) { - return def; - } - } + > E getEnumOrDefault(Class enumClass, E def) throws CommandNotEnoughArgumentsException; /** * Gets an enum value from the enum class with the same name as the next argument's value @@ -573,18 +446,16 @@ public class ArgConsumer { * @see #getEnum(Class) * @see #getEnumOrDefault(Class, Enum) * @see #peekEnumOrNull(Class) - * @see CommandArgument#getEnum(Class) + * @see ICommandArgument#getEnum(Class) */ - public > E getEnumOrNull(Class enumClass) throws CommandNotEnoughArgumentsException { - return getEnumOrDefault(enumClass, null); - } + > E getEnumOrNull(Class enumClass) throws CommandNotEnoughArgumentsException; /** * Tries to use a stateless {@link IArgParser} to parse the next argument into the specified class *

* A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire - * {@link ArgConsumer}. + * {@link IArgConsumer}}. * * @param type The type to peek as * @return An instance of the specified type @@ -597,16 +468,14 @@ public class ArgConsumer { * @see #peekAsOrDefault(Class, Object, int) * @see #peekAsOrNull(Class, int) */ - public T getAs(Class type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { - return get().getAs(type); - } + T getAs(Class type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; /** * Tries to use a stateless {@link IArgParser} to parse the next argument into the specified class *

* A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire - * {@link ArgConsumer}. + * {@link IArgConsumer}}. * * @param type The type to peek as * @param def The default value @@ -619,22 +488,14 @@ public class ArgConsumer { * @see #peekAsOrDefault(Class, Object, int) * @see #peekAsOrNull(Class, int) */ - public T getAsOrDefault(Class type, T def) throws CommandNotEnoughArgumentsException { - try { - T val = peek().getAs(type); - get(); - return val; - } catch (CommandInvalidTypeException e) { - return def; - } - } + T getAsOrDefault(Class type, T def) throws CommandNotEnoughArgumentsException; /** * Tries to use a stateless {@link IArgParser} to parse the next argument into the specified class *

* A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire - * {@link ArgConsumer}. + * {@link IArgConsumer}}. * * @param type The type to peek as * @return An instance of the specified type, or {@code null} if it couldn't be parsed @@ -646,75 +507,25 @@ public class ArgConsumer { * @see #peekAsOrDefault(Class, Object, int) * @see #peekAsOrNull(Class, int) */ - public T getAsOrNull(Class type) throws CommandNotEnoughArgumentsException { - return getAsOrDefault(type, null); - } + T getAsOrNull(Class type) throws CommandNotEnoughArgumentsException; - public > T getDatatypePost(D datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { - try { - return datatype.apply(this.context, original); - } catch (Exception e) { - e.printStackTrace(); - throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName()); - } - } + > T getDatatypePost(D datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; - public > T getDatatypePostOrDefault(D datatype, O original, T _default) { - final List argsSnapshot = new ArrayList<>(this.args); - final List consumedSnapshot = new ArrayList<>(this.consumed); - try { - return this.getDatatypePost(datatype, original); - } catch (Exception e) { - this.args.clear(); - this.args.addAll(argsSnapshot); - this.consumed.clear(); - this.consumed.addAll(consumedSnapshot); - return _default; - } - } + > T getDatatypePostOrDefault(D datatype, O original, T _default); - public > T getDatatypePostOrNull(D datatype, O original) { - return this.getDatatypePostOrDefault(datatype, original, null); - } + > T getDatatypePostOrNull(D datatype, O original); - public > T getDatatypeFor(D datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { - try { - return datatype.get(this.context); - } catch (Exception e) { - throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName()); - } - } + > T getDatatypeFor(D datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; - public > T getDatatypeForOrDefault(D datatype, T def) { - final List argsSnapshot = new ArrayList<>(this.args); - final List consumedSnapshot = new ArrayList<>(this.consumed); - try { - return this.getDatatypeFor(datatype); - } catch (Exception e) { - this.args.clear(); - this.args.addAll(argsSnapshot); - this.consumed.clear(); - this.consumed.addAll(consumedSnapshot); - return def; - } - } + > T getDatatypeForOrDefault(D datatype, T def); - public > T getDatatypeForOrNull(D datatype) { - return this.getDatatypeForOrDefault(datatype, null); - } + > T getDatatypeForOrNull(D datatype); - public Stream tabCompleteDatatype(T datatype) { - try { - return datatype.tabComplete(this.context); - } catch (Exception e) { - e.printStackTrace(); - } - return Stream.empty(); - } + Stream tabCompleteDatatype(T datatype); /** * Returns the "raw rest" of the string. For example, from a string arg1 arg2  arg3, split - * into three {@link CommandArgument}s {@code "arg1"}, {@code "arg2"}, and {@code "arg3"}: + * into three {@link ICommandArgument}s {@code "arg1"}, {@code "arg2"}, and {@code "arg3"}: * *

    *
  • {@code rawRest()} would return arg1 arg2  arg3
  • @@ -726,9 +537,7 @@ public class ArgConsumer { * * @return The "raw rest" of the string. */ - public String rawRest() { - return args.size() > 0 ? args.getFirst().rawRest : ""; - } + String rawRest(); /** * @param min The minimum amount of arguments to require. @@ -736,11 +545,7 @@ public class ArgConsumer { * @see #requireMax(int) * @see #requireExactly(int) */ - public void requireMin(int min) throws CommandNotEnoughArgumentsException { - if (args.size() < min) { - throw new CommandNotEnoughArgumentsException(min + consumed.size()); - } - } + void requireMin(int min) throws CommandNotEnoughArgumentsException; /** * @param max The maximum amount of arguments allowed. @@ -748,11 +553,7 @@ public class ArgConsumer { * @see #requireMin(int) * @see #requireExactly(int) */ - public void requireMax(int max) throws CommandTooManyArgumentsException { - if (args.size() > max) { - throw new CommandTooManyArgumentsException(max + consumed.size()); - } - } + void requireMax(int max) throws CommandTooManyArgumentsException; /** * @param args The exact amount of arguments to require. @@ -761,58 +562,34 @@ public class ArgConsumer { * @see #requireMin(int) * @see #requireMax(int) */ - public void requireExactly(int args) throws CommandException { - requireMin(args); - requireMax(args); - } + void requireExactly(int args) throws CommandException; /** - * @return If this {@link ArgConsumer} has consumed at least one argument. + * @return If this {@link IArgConsumer}} has consumed at least one argument. * @see #consumed() * @see #consumedString() */ - public boolean hasConsumed() { - return !consumed.isEmpty(); - } + boolean hasConsumed(); /** - * @return The last argument this {@link ArgConsumer} has consumed, or the {@link CommandArgument#unknown() unknown} - * argument if no arguments have been consumed yet. + * @return The last argument this {@link IArgConsumer}} has consumed, or an "unknown" argument, indicated by a + * comamnd argument index that has a value of {@code -1}, if no arguments have been consumed yet. * @see #consumedString() * @see #hasConsumed() */ - public CommandArgument consumed() { - return consumed.size() > 0 ? consumed.getLast() : CommandArgument.unknown(); - } + ICommandArgument consumed(); /** - * @return The value of thelast argument this {@link ArgConsumer} has consumed, or an empty string if no arguments + * @return The value of thelast argument this {@link IArgConsumer}} has consumed, or an empty string if no arguments * have been consumed yet * @see #consumed() * @see #hasConsumed() */ - public String consumedString() { - return consumed().value; - } + String consumedString(); /** - * @return A copy of this {@link ArgConsumer}. It has the same arguments (both consumed and not), but does not + * @return A copy of this {@link IArgConsumer}}. It has the same arguments (both consumed and not), but does not * affect or mutate this instance. Useful for the various {@code peek} functions */ - public ArgConsumer copy() { - return new ArgConsumer(manager, args, consumed); - } - - private final class Context implements IDatatypeContext { - - @Override - public final IBaritone getBaritone() { - return ArgConsumer.this.manager.getBaritone(); - } - - @Override - public final ArgConsumer getConsumer() { - return ArgConsumer.this; - } - } + IArgConsumer copy(); } diff --git a/src/api/java/baritone/api/utils/command/helpers/pagination/Paginator.java b/src/api/java/baritone/api/command/helpers/pagination/Paginator.java similarity index 72% rename from src/api/java/baritone/api/utils/command/helpers/pagination/Paginator.java rename to src/api/java/baritone/api/command/helpers/pagination/Paginator.java index da5ac4362..e5bf9d55f 100644 --- a/src/api/java/baritone/api/utils/command/helpers/pagination/Paginator.java +++ b/src/api/java/baritone/api/command/helpers/pagination/Paginator.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.helpers.pagination; +package baritone.api.command.helpers.pagination; import baritone.api.utils.Helper; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidTypeException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidTypeException; +import baritone.api.command.helpers.arguments.IArgConsumer; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; @@ -115,7 +115,7 @@ public class Paginator implements Helper { display(transform, null); } - public static void paginate(ArgConsumer consumer, Paginator pagi, Runnable pre, Function transform, String commandPrefix) throws CommandException { + public static void paginate(IArgConsumer consumer, Paginator pagi, Runnable pre, Function transform, String commandPrefix) throws CommandException { int page = 1; consumer.requireMax(1); if (consumer.hasAny()) { @@ -127,7 +127,7 @@ public class Paginator implements Helper { "a valid page (1-%d)", pagi.getMaxPage() ), - consumer.consumed().value + consumer.consumed().getValue() ); } } @@ -138,47 +138,47 @@ public class Paginator implements Helper { pagi.display(transform, commandPrefix); } - public static void paginate(ArgConsumer consumer, List elems, Runnable pre, Function transform, String commandPrefix) throws CommandException { + public static void paginate(IArgConsumer consumer, List elems, Runnable pre, Function transform, String commandPrefix) throws CommandException { paginate(consumer, new Paginator<>(elems), pre, transform, commandPrefix); } - public static void paginate(ArgConsumer consumer, T[] elems, Runnable pre, Function transform, String commandPrefix) throws CommandException { + public static void paginate(IArgConsumer consumer, T[] elems, Runnable pre, Function transform, String commandPrefix) throws CommandException { paginate(consumer, Arrays.asList(elems), pre, transform, commandPrefix); } - public static void paginate(ArgConsumer consumer, Paginator pagi, Function transform, String commandPrefix) throws CommandException { + public static void paginate(IArgConsumer consumer, Paginator pagi, Function transform, String commandPrefix) throws CommandException { paginate(consumer, pagi, null, transform, commandPrefix); } - public static void paginate(ArgConsumer consumer, List elems, Function transform, String commandPrefix) throws CommandException { + public static void paginate(IArgConsumer consumer, List elems, Function transform, String commandPrefix) throws CommandException { paginate(consumer, new Paginator<>(elems), null, transform, commandPrefix); } - public static void paginate(ArgConsumer consumer, T[] elems, Function transform, String commandPrefix) throws CommandException { + public static void paginate(IArgConsumer consumer, T[] elems, Function transform, String commandPrefix) throws CommandException { paginate(consumer, Arrays.asList(elems), null, transform, commandPrefix); } - public static void paginate(ArgConsumer consumer, Paginator pagi, Runnable pre, Function transform) throws CommandException { + public static void paginate(IArgConsumer consumer, Paginator pagi, Runnable pre, Function transform) throws CommandException { paginate(consumer, pagi, pre, transform, null); } - public static void paginate(ArgConsumer consumer, List elems, Runnable pre, Function transform) throws CommandException { + public static void paginate(IArgConsumer consumer, List elems, Runnable pre, Function transform) throws CommandException { paginate(consumer, new Paginator<>(elems), pre, transform, null); } - public static void paginate(ArgConsumer consumer, T[] elems, Runnable pre, Function transform) throws CommandException { + public static void paginate(IArgConsumer consumer, T[] elems, Runnable pre, Function transform) throws CommandException { paginate(consumer, Arrays.asList(elems), pre, transform, null); } - public static void paginate(ArgConsumer consumer, Paginator pagi, Function transform) throws CommandException { + public static void paginate(IArgConsumer consumer, Paginator pagi, Function transform) throws CommandException { paginate(consumer, pagi, null, transform, null); } - public static void paginate(ArgConsumer consumer, List elems, Function transform) throws CommandException { + public static void paginate(IArgConsumer consumer, List elems, Function transform) throws CommandException { paginate(consumer, new Paginator<>(elems), null, transform, null); } - public static void paginate(ArgConsumer consumer, T[] elems, Function transform) throws CommandException { + public static void paginate(IArgConsumer consumer, T[] elems, Function transform) throws CommandException { paginate(consumer, Arrays.asList(elems), null, transform, null); } } diff --git a/src/api/java/baritone/api/utils/command/helpers/tabcomplete/TabCompleteHelper.java b/src/api/java/baritone/api/command/helpers/tabcomplete/TabCompleteHelper.java similarity index 96% rename from src/api/java/baritone/api/utils/command/helpers/tabcomplete/TabCompleteHelper.java rename to src/api/java/baritone/api/command/helpers/tabcomplete/TabCompleteHelper.java index db63b2d58..57192f0c2 100644 --- a/src/api/java/baritone/api/utils/command/helpers/tabcomplete/TabCompleteHelper.java +++ b/src/api/java/baritone/api/command/helpers/tabcomplete/TabCompleteHelper.java @@ -15,15 +15,14 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.helpers.tabcomplete; +package baritone.api.command.helpers.tabcomplete; import baritone.api.BaritoneAPI; import baritone.api.Settings; import baritone.api.event.events.TabCompleteEvent; import baritone.api.utils.SettingsUtil; -import baritone.api.utils.command.datatypes.IDatatype; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import baritone.api.utils.command.manager.ICommandManager; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.command.manager.ICommandManager; import net.minecraft.util.ResourceLocation; import java.util.Comparator; @@ -45,7 +44,7 @@ import java.util.stream.Stream; * {@link #filterPrefix(String)} *
  • Get the stream using {@link #stream()}
  • *
  • Pass it up to whatever's calling your tab complete function (i.e. - * {@link ICommandManager#tabComplete(String)} or {@link ArgConsumer#tabCompleteDatatype(IDatatype)})
  • + * {@link ICommandManager#tabComplete(String)} or {@link IArgConsumer}#tabCompleteDatatype(IDatatype)}) *
*

* For advanced users: if you're intercepting {@link TabCompleteEvent}s directly, use {@link #build()} instead for an @@ -242,7 +241,7 @@ public class TabCompleteHelper { */ public TabCompleteHelper addCommands(ICommandManager manager) { return append(manager.getRegistry().descendingStream() - .flatMap(command -> command.names.stream()) + .flatMap(command -> command.getNames().stream()) .distinct() ); } diff --git a/src/api/java/baritone/api/utils/command/manager/ICommandManager.java b/src/api/java/baritone/api/command/manager/ICommandManager.java similarity index 77% rename from src/api/java/baritone/api/utils/command/manager/ICommandManager.java rename to src/api/java/baritone/api/command/manager/ICommandManager.java index 63682433e..f74a3c268 100644 --- a/src/api/java/baritone/api/utils/command/manager/ICommandManager.java +++ b/src/api/java/baritone/api/command/manager/ICommandManager.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.manager; +package baritone.api.command.manager; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.argument.CommandArgument; -import baritone.api.utils.command.registry.Registry; +import baritone.api.command.Command; +import baritone.api.command.argument.ICommandArgument; +import baritone.api.command.registry.Registry; import net.minecraft.util.Tuple; import java.util.List; @@ -44,9 +44,9 @@ public interface ICommandManager { boolean execute(String string); - boolean execute(Tuple> expanded); + boolean execute(Tuple> expanded); - Stream tabComplete(Tuple> expanded); + Stream tabComplete(Tuple> expanded); Stream tabComplete(String prefix); } diff --git a/src/api/java/baritone/api/utils/command/registry/Registry.java b/src/api/java/baritone/api/command/registry/Registry.java similarity index 99% rename from src/api/java/baritone/api/utils/command/registry/Registry.java rename to src/api/java/baritone/api/command/registry/Registry.java index bac50dcfa..067791690 100644 --- a/src/api/java/baritone/api/utils/command/registry/Registry.java +++ b/src/api/java/baritone/api/command/registry/Registry.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.registry; +package baritone.api.command.registry; import java.util.*; import java.util.function.Consumer; diff --git a/src/api/java/baritone/api/process/IGetToBlockProcess.java b/src/api/java/baritone/api/process/IGetToBlockProcess.java index a5a35577e..f58efbd35 100644 --- a/src/api/java/baritone/api/process/IGetToBlockProcess.java +++ b/src/api/java/baritone/api/process/IGetToBlockProcess.java @@ -17,6 +17,7 @@ package baritone.api.process; +import baritone.api.utils.BlockOptionalMeta; import net.minecraft.block.Block; /** @@ -24,7 +25,11 @@ import net.minecraft.block.Block; */ public interface IGetToBlockProcess extends IBaritoneProcess { - void getToBlock(Block block); + void getToBlock(BlockOptionalMeta block); + + default void getToBlock(Block block) { + getToBlock(new BlockOptionalMeta(block)); + } boolean blacklistClosest(); } diff --git a/src/api/java/baritone/api/utils/command/argparser/ArgParserManager.java b/src/api/java/baritone/api/utils/command/argparser/ArgParserManager.java deleted file mode 100644 index 1b0730c60..000000000 --- a/src/api/java/baritone/api/utils/command/argparser/ArgParserManager.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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.utils.command.argparser; - -import baritone.api.utils.command.argument.CommandArgument; -import baritone.api.utils.command.exception.CommandInvalidTypeException; -import baritone.api.utils.command.exception.CommandNoParserForTypeException; -import baritone.api.utils.command.exception.CommandUnhandledException; -import baritone.api.utils.command.registry.Registry; - -public class ArgParserManager { - - public static final Registry REGISTRY = new Registry<>(); - - static { - DefaultArgParsers.ALL.forEach(REGISTRY::register); - } - - /** - * @param type The type trying to be parsed - * @return A parser that can parse arguments into this class, if found. - */ - public static IArgParser.Stateless getParserStateless(Class type) { - //noinspection unchecked - return REGISTRY.descendingStream() - .filter(IArgParser.Stateless.class::isInstance) - .map(IArgParser.Stateless.class::cast) - .filter(parser -> parser.getTarget().isAssignableFrom(type)) - .findFirst() - .orElse(null); - } - - /** - * @param type The type trying to be parsed - * @return A parser that can parse arguments into this class, if found. - */ - public static IArgParser.Stated getParserStated(Class type, Class stateKlass) { - //noinspection unchecked - return REGISTRY.descendingStream() - .filter(IArgParser.Stated.class::isInstance) - .map(IArgParser.Stated.class::cast) - .filter(parser -> parser.getTarget().isAssignableFrom(type)) - .filter(parser -> parser.getStateType().isAssignableFrom(stateKlass)) - .map(IArgParser.Stated.class::cast) - .findFirst() - .orElse(null); - } - - /** - * Attempt to parse the specified argument with a stateless {@link IArgParser} that outputs the specified class. - * - * @param type The type to try and parse the argument into. - * @param arg The argument to parse. - * @return An instance of the specified class. - * @throws CommandInvalidTypeException If the parsing failed - */ - public static T parseStateless(Class type, CommandArgument arg) throws CommandInvalidTypeException { - IArgParser.Stateless parser = getParserStateless(type); - if (parser == null) { - throw new CommandNoParserForTypeException(type); - } - try { - return parser.parseArg(arg); - } catch (Exception exc) { - throw new CommandInvalidTypeException(arg, type.getSimpleName()); - } - } - - /** - * Attempt to parse the specified argument with a stated {@link IArgParser} that outputs the specified class. - * - * @param type The type to try and parse the argument into. - * @param arg The argument to parse. - * @param state The state to pass to the {@link IArgParser.Stated}. - * @return An instance of the specified class. - * @throws CommandInvalidTypeException If the parsing failed - * @see IArgParser.Stated - */ - public static T parseStated(Class type, Class stateKlass, CommandArgument arg, S state) throws CommandInvalidTypeException { - IArgParser.Stated parser = getParserStated(type, stateKlass); - if (parser == null) { - throw new CommandNoParserForTypeException(type); - } - try { - return parser.parseArg(arg, state); - } catch (Exception exc) { - throw new CommandInvalidTypeException(arg, type.getSimpleName()); - } - } -} diff --git a/src/api/java/baritone/api/utils/command/argument/CommandArgument.java b/src/api/java/baritone/api/utils/command/argument/CommandArgument.java deleted file mode 100644 index a5b044c43..000000000 --- a/src/api/java/baritone/api/utils/command/argument/CommandArgument.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * 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.utils.command.argument; - -import baritone.api.utils.command.argparser.ArgParserManager; -import baritone.api.utils.command.argparser.IArgParser; -import baritone.api.utils.command.exception.CommandInvalidArgumentException; -import baritone.api.utils.command.exception.CommandInvalidTypeException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import net.minecraft.util.EnumFacing; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Stream; - -/** - * A {@link CommandArgument} is an immutable object representing one command argument. It contains data on the index of - * that argument, its value, and the rest of the string that argument was found in - *

- * You're recommended to use {@link ArgConsumer}s to handle these. - */ -public class CommandArgument { - - public final int index; - public final String value; - public final String rawRest; - public final static Pattern argPattern = Pattern.compile("\\S+"); - - private CommandArgument(int index, String value, String rawRest) { - this.index = index; - this.value = value; - this.rawRest = rawRest; - } - - /** - * Gets an enum value from the enum class with the same name as this argument's value - *

- * For example if you getEnum as an {@link EnumFacing}, and this argument's value is "up", it will return {@link - * EnumFacing#UP} - * - * @param enumClass The enum class to search - * @return An enum constant of that class with the same name as this argument's value - * @throws CommandInvalidTypeException If the constant couldn't be found - * @see ArgConsumer#peekEnum(Class) - * @see ArgConsumer#peekEnum(Class, int) - * @see ArgConsumer#peekEnumOrNull(Class) - * @see ArgConsumer#peekEnumOrNull(Class, int) - * @see ArgConsumer#getEnum(Class) - * @see ArgConsumer#getEnumOrNull(Class) - */ - public > E getEnum(Class enumClass) throws CommandInvalidTypeException { - return Stream.of(enumClass.getEnumConstants()) - .filter(e -> e.name().equalsIgnoreCase(value)) - .findFirst() - .orElseThrow(() -> new CommandInvalidTypeException(this, enumClass.getSimpleName())); - } - - /** - * Tries to use a stateless {@link IArgParser} to parse this argument into the specified class - * - * @param type The class to parse this argument into - * @return An instance of the specified type - * @throws CommandInvalidTypeException If the parsing failed - */ - public T getAs(Class type) throws CommandInvalidTypeException { - return ArgParserManager.parseStateless(type, this); - } - - /** - * Tries to use a stateless {@link IArgParser} to parse this argument into the specified class - * - * @param type The class to parse this argument into - * @return If the parser succeeded - */ - public boolean is(Class type) { - try { - getAs(type); - return true; - } catch (Throwable t) { - return false; - } - } - - /** - * Tries to use a stated {@link IArgParser} to parse this argument into the specified class - * - * @param type The class to parse this argument into - * @return An instance of the specified type - * @throws CommandInvalidTypeException If the parsing failed - */ - @SuppressWarnings("UnusedReturnValue") - public T getAs(Class type, Class stateType, S state) throws CommandInvalidTypeException { - return ArgParserManager.parseStated(type, stateType, this, state); - } - - /** - * Tries to use a stated {@link IArgParser} to parse this argument into the specified class - * - * @param type The class to parse this argument into - * @return If the parser succeeded - */ - public boolean is(Class type, Class stateType, S state) { - try { - getAs(type, stateType, state); - return true; - } catch (Throwable t) { - return false; - } - } - - /** - * Turn a string into a list of {@link CommandArgument}s. This is needed because of {@link CommandArgument#rawRest} - * - * @param string The string to convert - * @param preserveEmptyLast If the string ends with whitespace, add an empty {@link CommandArgument} to the end This - * is useful for tab completion - * @return A list of {@link CommandArgument}s - */ - public static List from(String string, boolean preserveEmptyLast) { - List args = new ArrayList<>(); - Matcher argMatcher = argPattern.matcher(string); - int lastEnd = -1; - while (argMatcher.find()) { - args.add(new CommandArgument( - args.size(), - argMatcher.group(), - string.substring(argMatcher.start()) - )); - lastEnd = argMatcher.end(); - } - if (preserveEmptyLast && lastEnd < string.length()) { - args.add(new CommandArgument(args.size(), "", "")); - } - return args; - } - - /** - * @see #from(String, boolean) - */ - public static List from(String string) { - return from(string, false); - } - - /** - * Returns an "unknown" {@link CommandArgument}. This shouldn't be used unless you absolutely have no information - - * ESPECIALLY not with {@link CommandInvalidArgumentException}s - * - * @return The unknown {@link CommandArgument} - */ - public static CommandArgument unknown() { - return new CommandArgument(-1, "", ""); - } -} diff --git a/src/api/java/baritone/api/utils/command/execution/ICommandExecution.java b/src/api/java/baritone/api/utils/command/execution/ICommandExecution.java deleted file mode 100644 index 4ca5b193c..000000000 --- a/src/api/java/baritone/api/utils/command/execution/ICommandExecution.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.utils.command.execution; - -import baritone.api.utils.command.Command; -import baritone.api.utils.command.argument.CommandArgument; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import net.minecraft.util.Tuple; - -import java.util.List; -import java.util.stream.Stream; - -/** - * @author Brady - * @since 9/28/2019 - */ -public interface ICommandExecution { - - /** - * @return The label that was used to target the {@link Command} - */ - String getLabel(); - - /** - * @return The arguments to be passed to the {@link Command} - */ - ArgConsumer getArguments(); - - /** - * Executes the target command for this {@link ICommandExecution}. This method should never - * {@code throw} any exception, anything that is thrown during the target command execution - * should be safely handled. - */ - void execute(); - - /** - * Forwards this {@link ICommandExecution} to the target {@link Command} to perform a tab-completion. - * If the tab-completion operation is a failure, then {@link Stream#empty()} will be returned. - * - * @return The tab-completed arguments, if possible. - */ - Stream tabComplete(); - - static Tuple> expand(String string, boolean preserveEmptyLast) { - String label = string.split("\\s", 2)[0]; - List args = CommandArgument.from(string.substring(label.length()), preserveEmptyLast); - return new Tuple<>(label, args); - } - - static Tuple> expand(String string) { - return expand(string, false); - } -} diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index e92103a82..fe8685ed7 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -29,7 +29,7 @@ import baritone.event.GameEventHandler; import baritone.process.*; import baritone.selection.SelectionManager; import baritone.utils.*; -import baritone.utils.command.manager.CommandManager; +import baritone.command.manager.CommandManager; import baritone.utils.player.PrimaryPlayerContext; import net.minecraft.client.Minecraft; diff --git a/src/main/java/baritone/BaritoneProvider.java b/src/main/java/baritone/BaritoneProvider.java index 416f1cae5..cb24dfe21 100644 --- a/src/main/java/baritone/BaritoneProvider.java +++ b/src/main/java/baritone/BaritoneProvider.java @@ -20,8 +20,10 @@ package baritone; import baritone.api.IBaritone; import baritone.api.IBaritoneProvider; import baritone.api.cache.IWorldScanner; -import baritone.utils.command.BaritoneChatControl; +import baritone.api.command.ICommandSystem; +import baritone.command.BaritoneChatControl; import baritone.cache.WorldScanner; +import baritone.command.CommandSystem; import java.util.Collections; import java.util.List; @@ -57,4 +59,9 @@ public final class BaritoneProvider implements IBaritoneProvider { public IWorldScanner getWorldScanner() { return WorldScanner.INSTANCE; } + + @Override + public ICommandSystem getCommandSystem() { + return CommandSystem.INSTANCE; + } } diff --git a/src/main/java/baritone/utils/command/BaritoneChatControl.java b/src/main/java/baritone/command/BaritoneChatControl.java similarity index 89% rename from src/main/java/baritone/utils/command/BaritoneChatControl.java rename to src/main/java/baritone/command/BaritoneChatControl.java index 86e667b7d..79b8ee255 100644 --- a/src/main/java/baritone/utils/command/BaritoneChatControl.java +++ b/src/main/java/baritone/command/BaritoneChatControl.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.utils.command; +package baritone.command; import baritone.api.BaritoneAPI; import baritone.api.IBaritone; @@ -26,13 +26,14 @@ import baritone.api.event.events.TabCompleteEvent; import baritone.api.event.listener.AbstractGameEventListener; import baritone.api.utils.Helper; import baritone.api.utils.SettingsUtil; -import baritone.api.utils.command.argument.CommandArgument; -import baritone.api.utils.command.exception.CommandNotEnoughArgumentsException; -import baritone.api.utils.command.exception.CommandNotFoundException; -import baritone.api.utils.command.execution.ICommandExecution; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; -import baritone.api.utils.command.manager.ICommandManager; +import baritone.api.command.argument.ICommandArgument; +import baritone.api.command.exception.CommandNotEnoughArgumentsException; +import baritone.api.command.exception.CommandNotFoundException; +import baritone.command.helpers.arguments.ArgConsumer; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.manager.ICommandManager; +import baritone.command.argument.CommandArguments; +import baritone.command.manager.CommandManager; import net.minecraft.util.Tuple; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; @@ -46,7 +47,7 @@ import java.util.List; import java.util.Locale; import java.util.stream.Stream; -import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; +import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; public class BaritoneChatControl implements Helper, AbstractGameEventListener { @@ -67,7 +68,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener { event.cancel(); String commandStr = msg.substring(forceRun ? FORCE_COMMAND_PREFIX.length() : prefix.length()); if (!runCommand(commandStr) && !commandStr.trim().isEmpty()) { - new CommandNotFoundException(ICommandExecution.expand(commandStr).getA()).handle(null, null); + new CommandNotFoundException(CommandManager.expand(commandStr).getA()).handle(null, null); } } else if ((settings.chatControl.value || settings.chatControlAnyway.value) && runCommand(msg)) { event.cancel(); @@ -106,7 +107,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener { if (msg.isEmpty()) { return this.runCommand("help"); } - Tuple> pair = ICommandExecution.expand(msg); + Tuple> pair = CommandManager.expand(msg); String command = pair.getA(); String rest = msg.substring(pair.getA().length()); ArgConsumer argc = new ArgConsumer(this.manager, pair.getB()); @@ -155,7 +156,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener { return; } String msg = prefix.substring(commandPrefix.length()); - List args = CommandArgument.from(msg, true); + List args = CommandArguments.from(msg, true); Stream stream = tabComplete(msg); if (args.size() == 1) { stream = stream.map(x -> commandPrefix + x); @@ -165,7 +166,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener { public Stream tabComplete(String msg) { try { - List args = CommandArgument.from(msg, true); + List args = CommandArguments.from(msg, true); ArgConsumer argc = new ArgConsumer(this.manager, args); if (argc.hasAtMost(2)) { if (argc.hasExactly(1)) { diff --git a/src/main/java/baritone/command/CommandSystem.java b/src/main/java/baritone/command/CommandSystem.java new file mode 100644 index 000000000..49d3685c1 --- /dev/null +++ b/src/main/java/baritone/command/CommandSystem.java @@ -0,0 +1,35 @@ +/* + * 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.command; + +import baritone.api.command.ICommandSystem; +import baritone.command.argparser.ArgParserManager; +import baritone.api.command.argparser.IArgParserManager; + +/** + * @author Brady + * @since 10/4/2019 + */ +public enum CommandSystem implements ICommandSystem { + INSTANCE; + + @Override + public IArgParserManager getParserManager() { + return ArgParserManager.INSTANCE; + } +} diff --git a/src/main/java/baritone/command/argparser/ArgParserManager.java b/src/main/java/baritone/command/argparser/ArgParserManager.java new file mode 100644 index 000000000..a6acdcbcf --- /dev/null +++ b/src/main/java/baritone/command/argparser/ArgParserManager.java @@ -0,0 +1,90 @@ +/* + * 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.command.argparser; + +import baritone.api.command.argparser.IArgParser; +import baritone.api.command.argparser.IArgParserManager; +import baritone.api.command.argument.ICommandArgument; +import baritone.api.command.exception.CommandInvalidTypeException; +import baritone.api.command.exception.CommandNoParserForTypeException; +import baritone.api.command.registry.Registry; + +public enum ArgParserManager implements IArgParserManager { + INSTANCE; + + public final Registry registry = new Registry<>(); + + ArgParserManager() { + DefaultArgParsers.ALL.forEach(this.registry::register); + } + + @Override + public IArgParser.Stateless getParserStateless(Class type) { + //noinspection unchecked + return this.registry.descendingStream() + .filter(IArgParser.Stateless.class::isInstance) + .map(IArgParser.Stateless.class::cast) + .filter(parser -> parser.getTarget().isAssignableFrom(type)) + .findFirst() + .orElse(null); + } + + @Override + public IArgParser.Stated getParserStated(Class type, Class stateKlass) { + //noinspection unchecked + return this.registry.descendingStream() + .filter(IArgParser.Stated.class::isInstance) + .map(IArgParser.Stated.class::cast) + .filter(parser -> parser.getTarget().isAssignableFrom(type)) + .filter(parser -> parser.getStateType().isAssignableFrom(stateKlass)) + .map(IArgParser.Stated.class::cast) + .findFirst() + .orElse(null); + } + + @Override + public T parseStateless(Class type, ICommandArgument arg) throws CommandInvalidTypeException { + IArgParser.Stateless parser = this.getParserStateless(type); + if (parser == null) { + throw new CommandNoParserForTypeException(type); + } + try { + return parser.parseArg(arg); + } catch (Exception exc) { + throw new CommandInvalidTypeException(arg, type.getSimpleName()); + } + } + + @Override + public T parseStated(Class type, Class stateKlass, ICommandArgument arg, S state) throws CommandInvalidTypeException { + IArgParser.Stated parser = this.getParserStated(type, stateKlass); + if (parser == null) { + throw new CommandNoParserForTypeException(type); + } + try { + return parser.parseArg(arg, state); + } catch (Exception exc) { + throw new CommandInvalidTypeException(arg, type.getSimpleName()); + } + } + + @Override + public Registry getRegistry() { + return this.registry; + } +} diff --git a/src/api/java/baritone/api/utils/command/argparser/DefaultArgParsers.java b/src/main/java/baritone/command/argparser/DefaultArgParsers.java similarity index 82% rename from src/api/java/baritone/api/utils/command/argparser/DefaultArgParsers.java rename to src/main/java/baritone/command/argparser/DefaultArgParsers.java index c33f61fbd..77a14bf92 100644 --- a/src/api/java/baritone/api/utils/command/argparser/DefaultArgParsers.java +++ b/src/main/java/baritone/command/argparser/DefaultArgParsers.java @@ -15,9 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.api.utils.command.argparser; +package baritone.command.argparser; -import baritone.api.utils.command.argument.CommandArgument; +import baritone.api.command.argparser.IArgParser; +import baritone.api.command.argument.ICommandArgument; import java.util.Arrays; import java.util.List; @@ -34,8 +35,8 @@ public class DefaultArgParsers { } @Override - public Integer parseArg(CommandArgument arg) throws RuntimeException { - return Integer.parseInt(arg.value); + public Integer parseArg(ICommandArgument arg) throws RuntimeException { + return Integer.parseInt(arg.getValue()); } } @@ -48,8 +49,8 @@ public class DefaultArgParsers { } @Override - public Long parseArg(CommandArgument arg) throws RuntimeException { - return Long.parseLong(arg.value); + public Long parseArg(ICommandArgument arg) throws RuntimeException { + return Long.parseLong(arg.getValue()); } } @@ -62,8 +63,8 @@ public class DefaultArgParsers { } @Override - public Float parseArg(CommandArgument arg) throws RuntimeException { - String value = arg.value; + public Float parseArg(ICommandArgument arg) throws RuntimeException { + String value = arg.getValue(); if (!value.matches("^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)|)$")) { throw new IllegalArgumentException("failed float format check"); } @@ -80,8 +81,8 @@ public class DefaultArgParsers { } @Override - public Double parseArg(CommandArgument arg) throws RuntimeException { - String value = arg.value; + public Double parseArg(ICommandArgument arg) throws RuntimeException { + String value = arg.getValue(); if (!value.matches("^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)|)$")) { throw new IllegalArgumentException("failed double format check"); } @@ -101,8 +102,8 @@ public class DefaultArgParsers { } @Override - public Boolean parseArg(CommandArgument arg) throws RuntimeException { - String value = arg.value; + public Boolean parseArg(ICommandArgument arg) throws RuntimeException { + String value = arg.getValue(); if (TRUTHY_VALUES.contains(value.toLowerCase(Locale.US))) { return true; } else if (FALSY_VALUES.contains(value.toLowerCase(Locale.US))) { diff --git a/src/main/java/baritone/command/argument/CommandArgument.java b/src/main/java/baritone/command/argument/CommandArgument.java new file mode 100644 index 000000000..3ce6cda82 --- /dev/null +++ b/src/main/java/baritone/command/argument/CommandArgument.java @@ -0,0 +1,96 @@ +/* + * 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.command.argument; + +import baritone.command.argparser.ArgParserManager; +import baritone.api.command.argument.ICommandArgument; +import baritone.api.command.exception.CommandInvalidTypeException; + +import java.util.stream.Stream; + +/** + * The default implementation of {@link ICommandArgument} + * + * @author LoganDark + */ +class CommandArgument implements ICommandArgument { + + private final int index; + private final String value; + private final String rawRest; + + CommandArgument(int index, String value, String rawRest) { + this.index = index; + this.value = value; + this.rawRest = rawRest; + } + + @Override + public int getIndex() { + return this.index; + } + + @Override + public String getValue() { + return this.value; + } + + @Override + public String getRawRest() { + return this.rawRest; + } + + @Override + public > E getEnum(Class enumClass) throws CommandInvalidTypeException { + return Stream.of(enumClass.getEnumConstants()) + .filter(e -> e.name().equalsIgnoreCase(value)) + .findFirst() + .orElseThrow(() -> new CommandInvalidTypeException(this, enumClass.getSimpleName())); + } + + @Override + public T getAs(Class type) throws CommandInvalidTypeException { + return ArgParserManager.INSTANCE.parseStateless(type, this); + } + + @Override + public boolean is(Class type) { + try { + getAs(type); + return true; + } catch (Throwable t) { + return false; + } + } + + @SuppressWarnings("UnusedReturnValue") + @Override + public T getAs(Class type, Class stateType, S state) throws CommandInvalidTypeException { + return ArgParserManager.INSTANCE.parseStated(type, stateType, this, state); + } + + @Override + public boolean is(Class type, Class stateType, S state) { + try { + getAs(type, stateType, state); + return true; + } catch (Throwable t) { + return false; + } + } +} diff --git a/src/main/java/baritone/command/argument/CommandArguments.java b/src/main/java/baritone/command/argument/CommandArguments.java new file mode 100644 index 000000000..8d26acb48 --- /dev/null +++ b/src/main/java/baritone/command/argument/CommandArguments.java @@ -0,0 +1,79 @@ +/* + * 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.command.argument; + +import baritone.api.command.argument.ICommandArgument; +import baritone.api.command.exception.CommandInvalidArgumentException; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author LoganDark + */ +public final class CommandArguments { + + private CommandArguments() {} + + private static final Pattern ARG_PATTERN = Pattern.compile("\\S+"); + + /** + * Turn a string into a list of {@link ICommandArgument}s. This is needed because of {@link ICommandArgument#getRawRest()} + * + * @param string The string to convert + * @param preserveEmptyLast If the string ends with whitespace, add an empty {@link ICommandArgument} to the end This + * is useful for tab completion + * @return A list of {@link ICommandArgument}s + */ + public static List from(String string, boolean preserveEmptyLast) { + List args = new ArrayList<>(); + Matcher argMatcher = ARG_PATTERN.matcher(string); + int lastEnd = -1; + while (argMatcher.find()) { + args.add(new CommandArgument( + args.size(), + argMatcher.group(), + string.substring(argMatcher.start()) + )); + lastEnd = argMatcher.end(); + } + if (preserveEmptyLast && lastEnd < string.length()) { + args.add(new CommandArgument(args.size(), "", "")); + } + return args; + } + + /** + * @see #from(String, boolean) + */ + public static List from(String string) { + return from(string, false); + } + + /** + * Returns an "unknown" {@link CommandArgument}. This shouldn't be used unless you absolutely have no information - + * ESPECIALLY not with {@link CommandInvalidArgumentException}s + * + * @return The unknown {@link CommandArgument} + */ + public static CommandArgument unknown() { + return new CommandArgument(-1, "", ""); + } +} diff --git a/src/main/java/baritone/utils/command/defaults/AxisCommand.java b/src/main/java/baritone/command/defaults/AxisCommand.java similarity index 79% rename from src/main/java/baritone/utils/command/defaults/AxisCommand.java rename to src/main/java/baritone/command/defaults/AxisCommand.java index ae52bfb25..09d00ae79 100644 --- a/src/main/java/baritone/utils/command/defaults/AxisCommand.java +++ b/src/main/java/baritone/command/defaults/AxisCommand.java @@ -15,14 +15,14 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalAxis; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -31,11 +31,11 @@ import java.util.stream.Stream; public class AxisCommand extends Command { public AxisCommand(IBaritone baritone) { - super(baritone, Arrays.asList("axis", "highway")); + super(baritone, "axis", "highway"); } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); Goal goal = new GoalAxis(); baritone.getCustomGoalProcess().setGoal(goal); @@ -43,7 +43,7 @@ public class AxisCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/BlacklistCommand.java b/src/main/java/baritone/command/defaults/BlacklistCommand.java similarity index 81% rename from src/main/java/baritone/utils/command/defaults/BlacklistCommand.java rename to src/main/java/baritone/command/defaults/BlacklistCommand.java index 21551782b..5069f4348 100644 --- a/src/main/java/baritone/utils/command/defaults/BlacklistCommand.java +++ b/src/main/java/baritone/command/defaults/BlacklistCommand.java @@ -15,14 +15,14 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.process.IGetToBlockProcess; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidStateException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidStateException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -35,7 +35,7 @@ public class BlacklistCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); IGetToBlockProcess proc = baritone.getGetToBlockProcess(); if (!proc.isActive()) { @@ -49,7 +49,7 @@ public class BlacklistCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/BuildCommand.java b/src/main/java/baritone/command/defaults/BuildCommand.java similarity index 82% rename from src/main/java/baritone/utils/command/defaults/BuildCommand.java rename to src/main/java/baritone/command/defaults/BuildCommand.java index 9212bd36c..01f6fd82a 100644 --- a/src/main/java/baritone/utils/command/defaults/BuildCommand.java +++ b/src/main/java/baritone/command/defaults/BuildCommand.java @@ -15,16 +15,16 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.datatypes.RelativeBlockPos; -import baritone.api.utils.command.datatypes.RelativeFile; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidStateException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.datatypes.RelativeBlockPos; +import baritone.api.command.datatypes.RelativeFile; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidStateException; +import baritone.api.command.helpers.arguments.IArgConsumer; import net.minecraft.client.Minecraft; import java.io.File; @@ -42,7 +42,7 @@ public class BuildCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile(); if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) { file = new File(file.getAbsolutePath() + ".schematic"); @@ -64,7 +64,7 @@ public class BuildCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) throws CommandException { + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { if (args.hasExactlyOne()) { return RelativeFile.tabComplete(args, schematicsDir); } else if (args.has(2)) { diff --git a/src/main/java/baritone/utils/command/defaults/CancelCommand.java b/src/main/java/baritone/command/defaults/CancelCommand.java similarity index 77% rename from src/main/java/baritone/utils/command/defaults/CancelCommand.java rename to src/main/java/baritone/command/defaults/CancelCommand.java index a4ef4cc7b..aff839ae8 100644 --- a/src/main/java/baritone/utils/command/defaults/CancelCommand.java +++ b/src/main/java/baritone/command/defaults/CancelCommand.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -29,18 +29,18 @@ import java.util.stream.Stream; public class CancelCommand extends Command { public CancelCommand(IBaritone baritone) { - super(baritone, Arrays.asList("cancel", "stop")); + super(baritone, "cancel", "stop"); } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); baritone.getPathingBehavior().cancelEverything(); logDirect("ok canceled"); } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/ChestsCommand.java b/src/main/java/baritone/command/defaults/ChestsCommand.java similarity index 84% rename from src/main/java/baritone/utils/command/defaults/ChestsCommand.java rename to src/main/java/baritone/command/defaults/ChestsCommand.java index d4101a629..c3755b5a2 100644 --- a/src/main/java/baritone/utils/command/defaults/ChestsCommand.java +++ b/src/main/java/baritone/command/defaults/ChestsCommand.java @@ -15,15 +15,15 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.cache.IRememberedInventory; import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidStateException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidStateException; +import baritone.api.command.helpers.arguments.IArgConsumer; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; @@ -41,7 +41,7 @@ public class ChestsCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); Set> entries = ctx.worldData().getContainerMemory().getRememberedInventories().entrySet(); @@ -62,7 +62,7 @@ public class ChestsCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/ClickCommand.java b/src/main/java/baritone/command/defaults/ClickCommand.java similarity index 79% rename from src/main/java/baritone/utils/command/defaults/ClickCommand.java rename to src/main/java/baritone/command/defaults/ClickCommand.java index e5180b2ff..95b04f52c 100644 --- a/src/main/java/baritone/utils/command/defaults/ClickCommand.java +++ b/src/main/java/baritone/command/defaults/ClickCommand.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -33,14 +33,14 @@ public class ClickCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); baritone.openClick(); logDirect("aight dude"); } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/ComeCommand.java b/src/main/java/baritone/command/defaults/ComeCommand.java similarity index 81% rename from src/main/java/baritone/utils/command/defaults/ComeCommand.java rename to src/main/java/baritone/command/defaults/ComeCommand.java index bbefeb43a..9b336a252 100644 --- a/src/main/java/baritone/utils/command/defaults/ComeCommand.java +++ b/src/main/java/baritone/command/defaults/ComeCommand.java @@ -15,14 +15,14 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.pathing.goals.GoalBlock; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidStateException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidStateException; +import baritone.api.command.helpers.arguments.IArgConsumer; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; @@ -37,7 +37,7 @@ public class ComeCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); Entity entity = mc.getRenderViewEntity(); if (entity == null) { @@ -48,7 +48,7 @@ public class ComeCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/CommandAlias.java b/src/main/java/baritone/command/defaults/CommandAlias.java similarity index 84% rename from src/main/java/baritone/utils/command/defaults/CommandAlias.java rename to src/main/java/baritone/command/defaults/CommandAlias.java index cbd8ac77c..08b1ca05d 100644 --- a/src/main/java/baritone/utils/command/defaults/CommandAlias.java +++ b/src/main/java/baritone/command/defaults/CommandAlias.java @@ -15,11 +15,11 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Collections; import java.util.List; @@ -31,7 +31,7 @@ public class CommandAlias extends Command { public final String target; public CommandAlias(IBaritone baritone, List names, String shortDesc, String target) { - super(baritone, names); + super(baritone, names.toArray(new String[0])); this.shortDesc = shortDesc; this.target = target; } @@ -43,12 +43,12 @@ public class CommandAlias extends Command { } @Override - protected void executed(String label, ArgConsumer args) { + public void execute(String label, IArgConsumer args) { this.baritone.getCommandManager().execute(String.format("%s %s", target, args.rawRest())); } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return this.baritone.getCommandManager().tabComplete(String.format("%s %s", target, args.rawRest())); } diff --git a/src/main/java/baritone/utils/command/defaults/DefaultCommands.java b/src/main/java/baritone/command/defaults/DefaultCommands.java similarity index 96% rename from src/main/java/baritone/utils/command/defaults/DefaultCommands.java rename to src/main/java/baritone/command/defaults/DefaultCommands.java index 3f8e39087..dd1a3004e 100644 --- a/src/main/java/baritone/utils/command/defaults/DefaultCommands.java +++ b/src/main/java/baritone/command/defaults/DefaultCommands.java @@ -15,10 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; +import baritone.api.command.Command; import java.util.*; @@ -34,6 +34,7 @@ public final class DefaultCommands { new CommandAlias(baritone, Arrays.asList("modified", "mod", "baritone", "modifiedsettings"), "List modified settings", "set modified"), new CommandAlias(baritone, "reset", "Reset all settings or just one", "set reset"), new GoalCommand(baritone), + new GotoCommand(baritone), new PathCommand(baritone), new ProcCommand(baritone), new VersionCommand(baritone), diff --git a/src/main/java/baritone/utils/command/defaults/ExploreCommand.java b/src/main/java/baritone/command/defaults/ExploreCommand.java similarity index 83% rename from src/main/java/baritone/utils/command/defaults/ExploreCommand.java rename to src/main/java/baritone/command/defaults/ExploreCommand.java index dc156d0e0..a2054cc78 100644 --- a/src/main/java/baritone/utils/command/defaults/ExploreCommand.java +++ b/src/main/java/baritone/command/defaults/ExploreCommand.java @@ -15,14 +15,14 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.pathing.goals.GoalXZ; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.datatypes.RelativeGoalXZ; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.datatypes.RelativeGoalXZ; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -35,7 +35,7 @@ public class ExploreCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { if (args.hasAny()) { args.requireExactly(2); } else { @@ -49,7 +49,7 @@ public class ExploreCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { if (args.hasAtMost(2)) { return args.tabCompleteDatatype(RelativeGoalXZ.INSTANCE); } diff --git a/src/main/java/baritone/utils/command/defaults/ExploreFilterCommand.java b/src/main/java/baritone/command/defaults/ExploreFilterCommand.java similarity index 83% rename from src/main/java/baritone/utils/command/defaults/ExploreFilterCommand.java rename to src/main/java/baritone/command/defaults/ExploreFilterCommand.java index 4d75d1b49..a1c5074a3 100644 --- a/src/main/java/baritone/utils/command/defaults/ExploreFilterCommand.java +++ b/src/main/java/baritone/command/defaults/ExploreFilterCommand.java @@ -15,15 +15,15 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.datatypes.RelativeFile; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidStateException; -import baritone.api.utils.command.exception.CommandInvalidTypeException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.datatypes.RelativeFile; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidStateException; +import baritone.api.command.exception.CommandInvalidTypeException; +import baritone.api.command.helpers.arguments.IArgConsumer; import com.google.gson.JsonSyntaxException; import java.io.File; @@ -39,7 +39,7 @@ public class ExploreFilterCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(2); File file = args.getDatatypePost(RelativeFile.INSTANCE, mc.gameDir.getAbsoluteFile().getParentFile()); boolean invert = false; @@ -63,7 +63,7 @@ public class ExploreFilterCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) throws CommandException { + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { if (args.hasExactlyOne()) { return RelativeFile.tabComplete(args, RelativeFile.gameDir()); } diff --git a/src/main/java/baritone/utils/command/defaults/FarmCommand.java b/src/main/java/baritone/command/defaults/FarmCommand.java similarity index 80% rename from src/main/java/baritone/utils/command/defaults/FarmCommand.java rename to src/main/java/baritone/command/defaults/FarmCommand.java index 1f803ec60..9151852c1 100644 --- a/src/main/java/baritone/utils/command/defaults/FarmCommand.java +++ b/src/main/java/baritone/command/defaults/FarmCommand.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -33,14 +33,14 @@ public class FarmCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); baritone.getFarmProcess().farm(); logDirect("Farming"); } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/FindCommand.java b/src/main/java/baritone/command/defaults/FindCommand.java similarity index 84% rename from src/main/java/baritone/utils/command/defaults/FindCommand.java rename to src/main/java/baritone/command/defaults/FindCommand.java index 53046b159..0e5ada850 100644 --- a/src/main/java/baritone/utils/command/defaults/FindCommand.java +++ b/src/main/java/baritone/command/defaults/FindCommand.java @@ -15,14 +15,14 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.datatypes.BlockById; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.datatypes.BlockById; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import net.minecraft.block.Block; import net.minecraft.util.registry.IRegistry; @@ -38,7 +38,7 @@ public class FindCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { List toFind = new ArrayList<>(); while (args.hasAny()) { toFind.add(args.getDatatypeFor(BlockById.INSTANCE)); @@ -60,7 +60,7 @@ public class FindCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return args.tabCompleteDatatype(BlockById.INSTANCE); } diff --git a/src/main/java/baritone/utils/command/defaults/FollowCommand.java b/src/main/java/baritone/command/defaults/FollowCommand.java similarity index 88% rename from src/main/java/baritone/utils/command/defaults/FollowCommand.java rename to src/main/java/baritone/command/defaults/FollowCommand.java index aa2d93ef1..53bd0b6d5 100644 --- a/src/main/java/baritone/utils/command/defaults/FollowCommand.java +++ b/src/main/java/baritone/command/defaults/FollowCommand.java @@ -15,16 +15,16 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.datatypes.EntityClassById; -import baritone.api.utils.command.datatypes.IDatatypeFor; -import baritone.api.utils.command.datatypes.NearbyPlayer; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.Command; +import baritone.api.command.datatypes.EntityClassById; +import baritone.api.command.datatypes.IDatatypeFor; +import baritone.api.command.datatypes.NearbyPlayer; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityType; @@ -43,7 +43,7 @@ public class FollowCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMin(1); FollowGroup group; FollowList list; @@ -89,7 +89,7 @@ public class FollowCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) throws CommandException { + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { if (args.hasExactlyOne()) { return new TabCompleteHelper() .append(FollowGroup.class) diff --git a/src/main/java/baritone/utils/command/defaults/ForceCancelCommand.java b/src/main/java/baritone/command/defaults/ForceCancelCommand.java similarity index 81% rename from src/main/java/baritone/utils/command/defaults/ForceCancelCommand.java rename to src/main/java/baritone/command/defaults/ForceCancelCommand.java index 3de8a056b..f92134822 100644 --- a/src/main/java/baritone/utils/command/defaults/ForceCancelCommand.java +++ b/src/main/java/baritone/command/defaults/ForceCancelCommand.java @@ -15,13 +15,13 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.behavior.IPathingBehavior; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -34,7 +34,7 @@ public class ForceCancelCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); IPathingBehavior pathingBehavior = baritone.getPathingBehavior(); pathingBehavior.cancelEverything(); @@ -43,7 +43,7 @@ public class ForceCancelCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/GcCommand.java b/src/main/java/baritone/command/defaults/GcCommand.java similarity index 79% rename from src/main/java/baritone/utils/command/defaults/GcCommand.java rename to src/main/java/baritone/command/defaults/GcCommand.java index c2e7952cd..c64703e91 100644 --- a/src/main/java/baritone/utils/command/defaults/GcCommand.java +++ b/src/main/java/baritone/command/defaults/GcCommand.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -33,14 +33,14 @@ public class GcCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); System.gc(); logDirect("ok called System.gc()"); } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/GoalCommand.java b/src/main/java/baritone/command/defaults/GoalCommand.java similarity index 84% rename from src/main/java/baritone/utils/command/defaults/GoalCommand.java rename to src/main/java/baritone/command/defaults/GoalCommand.java index 3f7601117..46b506959 100644 --- a/src/main/java/baritone/utils/command/defaults/GoalCommand.java +++ b/src/main/java/baritone/command/defaults/GoalCommand.java @@ -15,18 +15,18 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.pathing.goals.Goal; import baritone.api.process.ICustomGoalProcess; import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.datatypes.RelativeCoordinate; -import baritone.api.utils.command.datatypes.RelativeGoal; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.Command; +import baritone.api.command.datatypes.RelativeCoordinate; +import baritone.api.command.datatypes.RelativeGoal; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import java.util.Arrays; import java.util.List; @@ -39,7 +39,7 @@ public class GoalCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { ICustomGoalProcess goalProcess = baritone.getCustomGoalProcess(); if (args.hasAny() && Arrays.asList("reset", "clear", "none").contains(args.peekString())) { args.requireMax(1); @@ -59,7 +59,7 @@ public class GoalCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) throws CommandException { + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { TabCompleteHelper helper = new TabCompleteHelper(); if (args.hasExactlyOne()) { helper.append("reset", "clear", "none", "~"); diff --git a/src/main/java/baritone/command/defaults/GotoCommand.java b/src/main/java/baritone/command/defaults/GotoCommand.java new file mode 100644 index 000000000..9659fff87 --- /dev/null +++ b/src/main/java/baritone/command/defaults/GotoCommand.java @@ -0,0 +1,82 @@ +/* + * 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.command.defaults; + +import baritone.api.IBaritone; +import baritone.api.command.Command; +import baritone.api.command.datatypes.BlockById; +import baritone.api.command.datatypes.ForBlockOptionalMeta; +import baritone.api.command.datatypes.RelativeCoordinate; +import baritone.api.command.datatypes.RelativeGoal; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.pathing.goals.Goal; +import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.BlockOptionalMeta; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +public class GotoCommand extends Command { + + protected GotoCommand(IBaritone baritone) { + super(baritone, "goto"); + } + + @Override + public void execute(String label, IArgConsumer args) throws CommandException { + if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) { // if we have a numeric first argument... + BetterBlockPos origin = baritone.getPlayerContext().playerFeet(); + Goal goal = args.getDatatypePostOrNull(RelativeGoal.INSTANCE, origin); + logDirect(String.format("Going to: %s", goal.toString())); + baritone.getCustomGoalProcess().setGoalAndPath(goal); + return; + } + args.requireMax(1); + BlockOptionalMeta destination = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE); + baritone.getGetToBlockProcess().getToBlock(destination); + } + + @Override + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { + // since it's either a goal or a block, I don't think we can tab complete properly? + // so just tab complete for the block variant + return args.tabCompleteDatatype(BlockById.INSTANCE); + } + + @Override + public String getShortDesc() { + return "Go to a coordinate or block"; + } + + @Override + public List getLongDesc() { + return Arrays.asList( + "The got command tells Baritone to head towards a given goal or block.", + "", + "Wherever a coordinate is expected, you can use ~ just like in regular Minecraft commands. Or, you can just use regular numbers.", + "", + "Usage:", + "> goto - Go to a block, wherever it is in the world", + "> goto - Go to a Y level", + "> goto - Go to an X,Z position", + "> goto - Go to an X,Y,Z position" + ); + } +} diff --git a/src/main/java/baritone/utils/command/defaults/HelpCommand.java b/src/main/java/baritone/command/defaults/HelpCommand.java similarity index 84% rename from src/main/java/baritone/utils/command/defaults/HelpCommand.java rename to src/main/java/baritone/command/defaults/HelpCommand.java index a9d0e1047..fe3c48082 100644 --- a/src/main/java/baritone/utils/command/defaults/HelpCommand.java +++ b/src/main/java/baritone/command/defaults/HelpCommand.java @@ -15,15 +15,15 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandNotFoundException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import baritone.api.utils.command.helpers.pagination.Paginator; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandNotFoundException; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.command.helpers.pagination.Paginator; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; @@ -35,16 +35,16 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; +import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; public class HelpCommand extends Command { public HelpCommand(IBaritone baritone) { - super(baritone, Arrays.asList("help", "?")); + super(baritone, "help", "?"); } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(1); if (!args.hasAny() || args.is(Integer.class)) { Paginator.paginate( @@ -55,8 +55,8 @@ public class HelpCommand extends Command { ), () -> logDirect("All Baritone commands (clickable):"), command -> { - String names = String.join("/", command.names); - String name = command.names.get(0); + String names = String.join("/", command.getNames()); + String name = command.getNames().get(0); ITextComponent shortDescComponent = new TextComponentString(" - " + command.getShortDesc()); shortDescComponent.getStyle().setColor(TextFormatting.DARK_GRAY); ITextComponent namesComponent = new TextComponentString(names); @@ -66,7 +66,7 @@ public class HelpCommand extends Command { hoverComponent.appendSibling(namesComponent); hoverComponent.appendText("\n" + command.getShortDesc()); hoverComponent.appendText("\n\nClick to view full help"); - String clickCommand = FORCE_COMMAND_PREFIX + String.format("%s %s", label, command.names.get(0)); + String clickCommand = FORCE_COMMAND_PREFIX + String.format("%s %s", label, command.getNames().get(0)); ITextComponent component = new TextComponentString(name); component.getStyle().setColor(TextFormatting.GRAY); component.appendSibling(shortDescComponent); @@ -83,7 +83,7 @@ public class HelpCommand extends Command { if (command == null) { throw new CommandNotFoundException(commandName); } - logDirect(String.format("%s - %s", String.join(" / ", command.names), command.getShortDesc())); + logDirect(String.format("%s - %s", String.join(" / ", command.getNames()), command.getShortDesc())); logDirect(""); command.getLongDesc().forEach(this::logDirect); logDirect(""); @@ -97,7 +97,7 @@ public class HelpCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) throws CommandException { + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { if (args.hasExactlyOne()) { return new TabCompleteHelper() .addCommands(this.baritone.getCommandManager()) diff --git a/src/main/java/baritone/utils/command/defaults/InvertCommand.java b/src/main/java/baritone/command/defaults/InvertCommand.java similarity index 82% rename from src/main/java/baritone/utils/command/defaults/InvertCommand.java rename to src/main/java/baritone/command/defaults/InvertCommand.java index f52e6226c..ba79a4a94 100644 --- a/src/main/java/baritone/utils/command/defaults/InvertCommand.java +++ b/src/main/java/baritone/command/defaults/InvertCommand.java @@ -15,16 +15,16 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalInverted; import baritone.api.process.ICustomGoalProcess; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidStateException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidStateException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -37,7 +37,7 @@ public class InvertCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess(); Goal goal; @@ -54,7 +54,7 @@ public class InvertCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/MineCommand.java b/src/main/java/baritone/command/defaults/MineCommand.java similarity index 82% rename from src/main/java/baritone/utils/command/defaults/MineCommand.java rename to src/main/java/baritone/command/defaults/MineCommand.java index e77c3bd75..d2846e0ae 100644 --- a/src/main/java/baritone/utils/command/defaults/MineCommand.java +++ b/src/main/java/baritone/command/defaults/MineCommand.java @@ -15,15 +15,15 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.utils.BlockOptionalMeta; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.datatypes.BlockById; -import baritone.api.utils.command.datatypes.ForBlockOptionalMeta; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.datatypes.BlockById; +import baritone.api.command.datatypes.ForBlockOptionalMeta; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.cache.WorldScanner; import java.util.ArrayList; @@ -38,7 +38,7 @@ public class MineCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { int quantity = args.getAsOrDefault(Integer.class, 0); args.requireMin(1); List boms = new ArrayList<>(); @@ -51,7 +51,7 @@ public class MineCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return args.tabCompleteDatatype(BlockById.INSTANCE); } diff --git a/src/main/java/baritone/command/defaults/PathCommand.java b/src/main/java/baritone/command/defaults/PathCommand.java new file mode 100644 index 000000000..fff61a70a --- /dev/null +++ b/src/main/java/baritone/command/defaults/PathCommand.java @@ -0,0 +1,65 @@ +/* + * 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.command.defaults; + +import baritone.api.IBaritone; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.process.ICustomGoalProcess; +import baritone.cache.WorldScanner; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +public class PathCommand extends Command { + + public PathCommand(IBaritone baritone) { + super(baritone, "path"); + } + + @Override + public void execute(String label, IArgConsumer args) throws CommandException { + ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess(); + args.requireMax(0); + WorldScanner.INSTANCE.repack(ctx); + customGoalProcess.path(); + logDirect("Now pathing"); + } + + @Override + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { + return Stream.empty(); + } + + @Override + public String getShortDesc() { + return "Start heading towards the goal"; + } + + @Override + public List getLongDesc() { + return Arrays.asList( + "The path command tells Baritone to head towards the current goal.", + "", + "Usage:", + "> path - Start the pathing." + ); + } +} diff --git a/src/main/java/baritone/utils/command/defaults/PauseResumeCommands.java b/src/main/java/baritone/command/defaults/PauseResumeCommands.java similarity index 86% rename from src/main/java/baritone/utils/command/defaults/PauseResumeCommands.java rename to src/main/java/baritone/command/defaults/PauseResumeCommands.java index bc3c392ac..11e678820 100644 --- a/src/main/java/baritone/utils/command/defaults/PauseResumeCommands.java +++ b/src/main/java/baritone/command/defaults/PauseResumeCommands.java @@ -15,16 +15,16 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.process.IBaritoneProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidStateException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidStateException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -79,7 +79,7 @@ public class PauseResumeCommands { ); pauseCommand = new Command(baritone, "pause") { @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); if (paused[0]) { throw new CommandInvalidStateException("Already paused"); @@ -89,7 +89,7 @@ public class PauseResumeCommands { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } @@ -112,8 +112,9 @@ public class PauseResumeCommands { }; resumeCommand = new Command(baritone, "resume") { @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); + baritone.getBuilderProcess().resume(); if (!paused[0]) { throw new CommandInvalidStateException("Not paused"); } @@ -122,7 +123,7 @@ public class PauseResumeCommands { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } @@ -143,13 +144,13 @@ public class PauseResumeCommands { }; pausedCommand = new Command(baritone, "paused") { @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); logDirect(String.format("Baritone is %spaused", paused[0] ? "" : "not ")); } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/ProcCommand.java b/src/main/java/baritone/command/defaults/ProcCommand.java similarity index 85% rename from src/main/java/baritone/utils/command/defaults/ProcCommand.java rename to src/main/java/baritone/command/defaults/ProcCommand.java index 40d8e72b5..794a44802 100644 --- a/src/main/java/baritone/utils/command/defaults/ProcCommand.java +++ b/src/main/java/baritone/command/defaults/ProcCommand.java @@ -15,16 +15,16 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.pathing.calc.IPathingControlManager; import baritone.api.process.IBaritoneProcess; import baritone.api.process.PathingCommand; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidStateException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidStateException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -37,7 +37,7 @@ public class ProcCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); IPathingControlManager pathingControlManager = baritone.getPathingControlManager(); IBaritoneProcess process = pathingControlManager.mostRecentInControl().orElse(null); @@ -62,7 +62,7 @@ public class ProcCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/ReloadAllCommand.java b/src/main/java/baritone/command/defaults/ReloadAllCommand.java similarity index 80% rename from src/main/java/baritone/utils/command/defaults/ReloadAllCommand.java rename to src/main/java/baritone/command/defaults/ReloadAllCommand.java index c16000f73..9f4ddd83d 100644 --- a/src/main/java/baritone/utils/command/defaults/ReloadAllCommand.java +++ b/src/main/java/baritone/command/defaults/ReloadAllCommand.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -33,14 +33,14 @@ public class ReloadAllCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); ctx.worldData().getCachedWorld().reloadAllFromDisk(); logDirect("Reloaded"); } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/RenderCommand.java b/src/main/java/baritone/command/defaults/RenderCommand.java similarity index 83% rename from src/main/java/baritone/utils/command/defaults/RenderCommand.java rename to src/main/java/baritone/command/defaults/RenderCommand.java index 66926d23f..d872228a0 100644 --- a/src/main/java/baritone/utils/command/defaults/RenderCommand.java +++ b/src/main/java/baritone/command/defaults/RenderCommand.java @@ -15,13 +15,13 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -34,7 +34,7 @@ public class RenderCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); BetterBlockPos origin = ctx.playerFeet(); int renderDistance = (mc.gameSettings.renderDistanceChunks + 1) * 16; @@ -50,7 +50,7 @@ public class RenderCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/RepackCommand.java b/src/main/java/baritone/command/defaults/RepackCommand.java similarity index 77% rename from src/main/java/baritone/utils/command/defaults/RepackCommand.java rename to src/main/java/baritone/command/defaults/RepackCommand.java index bd918f097..d42bd95ae 100644 --- a/src/main/java/baritone/utils/command/defaults/RepackCommand.java +++ b/src/main/java/baritone/command/defaults/RepackCommand.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import baritone.cache.WorldScanner; import java.util.Arrays; @@ -30,17 +30,17 @@ import java.util.stream.Stream; public class RepackCommand extends Command { public RepackCommand(IBaritone baritone) { - super(baritone, Arrays.asList("repack", "rescan")); + super(baritone, "repack", "rescan"); } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); logDirect(String.format("Queued %d chunks for repacking", WorldScanner.INSTANCE.repack(ctx))); } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/SaveAllCommand.java b/src/main/java/baritone/command/defaults/SaveAllCommand.java similarity index 79% rename from src/main/java/baritone/utils/command/defaults/SaveAllCommand.java rename to src/main/java/baritone/command/defaults/SaveAllCommand.java index 8343f7533..7df2e320c 100644 --- a/src/main/java/baritone/utils/command/defaults/SaveAllCommand.java +++ b/src/main/java/baritone/command/defaults/SaveAllCommand.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -33,14 +33,14 @@ public class SaveAllCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); ctx.worldData().getCachedWorld().save(); logDirect("Saved"); } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/SchematicaCommand.java b/src/main/java/baritone/command/defaults/SchematicaCommand.java similarity index 79% rename from src/main/java/baritone/utils/command/defaults/SchematicaCommand.java rename to src/main/java/baritone/command/defaults/SchematicaCommand.java index 91e31daa4..5f659d1fd 100644 --- a/src/main/java/baritone/utils/command/defaults/SchematicaCommand.java +++ b/src/main/java/baritone/command/defaults/SchematicaCommand.java @@ -15,12 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -33,13 +33,13 @@ public class SchematicaCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); baritone.getBuilderProcess().buildOpenSchematic(); } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java similarity index 94% rename from src/main/java/baritone/utils/command/defaults/SelCommand.java rename to src/main/java/baritone/command/defaults/SelCommand.java index d9899f429..342d0a314 100644 --- a/src/main/java/baritone/utils/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.Baritone; import baritone.api.IBaritone; @@ -28,15 +28,15 @@ import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BlockOptionalMeta; import baritone.api.utils.BlockOptionalMetaLookup; import baritone.api.utils.ISchematic; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.datatypes.ForBlockOptionalMeta; -import baritone.api.utils.command.datatypes.ForEnumFacing; -import baritone.api.utils.command.datatypes.RelativeBlockPos; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidStateException; -import baritone.api.utils.command.exception.CommandInvalidTypeException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.Command; +import baritone.api.command.datatypes.ForBlockOptionalMeta; +import baritone.api.command.datatypes.ForEnumFacing; +import baritone.api.command.datatypes.RelativeBlockPos; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidStateException; +import baritone.api.command.exception.CommandInvalidTypeException; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import baritone.utils.IRenderer; import net.minecraft.init.Blocks; import net.minecraft.util.EnumFacing; @@ -56,7 +56,7 @@ public class SelCommand extends Command { private BetterBlockPos pos1 = null; public SelCommand(IBaritone baritone) { - super(baritone, Arrays.asList("sel", "selection", "s")); + super(baritone, "sel", "selection", "s"); baritone.getGameEventHandler().registerEventListener(new AbstractGameEventListener() { @Override public void onRenderPass(RenderEvent event) { @@ -75,7 +75,7 @@ public class SelCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { Action action = Action.getByName(args.getString()); if (action == null) { throw new CommandInvalidTypeException(args.consumed(), "an action"); @@ -186,7 +186,7 @@ public class SelCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) throws CommandException { + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { if (args.hasExactlyOne()) { return new TabCompleteHelper() .append(Action.getAllNames()) diff --git a/src/main/java/baritone/utils/command/defaults/SetCommand.java b/src/main/java/baritone/command/defaults/SetCommand.java similarity index 94% rename from src/main/java/baritone/utils/command/defaults/SetCommand.java rename to src/main/java/baritone/command/defaults/SetCommand.java index 48c4580f5..280f56eac 100644 --- a/src/main/java/baritone/utils/command/defaults/SetCommand.java +++ b/src/main/java/baritone/command/defaults/SetCommand.java @@ -15,18 +15,18 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.Baritone; import baritone.api.IBaritone; import baritone.api.Settings; import baritone.api.utils.SettingsUtil; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidTypeException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import baritone.api.utils.command.helpers.pagination.Paginator; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidTypeException; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.command.helpers.pagination.Paginator; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; @@ -41,16 +41,16 @@ import java.util.stream.Stream; import static baritone.api.utils.SettingsUtil.settingTypeToString; import static baritone.api.utils.SettingsUtil.settingValueToString; -import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; +import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; public class SetCommand extends Command { public SetCommand(IBaritone baritone) { - super(baritone, Arrays.asList("set", "setting", "settings")); + super(baritone, "set", "setting", "settings"); } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { String arg = args.hasAny() ? args.getString().toLowerCase(Locale.US) : "list"; if (Arrays.asList("s", "save").contains(arg)) { SettingsUtil.save(Baritone.settings()); @@ -186,7 +186,7 @@ public class SetCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) throws CommandException { + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { if (args.hasAny()) { String arg = args.getString(); if (args.hasExactlyOne() && !Arrays.asList("s", "save").contains(args.peekString().toLowerCase(Locale.US))) { diff --git a/src/main/java/baritone/utils/command/defaults/ThisWayCommand.java b/src/main/java/baritone/command/defaults/ThisWayCommand.java similarity index 80% rename from src/main/java/baritone/utils/command/defaults/ThisWayCommand.java rename to src/main/java/baritone/command/defaults/ThisWayCommand.java index 4c6f35226..9ff42f42e 100644 --- a/src/main/java/baritone/utils/command/defaults/ThisWayCommand.java +++ b/src/main/java/baritone/command/defaults/ThisWayCommand.java @@ -15,13 +15,13 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.pathing.goals.GoalXZ; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -30,11 +30,11 @@ import java.util.stream.Stream; public class ThisWayCommand extends Command { public ThisWayCommand(IBaritone baritone) { - super(baritone, Arrays.asList("thisway", "forward")); + super(baritone, "thisway", "forward"); } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireExactly(1); GoalXZ goal = GoalXZ.fromDirection( ctx.playerFeetAsVec(), @@ -46,7 +46,7 @@ public class ThisWayCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/TunnelCommand.java b/src/main/java/baritone/command/defaults/TunnelCommand.java similarity index 83% rename from src/main/java/baritone/utils/command/defaults/TunnelCommand.java rename to src/main/java/baritone/command/defaults/TunnelCommand.java index 588287d64..e7830c05d 100644 --- a/src/main/java/baritone/utils/command/defaults/TunnelCommand.java +++ b/src/main/java/baritone/command/defaults/TunnelCommand.java @@ -15,14 +15,14 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalStrictDirection; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -35,7 +35,7 @@ public class TunnelCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); Goal goal = new GoalStrictDirection( ctx.playerFeet(), @@ -46,7 +46,7 @@ public class TunnelCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/VersionCommand.java b/src/main/java/baritone/command/defaults/VersionCommand.java similarity index 79% rename from src/main/java/baritone/utils/command/defaults/VersionCommand.java rename to src/main/java/baritone/command/defaults/VersionCommand.java index fe53f523e..6e063b0f2 100644 --- a/src/main/java/baritone/utils/command/defaults/VersionCommand.java +++ b/src/main/java/baritone/command/defaults/VersionCommand.java @@ -15,13 +15,13 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidStateException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; +import baritone.api.command.Command; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidStateException; +import baritone.api.command.helpers.arguments.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -34,7 +34,7 @@ public class VersionCommand extends Command { } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); String version = getClass().getPackage().getImplementationVersion(); if (version == null) { @@ -45,7 +45,7 @@ public class VersionCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) { + public Stream tabComplete(String label, IArgConsumer args) { return Stream.empty(); } diff --git a/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java b/src/main/java/baritone/command/defaults/WaypointsCommand.java similarity index 93% rename from src/main/java/baritone/utils/command/defaults/WaypointsCommand.java rename to src/main/java/baritone/command/defaults/WaypointsCommand.java index 01f5817e9..c61f6557e 100644 --- a/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java +++ b/src/main/java/baritone/command/defaults/WaypointsCommand.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.utils.command.defaults; +package baritone.command.defaults; import baritone.api.IBaritone; import baritone.api.cache.IWaypoint; @@ -23,15 +23,15 @@ import baritone.api.cache.Waypoint; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalBlock; import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.datatypes.ForWaypoints; -import baritone.api.utils.command.datatypes.RelativeBlockPos; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidStateException; -import baritone.api.utils.command.exception.CommandInvalidTypeException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import baritone.api.utils.command.helpers.pagination.Paginator; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.Command; +import baritone.api.command.datatypes.ForWaypoints; +import baritone.api.command.datatypes.RelativeBlockPos; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidStateException; +import baritone.api.command.exception.CommandInvalidTypeException; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.command.helpers.pagination.Paginator; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; @@ -43,16 +43,16 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Stream; -import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; +import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; public class WaypointsCommand extends Command { public WaypointsCommand(IBaritone baritone) { - super(baritone, Arrays.asList("waypoints", "waypoint", "wp")); + super(baritone, "waypoints", "waypoint", "wp"); } @Override - protected void executed(String label, ArgConsumer args) throws CommandException { + public void execute(String label, IArgConsumer args) throws CommandException { Action action = args.hasAny() ? Action.getByName(args.getString()) : Action.LIST; if (action == null) { throw new CommandInvalidTypeException(args.consumed(), "an action"); @@ -241,7 +241,7 @@ public class WaypointsCommand extends Command { } @Override - protected Stream tabCompleted(String label, ArgConsumer args) throws CommandException { + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { if (args.hasAny()) { if (args.hasExactlyOne()) { return new TabCompleteHelper() diff --git a/src/main/java/baritone/command/helpers/arguments/ArgConsumer.java b/src/main/java/baritone/command/helpers/arguments/ArgConsumer.java new file mode 100644 index 000000000..c6a4fb0c7 --- /dev/null +++ b/src/main/java/baritone/command/helpers/arguments/ArgConsumer.java @@ -0,0 +1,444 @@ +/* + * 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.command.helpers.arguments; + +import baritone.api.IBaritone; +import baritone.api.command.argument.ICommandArgument; +import baritone.api.command.datatypes.IDatatype; +import baritone.api.command.datatypes.IDatatypeContext; +import baritone.api.command.datatypes.IDatatypeFor; +import baritone.api.command.datatypes.IDatatypePost; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidTypeException; +import baritone.api.command.exception.CommandNotEnoughArgumentsException; +import baritone.api.command.exception.CommandTooManyArgumentsException; +import baritone.api.command.helpers.arguments.IArgConsumer; +import baritone.api.command.manager.ICommandManager; +import baritone.command.argument.CommandArguments; + +import java.util.ArrayList; +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Stream; + +public class ArgConsumer implements IArgConsumer { + + /** + * The parent {@link ICommandManager} for this {@link IArgConsumer}}. Used by {@link #context}. + */ + private final ICommandManager manager; + + /** + * The {@link IDatatypeContext} instance for this {@link IArgConsumer}}, passed to + * datatypes when an operation is performed upon them. + * + * @see IDatatype + * @see IDatatypeContext + */ + private final IDatatypeContext context; + + /** + * The list of arguments in this ArgConsumer + */ + private final LinkedList args; + + /** + * The list of consumed arguments for this ArgConsumer. The most recently consumed argument is the last one + */ + private final Deque consumed; + + private ArgConsumer(ICommandManager manager, Deque args, Deque consumed) { + this.manager = manager; + this.context = this.new Context(); + this.args = new LinkedList<>(args); + this.consumed = new LinkedList<>(consumed); + } + + public ArgConsumer(ICommandManager manager, List args) { + this(manager, new LinkedList<>(args), new LinkedList<>()); + } + + @Override + public LinkedList getArgs() { + return this.args; + } + + @Override + public Deque getConsumed() { + return this.consumed; + } + + @Override + public boolean has(int num) { + return args.size() >= num; + } + + @Override + public boolean hasAny() { + return has(1); + } + + @Override + public boolean hasAtMost(int num) { + return args.size() <= num; + } + + @Override + public boolean hasAtMostOne() { + return hasAtMost(1); + } + + @Override + public boolean hasExactly(int num) { + return args.size() == num; + } + + @Override + public boolean hasExactlyOne() { + return hasExactly(1); + } + + @Override + public ICommandArgument peek(int index) throws CommandNotEnoughArgumentsException { + requireMin(index + 1); + return args.get(index); + } + + @Override + public ICommandArgument peek() throws CommandNotEnoughArgumentsException { + return peek(0); + } + + @Override + public boolean is(Class type, int index) throws CommandNotEnoughArgumentsException { + return peek(index).is(type); + } + + @Override + public boolean is(Class type) throws CommandNotEnoughArgumentsException { + return is(type, 0); + } + + @Override + public String peekString(int index) throws CommandNotEnoughArgumentsException { + return peek(index).getValue(); + } + + @Override + public String peekString() throws CommandNotEnoughArgumentsException { + return peekString(0); + } + + @Override + public > E peekEnum(Class enumClass, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { + return peek(index).getEnum(enumClass); + } + + @Override + public > E peekEnum(Class enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { + return peekEnum(enumClass, 0); + } + + @Override + public > E peekEnumOrNull(Class enumClass, int index) throws CommandNotEnoughArgumentsException { + try { + return peekEnum(enumClass, index); + } catch (CommandInvalidTypeException e) { + return null; + } + } + + @Override + public > E peekEnumOrNull(Class enumClass) throws CommandNotEnoughArgumentsException { + return peekEnumOrNull(enumClass, 0); + } + + @Override + public T peekAs(Class type, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { + return peek(index).getAs(type); + } + + @Override + public T peekAs(Class type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { + return peekAs(type, 0); + } + + @Override + public T peekAsOrDefault(Class type, T def, int index) throws CommandNotEnoughArgumentsException { + try { + return peekAs(type, index); + } catch (CommandInvalidTypeException e) { + return def; + } + } + + @Override + public T peekAsOrDefault(Class type, T def) throws CommandNotEnoughArgumentsException { + return peekAsOrDefault(type, def, 0); + } + + @Override + public T peekAsOrNull(Class type, int index) throws CommandNotEnoughArgumentsException { + return peekAsOrDefault(type, null, index); + } + + @Override + public T peekAsOrNull(Class type) throws CommandNotEnoughArgumentsException { + return peekAsOrNull(type, 0); + } + + @Override + public T peekDatatype(IDatatypeFor datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { + return copy().getDatatypeFor(datatype); + } + + @Override + public T peekDatatype(IDatatypePost datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { + return this.peekDatatype(datatype, null); + } + + @Override + public T peekDatatype(IDatatypePost datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { + return copy().getDatatypePost(datatype, original); + } + + @Override + public T peekDatatypeOrNull(IDatatypeFor datatype) { + return copy().getDatatypeForOrNull(datatype); + } + + @Override + public T peekDatatypeOrNull(IDatatypePost datatype) { + return copy().getDatatypePostOrNull(datatype, null); + } + + @Override + public > T peekDatatypePost(D datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { + return copy().getDatatypePost(datatype, original); + } + + @Override + public > T peekDatatypePostOrDefault(D datatype, O original, T def) { + return copy().getDatatypePostOrDefault(datatype, original, def); + } + + @Override + public > T peekDatatypePostOrNull(D datatype, O original) { + return peekDatatypePostOrDefault(datatype, original, null); + } + + @Override + public > T peekDatatypeFor(Class datatype) { + return copy().peekDatatypeFor(datatype); + } + + @Override + public > T peekDatatypeForOrDefault(Class datatype, T def) { + return copy().peekDatatypeForOrDefault(datatype, def); + } + + @Override + public > T peekDatatypeForOrNull(Class datatype) { + return peekDatatypeForOrDefault(datatype, null); + } + + @Override + public ICommandArgument get() throws CommandNotEnoughArgumentsException { + requireMin(1); + ICommandArgument arg = args.removeFirst(); + consumed.add(arg); + return arg; + } + + @Override + public String getString() throws CommandNotEnoughArgumentsException { + return get().getValue(); + } + + @Override + public > E getEnum(Class enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { + return get().getEnum(enumClass); + } + + @Override + public > E getEnumOrDefault(Class enumClass, E def) throws CommandNotEnoughArgumentsException { + try { + peekEnum(enumClass); + return getEnum(enumClass); + } catch (CommandInvalidTypeException e) { + return def; + } + } + + @Override + public > E getEnumOrNull(Class enumClass) throws CommandNotEnoughArgumentsException { + return getEnumOrDefault(enumClass, null); + } + + @Override + public T getAs(Class type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { + return get().getAs(type); + } + + @Override + public T getAsOrDefault(Class type, T def) throws CommandNotEnoughArgumentsException { + try { + T val = peek().getAs(type); + get(); + return val; + } catch (CommandInvalidTypeException e) { + return def; + } + } + + @Override + public T getAsOrNull(Class type) throws CommandNotEnoughArgumentsException { + return getAsOrDefault(type, null); + } + + @Override + public > T getDatatypePost(D datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { + try { + return datatype.apply(this.context, original); + } catch (Exception e) { + e.printStackTrace(); + throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName()); + } + } + + @Override + public > T getDatatypePostOrDefault(D datatype, O original, T _default) { + final List argsSnapshot = new ArrayList<>(this.args); + final List consumedSnapshot = new ArrayList<>(this.consumed); + try { + return this.getDatatypePost(datatype, original); + } catch (Exception e) { + this.args.clear(); + this.args.addAll(argsSnapshot); + this.consumed.clear(); + this.consumed.addAll(consumedSnapshot); + return _default; + } + } + + @Override + public > T getDatatypePostOrNull(D datatype, O original) { + return this.getDatatypePostOrDefault(datatype, original, null); + } + + @Override + public > T getDatatypeFor(D datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException { + try { + return datatype.get(this.context); + } catch (Exception e) { + throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName()); + } + } + + @Override + public > T getDatatypeForOrDefault(D datatype, T def) { + final List argsSnapshot = new ArrayList<>(this.args); + final List consumedSnapshot = new ArrayList<>(this.consumed); + try { + return this.getDatatypeFor(datatype); + } catch (Exception e) { + this.args.clear(); + this.args.addAll(argsSnapshot); + this.consumed.clear(); + this.consumed.addAll(consumedSnapshot); + return def; + } + } + + @Override + public > T getDatatypeForOrNull(D datatype) { + return this.getDatatypeForOrDefault(datatype, null); + } + + @Override + public Stream tabCompleteDatatype(T datatype) { + try { + return datatype.tabComplete(this.context); + } catch (Exception e) { + e.printStackTrace(); + } + return Stream.empty(); + } + + @Override + public String rawRest() { + return args.size() > 0 ? args.getFirst().getRawRest() : ""; + } + + @Override + public void requireMin(int min) throws CommandNotEnoughArgumentsException { + if (args.size() < min) { + throw new CommandNotEnoughArgumentsException(min + consumed.size()); + } + } + + @Override + public void requireMax(int max) throws CommandTooManyArgumentsException { + if (args.size() > max) { + throw new CommandTooManyArgumentsException(max + consumed.size()); + } + } + + @Override + public void requireExactly(int args) throws CommandException { + requireMin(args); + requireMax(args); + } + + @Override + public boolean hasConsumed() { + return !consumed.isEmpty(); + } + + @Override + public ICommandArgument consumed() { + return consumed.size() > 0 ? consumed.getLast() : CommandArguments.unknown(); + } + + @Override + public String consumedString() { + return consumed().getValue(); + } + + @Override + public ArgConsumer copy() { + return new ArgConsumer(manager, args, consumed); + } + + /** + * Implementation of {@link IDatatypeContext} which adapts to the parent {@link IArgConsumer}} + */ + private final class Context implements IDatatypeContext { + + @Override + public final IBaritone getBaritone() { + return ArgConsumer.this.manager.getBaritone(); + } + + @Override + public final ArgConsumer getConsumer() { + return ArgConsumer.this; + } + } +} diff --git a/src/main/java/baritone/command/manager/CommandManager.java b/src/main/java/baritone/command/manager/CommandManager.java new file mode 100644 index 000000000..78fc2c9ff --- /dev/null +++ b/src/main/java/baritone/command/manager/CommandManager.java @@ -0,0 +1,160 @@ +/* + * 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.command.manager; + +import baritone.Baritone; +import baritone.api.IBaritone; +import baritone.api.command.Command; +import baritone.api.command.argument.ICommandArgument; +import baritone.api.command.exception.CommandUnhandledException; +import baritone.api.command.exception.ICommandException; +import baritone.api.command.helpers.tabcomplete.TabCompleteHelper; +import baritone.api.command.manager.ICommandManager; +import baritone.api.command.registry.Registry; +import baritone.command.argument.CommandArguments; +import baritone.command.defaults.DefaultCommands; +import baritone.command.helpers.arguments.ArgConsumer; +import net.minecraft.util.Tuple; + +import java.util.List; +import java.util.Locale; +import java.util.stream.Stream; + +/** + * The default, internal implementation of {@link ICommandManager} + * + * @author Brady + * @since 9/21/2019 + */ +public class CommandManager implements ICommandManager { + + private final Registry registry = new Registry<>(); + private final Baritone baritone; + + public CommandManager(Baritone baritone) { + this.baritone = baritone; + DefaultCommands.createAll(baritone).forEach(this.registry::register); + } + + @Override + public IBaritone getBaritone() { + return this.baritone; + } + + @Override + public Registry getRegistry() { + return this.registry; + } + + @Override + public Command getCommand(String name) { + for (Command command : this.registry.entries) { + if (command.getNames().contains(name.toLowerCase(Locale.US))) { + return command; + } + } + return null; + } + + @Override + public boolean execute(String string) { + return this.execute(expand(string)); + } + + @Override + public boolean execute(Tuple> expanded) { + ExecutionWrapper execution = this.from(expanded); + if (execution != null) { + execution.execute(); + } + return execution != null; + } + + @Override + public Stream tabComplete(Tuple> expanded) { + ExecutionWrapper execution = this.from(expanded); + return execution == null ? Stream.empty() : execution.tabComplete(); + } + + @Override + public Stream tabComplete(String prefix) { + Tuple> pair = expand(prefix, true); + String label = pair.getA(); + List args = pair.getB(); + if (args.isEmpty()) { + return new TabCompleteHelper() + .addCommands(this.baritone.getCommandManager()) + .filterPrefix(label) + .stream(); + } else { + return tabComplete(pair); + } + } + + private ExecutionWrapper from(Tuple> expanded) { + String label = expanded.getA(); + ArgConsumer args = new ArgConsumer(this, expanded.getB()); + + Command command = this.getCommand(label); + return command == null ? null : new ExecutionWrapper(command, label, args); + } + + private static Tuple> expand(String string, boolean preserveEmptyLast) { + String label = string.split("\\s", 2)[0]; + List args = CommandArguments.from(string.substring(label.length()), preserveEmptyLast); + return new Tuple<>(label, args); + } + + public static Tuple> expand(String string) { + return expand(string, false); + } + + private static final class ExecutionWrapper { + + private Command command; + private String label; + private ArgConsumer args; + + private ExecutionWrapper(Command command, String label, ArgConsumer args) { + this.command = command; + this.label = label; + this.args = args; + } + + private void execute() { + try { + this.command.execute(this.label, this.args); + } catch (Throwable t) { + // Create a handleable exception, wrap if needed + ICommandException exception = t instanceof ICommandException + ? (ICommandException) t + : new CommandUnhandledException(t); + + exception.handle(command, args.getArgs()); + } + } + + private Stream tabComplete() { + try { + return this.command.tabComplete(this.label, this.args); + } catch (Throwable t) { + return Stream.empty(); + } + } + } +} diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 01622d9ac..82a4aa705 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -380,7 +380,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil @Override public boolean inSchematic(int x, int y, int z, IBlockState currentState) { - return ISchematic.super.inSchematic(x, y, z, currentState) && y >= minYInclusive && y <= maxYInclusive; + return ISchematic.super.inSchematic(x, y, z, currentState) && y >= minYInclusive && y <= maxYInclusive && realSchematic.inSchematic(x, y, z, currentState); } @Override diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index ec99bd890..88cacca0c 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -22,6 +22,7 @@ import baritone.api.pathing.goals.*; import baritone.api.process.IGetToBlockProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; +import baritone.api.utils.BlockOptionalMeta; import baritone.api.utils.BlockOptionalMetaLookup; import baritone.api.utils.Rotation; import baritone.api.utils.RotationUtils; @@ -33,14 +34,11 @@ import net.minecraft.init.Blocks; import net.minecraft.inventory.ContainerPlayer; import net.minecraft.util.math.BlockPos; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; +import java.util.*; public final class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBlockProcess { - private Block gettingTo; + private BlockOptionalMeta gettingTo; private List knownLocations; private List blacklist; // locations we failed to calc to private BlockPos start; @@ -53,7 +51,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG } @Override - public void getToBlock(Block block) { + public void getToBlock(BlockOptionalMeta block) { onLostControl(); gettingTo = block; start = ctx.playerFeet(); @@ -109,7 +107,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG } if (goal.isInGoal(ctx.playerFeet()) && goal.isInGoal(baritone.getPathingBehavior().pathStart()) && isSafeToCancel) { // we're there - if (rightClickOnArrival(gettingTo)) { + if (rightClickOnArrival(gettingTo.getBlock())) { if (rightClick()) { onLostControl(); return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL); @@ -175,16 +173,16 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG } private synchronized void rescan(List known, CalculationContext context) { - List positions = MineProcess.searchWorld(context, new BlockOptionalMetaLookup(gettingTo), 64, known, blacklist); + List positions = MineProcess.searchWorld(context, new BlockOptionalMetaLookup(gettingTo), 64, known, blacklist, Collections.emptyList()); positions.removeIf(blacklist::contains); knownLocations = positions; } private Goal createGoal(BlockPos pos) { - if (walkIntoInsteadOfAdjacent(gettingTo)) { + if (walkIntoInsteadOfAdjacent(gettingTo.getBlock())) { return new GoalTwoBlocks(pos); } - if (blockOnTopMustBeRemoved(gettingTo) && baritone.bsi.get0(pos.up()).isBlockNormalCube()) { + if (blockOnTopMustBeRemoved(gettingTo.getBlock()) && baritone.bsi.get0(pos.up()).isBlockNormalCube()) { return new GoalBlock(pos.up()); } return new GoalGetToBlock(pos); diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 4043e6270..a76121b8d 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -39,7 +39,6 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; import java.util.*; import java.util.stream.Collectors; @@ -58,6 +57,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro private BlockOptionalMetaLookup filter; private List knownOreLocations; private List blacklist; // inaccessible + private Map anticipatedDrops; private BlockPos branchPoint; private GoalRunAway branchPointRunaway; private int desiredQuantity; @@ -101,6 +101,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro cancel(); return null; } + updateLoucaSystem(); int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; List curr = new ArrayList<>(knownOreLocations); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain @@ -141,6 +142,23 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return command; } + private void updateLoucaSystem() { + Map copy = new HashMap<>(anticipatedDrops); + ctx.getSelectedBlock().ifPresent(pos -> { + if (knownOreLocations.contains(pos)) { + copy.put(pos, System.currentTimeMillis() + Baritone.settings().mineDropLoiterDurationMSThanksLouca.value); + } + }); + // elaborate dance to avoid concurrentmodificationexcepption since rescan thread reads this + // don't want to slow everything down with a gross lock do we now + for (BlockPos pos : anticipatedDrops.keySet()) { + if (copy.get(pos) < System.currentTimeMillis()) { + copy.remove(pos); + } + } + anticipatedDrops = copy; + } + @Override public void onLostControl() { mine(0, (BlockOptionalMetaLookup) null); @@ -155,9 +173,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro boolean legit = Baritone.settings().legitMine.value; List locs = knownOreLocations; if (!locs.isEmpty()) { - List locs2 = prune(new CalculationContext(baritone), new ArrayList<>(locs), filter, ORE_LOCATIONS_COUNT, blacklist); + CalculationContext context = new CalculationContext(baritone); + List locs2 = prune(context, new ArrayList<>(locs), filter, ORE_LOCATIONS_COUNT, blacklist, droppedItemsScan()); // can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final - Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2)).toArray(Goal[]::new)); + Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2, context)).toArray(Goal[]::new)); knownOreLocations = locs2; return new PathingCommand(goal, legit ? PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH : PathingCommandType.REVALIDATE_GOAL_AND_PATH); } @@ -197,8 +216,9 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro if (Baritone.settings().legitMine.value) { return; } - List locs = searchWorld(context, filter, ORE_LOCATIONS_COUNT, already, blacklist); - locs.addAll(droppedItemsScan(filter, ctx.world())); + List dropped = droppedItemsScan(); + List locs = searchWorld(context, filter, ORE_LOCATIONS_COUNT, already, blacklist, dropped); + locs.addAll(dropped); if (locs.isEmpty()) { logDirect("No locations for " + filter + " known, cancelling"); cancel(); @@ -207,19 +227,19 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro knownOreLocations = locs; } - private boolean internalMiningGoal(BlockPos pos, IPlayerContext ctx, List locs) { + private boolean internalMiningGoal(BlockPos pos, CalculationContext context, List locs) { // Here, BlockStateInterface is used because the position may be in a cached chunk (the targeted block is one that is kept track of) if (locs.contains(pos)) { return true; } - IBlockState state = BlockStateInterface.get(ctx, pos); + IBlockState state = context.bsi.get0(pos); if (Baritone.settings().internalMiningAirException.value && state.getBlock() instanceof BlockAir) { return true; } - return filter.has(state); + return filter.has(state) && plausibleToBreak(context, pos); } - private Goal coalesce(BlockPos loc, List locs) { + private Goal coalesce(BlockPos loc, List locs, CalculationContext context) { boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof BlockFalling); if (!Baritone.settings().forceInternalMining.value) { if (assumeVerticalShaftMine) { @@ -230,9 +250,9 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return new GoalTwoBlocks(loc); } } - boolean upwardGoal = internalMiningGoal(loc.up(), ctx, locs); - boolean downwardGoal = internalMiningGoal(loc.down(), ctx, locs); - boolean doubleDownwardGoal = internalMiningGoal(loc.down(2), ctx, locs); + boolean upwardGoal = internalMiningGoal(loc.up(), context, locs); + boolean downwardGoal = internalMiningGoal(loc.down(), context, locs); + boolean doubleDownwardGoal = internalMiningGoal(loc.down(2), context, locs); if (upwardGoal == downwardGoal) { // symmetric if (doubleDownwardGoal && assumeVerticalShaftMine) { // we have a checkerboard like pattern @@ -281,12 +301,12 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } } - public static List droppedItemsScan(BlockOptionalMetaLookup filter, World world) { + public List droppedItemsScan() { if (!Baritone.settings().mineScanDroppedItems.value) { return Collections.emptyList(); } List ret = new ArrayList<>(); - for (Entity entity : world.loadedEntityList) { + for (Entity entity : ctx.world().loadedEntityList) { if (entity instanceof EntityItem) { EntityItem ei = (EntityItem) entity; if (filter.has(ei.getItem())) { @@ -294,10 +314,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } } } + ret.addAll(anticipatedDrops.keySet()); return ret; } - public static List searchWorld(CalculationContext ctx, BlockOptionalMetaLookup filter, int max, List alreadyKnown, List blacklist) { + public static List searchWorld(CalculationContext ctx, BlockOptionalMetaLookup filter, int max, List alreadyKnown, List blacklist, List dropped) { List locs = new ArrayList<>(); List untracked = new ArrayList<>(); for (BlockOptionalMeta bom : filter.blocks()) { @@ -318,7 +339,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } } - locs = prune(ctx, locs, filter, max, blacklist); + locs = prune(ctx, locs, filter, max, blacklist, dropped); if (!untracked.isEmpty() || (Baritone.settings().extendCacheOnThreshold.value && locs.size() < max)) { locs.addAll(WorldScanner.INSTANCE.scanChunkRadius( @@ -332,11 +353,12 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro locs.addAll(alreadyKnown); - return prune(ctx, locs, filter, max, blacklist); + return prune(ctx, locs, filter, max, blacklist, dropped); } private void addNearby() { - knownOreLocations.addAll(droppedItemsScan(filter, ctx.world())); + List dropped = droppedItemsScan(); + knownOreLocations.addAll(dropped); BlockPos playerFeet = ctx.playerFeet(); BlockStateInterface bsi = new BlockStateInterface(ctx); int searchDist = 10; @@ -355,11 +377,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } } } - knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, filter, ORE_LOCATIONS_COUNT, blacklist); + knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, filter, ORE_LOCATIONS_COUNT, blacklist, dropped); } - private static List prune(CalculationContext ctx, List locs2, BlockOptionalMetaLookup filter, int max, List blacklist) { - List dropped = droppedItemsScan(filter, ctx.world); + private static List prune(CalculationContext ctx, List locs2, BlockOptionalMetaLookup filter, int max, List blacklist, List dropped) { dropped.removeIf(drop -> { for (BlockPos pos : locs2) { if (pos.distanceSq(drop) <= 9 && filter.has(ctx.get(pos.getX(), pos.getY(), pos.getZ())) && MineProcess.plausibleToBreak(ctx, pos)) { // TODO maybe drop also has to be supported? no lava below? @@ -416,6 +437,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro this.blacklist = new ArrayList<>(); this.branchPoint = null; this.branchPointRunaway = null; + this.anticipatedDrops = new HashMap<>(); if (filter != null) { rescan(new ArrayList<>(), new CalculationContext(baritone)); } diff --git a/src/main/java/baritone/utils/GuiClick.java b/src/main/java/baritone/utils/GuiClick.java index 60663d577..f213efa11 100644 --- a/src/main/java/baritone/utils/GuiClick.java +++ b/src/main/java/baritone/utils/GuiClick.java @@ -39,7 +39,7 @@ import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.util.Collections; -import static baritone.api.utils.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; +import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; import static org.lwjgl.opengl.GL11.*; public class GuiClick extends GuiScreen { diff --git a/src/main/java/baritone/utils/command/defaults/PathCommand.java b/src/main/java/baritone/utils/command/defaults/PathCommand.java deleted file mode 100644 index 4cd766ea1..000000000 --- a/src/main/java/baritone/utils/command/defaults/PathCommand.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.utils.command.defaults; - -import baritone.api.IBaritone; -import baritone.api.pathing.goals.Goal; -import baritone.api.process.ICustomGoalProcess; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.datatypes.RelativeCoordinate; -import baritone.api.utils.command.datatypes.RelativeGoal; -import baritone.api.utils.command.exception.CommandException; -import baritone.api.utils.command.exception.CommandInvalidStateException; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; -import baritone.cache.WorldScanner; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Stream; - -public class PathCommand extends Command { - - public PathCommand(IBaritone baritone) { - super(baritone, Arrays.asList("path", "goto")); - } - - @Override - protected void executed(String label, ArgConsumer args) throws CommandException { - ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess(); - Goal goal; - if (args.hasAny()) { - args.requireMax(3); - goal = args.getDatatypePost(RelativeGoal.INSTANCE, ctx.playerFeet()); - } else if ((goal = customGoalProcess.getGoal()) == null) { - throw new CommandInvalidStateException("No goal"); - } - args.requireMax(0); - WorldScanner.INSTANCE.repack(ctx); - customGoalProcess.setGoalAndPath(goal); - logDirect("Now pathing"); - } - - @Override - protected Stream tabCompleted(String label, ArgConsumer args) throws CommandException { - if (args.hasAny() && !args.has(4)) { - while (args.has(2)) { - if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) == null) { - break; - } - args.get(); - if (!args.has(2)) { - return new TabCompleteHelper() - .append("~") - .filterPrefix(args.getString()) - .stream(); - } - } - } - return Stream.empty(); - } - - @Override - public String getShortDesc() { - return "Start heading towards a goal"; - } - - @Override - public List getLongDesc() { - return Arrays.asList( - "The path command tells Baritone to head towards the current goal.", - "", - "Usage:", - "> path - Start the pathing.", - "> path ", - "> path ", - "> path - Define the goal here" - ); - } -} diff --git a/src/main/java/baritone/utils/command/execution/CommandExecution.java b/src/main/java/baritone/utils/command/execution/CommandExecution.java deleted file mode 100644 index 1e8fe8382..000000000 --- a/src/main/java/baritone/utils/command/execution/CommandExecution.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.utils.command.execution; - -import baritone.api.utils.command.Command; -import baritone.api.utils.command.exception.CommandUnhandledException; -import baritone.api.utils.command.exception.ICommandException; -import baritone.api.utils.command.execution.ICommandExecution; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import baritone.utils.command.manager.CommandManager; - -import java.util.stream.Stream; - -/** - * The default, internal implementation of {@link ICommandExecution}, which is used by {@link CommandManager} - * - * @author LoganDark, Brady - */ -public class CommandExecution implements ICommandExecution { - - /** - * The command itself - */ - private final Command command; - - /** - * The name this command was called with - */ - private final String label; - - /** - * The arg consumer - */ - private final ArgConsumer args; - - public CommandExecution(Command command, String label, ArgConsumer args) { - this.command = command; - this.label = label; - this.args = args; - } - - @Override - public String getLabel() { - return this.label; - } - - @Override - public ArgConsumer getArguments() { - return this.args; - } - - @Override - public void execute() { - try { - command.execute(this); - } catch (Throwable t) { - // Create a handleable exception, wrap if needed - ICommandException exception = t instanceof ICommandException - ? (ICommandException) t - : new CommandUnhandledException(t); - - exception.handle(command, args.args); - } - } - - @Override - public Stream tabComplete() { - return command.tabComplete(this); - } -} diff --git a/src/main/java/baritone/utils/command/manager/CommandManager.java b/src/main/java/baritone/utils/command/manager/CommandManager.java deleted file mode 100644 index 82f25a4a4..000000000 --- a/src/main/java/baritone/utils/command/manager/CommandManager.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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.utils.command.manager; - -import baritone.Baritone; -import baritone.api.IBaritone; -import baritone.api.utils.command.Command; -import baritone.api.utils.command.argument.CommandArgument; -import baritone.api.utils.command.execution.ICommandExecution; -import baritone.api.utils.command.helpers.arguments.ArgConsumer; -import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper; -import baritone.api.utils.command.manager.ICommandManager; -import baritone.api.utils.command.registry.Registry; -import baritone.utils.command.defaults.DefaultCommands; -import baritone.utils.command.execution.CommandExecution; -import net.minecraft.util.Tuple; - -import java.util.List; -import java.util.Locale; -import java.util.stream.Stream; - -/** - * The default, internal implementation of {@link ICommandManager} - * - * @author Brady - * @since 9/21/2019 - */ -public class CommandManager implements ICommandManager { - - private final Registry registry = new Registry<>(); - private final Baritone baritone; - - public CommandManager(Baritone baritone) { - this.baritone = baritone; - DefaultCommands.createAll(baritone).forEach(this.registry::register); - } - - @Override - public IBaritone getBaritone() { - return this.baritone; - } - - @Override - public Registry getRegistry() { - return this.registry; - } - - @Override - public Command getCommand(String name) { - for (Command command : this.registry.entries) { - if (command.names.contains(name.toLowerCase(Locale.US))) { - return command; - } - } - return null; - } - - @Override - public boolean execute(String string) { - return this.execute(ICommandExecution.expand(string)); - } - - @Override - public boolean execute(Tuple> expanded) { - ICommandExecution execution = this.from(expanded); - if (execution != null) { - execution.execute(); - } - return execution != null; - } - - @Override - public Stream tabComplete(Tuple> expanded) { - ICommandExecution execution = this.from(expanded); - return execution == null ? Stream.empty() : execution.tabComplete(); - } - - @Override - public Stream tabComplete(String prefix) { - Tuple> pair = ICommandExecution.expand(prefix, true); - String label = pair.getA(); - List args = pair.getB(); - if (args.isEmpty()) { - return new TabCompleteHelper() - .addCommands(this.baritone.getCommandManager()) - .filterPrefix(label) - .stream(); - } else { - return tabComplete(pair); - } - } - - private ICommandExecution from(Tuple> expanded) { - String label = expanded.getA(); - ArgConsumer args = new ArgConsumer(this, expanded.getB()); - - Command command = this.getCommand(label); - return command == null ? null : new CommandExecution(command, label, args); - } -}