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.argparser; 019 020import baritone.api.command.argument.ICommandArgument; 021import baritone.api.command.exception.CommandInvalidTypeException; 022import baritone.api.command.registry.Registry; 023 024/** 025 * Used to retrieve {@link IArgParser} instances from the registry, by their target class. 026 * It can be assumed that a {@link IArgParser} exists for {@link Integer}, {@link Long}, 027 * {@link Float}, {@link Double} and {@link Boolean}. 028 * 029 * @author Brady 030 * @since 10/4/2019 031 */ 032public interface IArgParserManager { 033 034 /** 035 * @param type The type trying to be parsed 036 * @return A parser that can parse arguments into this class, if found. 037 */ 038 <T> IArgParser.Stateless<T> getParserStateless(Class<T> type); 039 040 /** 041 * @param type The type trying to be parsed 042 * @return A parser that can parse arguments into this class, if found. 043 */ 044 <T, S> IArgParser.Stated<T, S> getParserStated(Class<T> type, Class<S> stateKlass); 045 046 /** 047 * Attempt to parse the specified argument with a stateless {@link IArgParser} that outputs the specified class. 048 * 049 * @param type The type to try and parse the argument into. 050 * @param arg The argument to parse. 051 * @return An instance of the specified class. 052 * @throws CommandInvalidTypeException If the parsing failed 053 */ 054 <T> T parseStateless(Class<T> type, ICommandArgument arg) throws CommandInvalidTypeException; 055 056 /** 057 * Attempt to parse the specified argument with a stated {@link IArgParser} that outputs the specified class. 058 * 059 * @param type The type to try and parse the argument into. 060 * @param arg The argument to parse. 061 * @param state The state to pass to the {@link IArgParser.Stated}. 062 * @return An instance of the specified class. 063 * @throws CommandInvalidTypeException If the parsing failed 064 * @see IArgParser.Stated 065 */ 066 <T, S> T parseStated(Class<T> type, Class<S> stateKlass, ICommandArgument arg, S state) throws CommandInvalidTypeException; 067 068 Registry<IArgParser> getRegistry(); 069}