001/*
002 * This file is part of Baritone.
003 *
004 * Baritone is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU Lesser General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * Baritone is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU Lesser General Public License for more details.
013 *
014 * You should have received a copy of the GNU Lesser General Public License
015 * along with Baritone.  If not, see <https://www.gnu.org/licenses/>.
016 */
017
018package baritone.api.command.argument;
019
020import baritone.api.command.argparser.IArgParser;
021import baritone.api.command.exception.CommandInvalidTypeException;
022import net.minecraft.util.EnumFacing;
023
024/**
025 * A {@link ICommandArgument} is an immutable object representing one command argument. It contains data on the index of
026 * that argument, its value, and the rest of the string that argument was found in
027 * <p>
028 * You're recommended to use {@link IArgConsumer}}s to handle these.
029 *
030 * @author Brady
031 * @since 10/2/2019
032 */
033public interface ICommandArgument {
034
035    /**
036     * @return The index of this command argument in the list of command arguments generated
037     */
038    int getIndex();
039
040    /**
041     * @return The raw value of just this argument
042     */
043    String getValue();
044
045    /**
046     * @return The raw value of the remaining arguments after this one was captured
047     */
048    String getRawRest();
049
050    /**
051     * Gets an enum value from the enum class with the same name as this argument's value
052     * <p>
053     * For example if you getEnum as an {@link EnumFacing}, and this argument's value is "up", it will return {@link
054     * EnumFacing#UP}
055     *
056     * @param enumClass The enum class to search
057     * @return An enum constant of that class with the same name as this argument's value
058     * @throws CommandInvalidTypeException If the constant couldn't be found
059     * @see IArgConsumer#peekEnum(Class)
060     * @see IArgConsumer#peekEnum(Class, int)
061     * @see IArgConsumer#peekEnumOrNull(Class)
062     * @see IArgConsumer#peekEnumOrNull(Class, int)
063     * @see IArgConsumer#getEnum(Class)
064     * @see IArgConsumer#getEnumOrNull(Class)
065     */
066    <E extends Enum<?>> E getEnum(Class<E> enumClass) throws CommandInvalidTypeException;
067
068    /**
069     * Tries to use a <b>stateless</b> {@link IArgParser} to parse this argument into the specified class
070     *
071     * @param type The class to parse this argument into
072     * @return An instance of the specified type
073     * @throws CommandInvalidTypeException If the parsing failed
074     */
075    <T> T getAs(Class<T> type) throws CommandInvalidTypeException;
076
077    /**
078     * Tries to use a <b>stateless</b> {@link IArgParser} to parse this argument into the specified class
079     *
080     * @param type The class to parse this argument into
081     * @return If the parser succeeded
082     */
083    <T> boolean is(Class<T> type);
084
085    /**
086     * Tries to use a <b>stated</b> {@link IArgParser} to parse this argument into the specified class
087     *
088     * @param type The class to parse this argument into
089     * @return An instance of the specified type
090     * @throws CommandInvalidTypeException If the parsing failed
091     */
092    <T, S> T getAs(Class<T> type, Class<S> stateType, S state) throws CommandInvalidTypeException;
093
094    /**
095     * Tries to use a <b>stated</b> {@link IArgParser} to parse this argument into the specified class
096     *
097     * @param type The class to parse this argument into
098     * @return If the parser succeeded
099     */
100    <T, S> boolean is(Class<T> type, Class<S> stateType, S state);
101}