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.ICommand; 021import baritone.api.command.argparser.IArgParser; 022import baritone.api.command.datatypes.IDatatype; 023import baritone.api.command.datatypes.IDatatypeFor; 024import baritone.api.command.datatypes.IDatatypePost; 025import baritone.api.command.exception.CommandException; 026import baritone.api.command.exception.CommandInvalidTypeException; 027import baritone.api.command.exception.CommandNotEnoughArgumentsException; 028import baritone.api.command.exception.CommandTooManyArgumentsException; 029import baritone.api.utils.Helper; 030import java.util.Deque; 031import java.util.LinkedList; 032import java.util.stream.Stream; 033import net.minecraft.core.Direction; 034 035/** 036 * The {@link IArgConsumer} is how {@link ICommand}s read the arguments passed to them. This class has many benefits: 037 * 038 * <ul> 039 * <li>Mutability. The whole concept of the {@link IArgConsumer}} is to let you gradually consume arguments in any way 040 * you'd like. You can change your consumption based on earlier arguments, for subcommands for example.</li> 041 * <li>You don't need to keep track of your consumption. The {@link IArgConsumer}} keeps track of the arguments you 042 * consume so that it can throw detailed exceptions whenever something is out of the ordinary. Additionally, if you 043 * need to retrieve an argument after you've already consumed it - look no further than {@link #consumed()}!</li> 044 * <li>Easy retrieval of many different types. If you need to retrieve an instance of an int or float for example, 045 * look no further than {@link #getAs(Class)}. If you need a more powerful way of retrieving data, try out the many 046 * {@code getDatatype...} methods.</li> 047 * <li>It's very easy to throw detailed exceptions. The {@link IArgConsumer}} has many different methods that can 048 * enforce the number of arguments, the type of arguments, and more, throwing different types of 049 * {@link CommandException}s if something seems off. You're recommended to do all validation and store all needed 050 * data in variables BEFORE logging any data to chat via {@link Helper#logDirect(String)}, so that the error 051 * handlers can do their job and log the error to chat.</li> 052 * </ul> 053 */ 054public interface IArgConsumer { 055 056 LinkedList<ICommandArgument> getArgs(); 057 058 Deque<ICommandArgument> getConsumed(); 059 060 /** 061 * @param num The number of arguments to check for 062 * @return {@code true} if there are <i>at least</i> {@code num} arguments left in this {@link IArgConsumer}} 063 * @see #hasAny() 064 * @see #hasAtMost(int) 065 * @see #hasExactly(int) 066 */ 067 boolean has(int num); 068 069 /** 070 * @return {@code true} if there is <i>at least</i> 1 argument left in this {@link IArgConsumer}} 071 * @see #has(int) 072 * @see #hasAtMostOne() 073 * @see #hasExactlyOne() 074 */ 075 boolean hasAny(); 076 077 /** 078 * @param num The number of arguments to check for 079 * @return {@code true} if there are <i>at most</i> {@code num} arguments left in this {@link IArgConsumer}} 080 * @see #has(int) 081 * @see #hasAtMost(int) 082 * @see #hasExactly(int) 083 */ 084 boolean hasAtMost(int num); 085 086 /** 087 * @return {@code true} if there is <i>at most</i> 1 argument left in this {@link IArgConsumer}} 088 * @see #hasAny() 089 * @see #hasAtMostOne() 090 * @see #hasExactlyOne() 091 */ 092 boolean hasAtMostOne(); 093 094 /** 095 * @param num The number of arguments to check for 096 * @return {@code true} if there are <i>exactly</i> {@code num} arguments left in this {@link IArgConsumer}} 097 * @see #has(int) 098 * @see #hasAtMost(int) 099 */ 100 boolean hasExactly(int num); 101 102 /** 103 * @return {@code true} if there is <i>exactly</i> 1 argument left in this {@link IArgConsumer}} 104 * @see #hasAny() 105 * @see #hasAtMostOne() 106 */ 107 boolean hasExactlyOne(); 108 109 /** 110 * @param index The index to peek 111 * @return The argument at index {@code index} in this {@link IArgConsumer}}, with 0 being the next one. This does not 112 * mutate the {@link IArgConsumer}} 113 * @throws CommandNotEnoughArgumentsException If there is less than {@code index + 1} arguments left 114 * @see #peek() 115 * @see #peekString(int) 116 * @see #peekAs(Class, int) 117 * @see #get() 118 */ 119 ICommandArgument peek(int index) throws CommandNotEnoughArgumentsException; 120 121 /** 122 * @return The next argument in this {@link IArgConsumer}}. This does not mutate the {@link IArgConsumer}} 123 * @throws CommandNotEnoughArgumentsException If there is less than one argument left 124 * @see #peek(int) 125 * @see #peekString() 126 * @see #peekAs(Class) 127 * @see #get() 128 */ 129 ICommandArgument peek() throws CommandNotEnoughArgumentsException; 130 131 /** 132 * @param index The index to peek 133 * @param type The type to check for 134 * @return If an ArgParser.Stateless for the specified {@code type} would succeed in parsing the next 135 * argument 136 * @throws CommandNotEnoughArgumentsException If there is less than {@code index + 1} arguments left 137 * @see #peek() 138 * @see #getAs(Class) 139 */ 140 boolean is(Class<?> type, int index) throws CommandNotEnoughArgumentsException; 141 142 /** 143 * @param type The type to check for 144 * @return If an ArgParser.Stateless for the specified {@code type} would succeed in parsing the next 145 * argument 146 * @throws CommandNotEnoughArgumentsException If there is less than one argument left 147 * @see #peek() 148 * @see #getAs(Class) 149 */ 150 boolean is(Class<?> type) throws CommandNotEnoughArgumentsException; 151 152 /** 153 * @param index The index to peek 154 * @return The value of the argument at index {@code index} in this {@link IArgConsumer}}, with 0 being the next one 155 * This does not mutate the {@link IArgConsumer}} 156 * @throws CommandNotEnoughArgumentsException If there is less than {@code index + 1} arguments left 157 * @see #peek() 158 * @see #peekString() 159 */ 160 String peekString(int index) throws CommandNotEnoughArgumentsException; 161 162 /** 163 * @return The value of the next argument in this {@link IArgConsumer}}. This does not mutate the {@link IArgConsumer}} 164 * @throws CommandNotEnoughArgumentsException If there is less than one argument left 165 * @see #peekString(int) 166 * @see #getString() 167 */ 168 String peekString() throws CommandNotEnoughArgumentsException; 169 170 /** 171 * @param index The index to peek 172 * @param enumClass The class to search 173 * @return From the specified enum class, an enum constant of that class. The enum constant's name will match the 174 * next argument's value 175 * @throws java.util.NoSuchElementException If the constant couldn't be found 176 * @see #peekEnumOrNull(Class) 177 * @see #getEnum(Class) 178 * @see ICommandArgument#getEnum(Class) 179 */ 180 <E extends Enum<?>> E peekEnum(Class<E> enumClass, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; 181 182 /** 183 * @param enumClass The class to search 184 * @return From the specified enum class, an enum constant of that class. The enum constant's name will match the 185 * next argument's value 186 * @throws CommandInvalidTypeException If the constant couldn't be found 187 * @see #peekEnumOrNull(Class) 188 * @see #getEnum(Class) 189 * @see ICommandArgument#getEnum(Class) 190 */ 191 <E extends Enum<?>> E peekEnum(Class<E> enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; 192 193 /** 194 * @param index The index to peek 195 * @param enumClass The class to search 196 * @return From the specified enum class, an enum constant of that class. The enum constant's name will match the 197 * next argument's value. If no constant could be found, null 198 * @see #peekEnum(Class) 199 * @see #getEnumOrNull(Class) 200 * @see ICommandArgument#getEnum(Class) 201 */ 202 <E extends Enum<?>> E peekEnumOrNull(Class<E> enumClass, int index) throws CommandNotEnoughArgumentsException; 203 204 /** 205 * @param enumClass The class to search 206 * @return From the specified enum class, an enum constant of that class. The enum constant's name will match the 207 * next argument's value. If no constant could be found, null 208 * @see #peekEnum(Class) 209 * @see #getEnumOrNull(Class) 210 * @see ICommandArgument#getEnum(Class) 211 */ 212 <E extends Enum<?>> E peekEnumOrNull(Class<E> enumClass) throws CommandNotEnoughArgumentsException; 213 214 /** 215 * Tries to use a <b>stateless</b> {@link IArgParser} to parse the argument at the specified index into the specified 216 * class 217 * <p> 218 * A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. 219 * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire 220 * {@link IArgConsumer}}. 221 * 222 * @param type The type to peek as 223 * @param index The index to peek 224 * @return An instance of the specified type 225 * @throws CommandInvalidTypeException If the parsing failed 226 * @see IArgParser 227 * @see #peekAs(Class) 228 * @see #peekAsOrDefault(Class, Object, int) 229 * @see #peekAsOrNull(Class, int) 230 */ 231 <T> T peekAs(Class<T> type, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; 232 233 /** 234 * Tries to use a <b>stateless</b> {@link IArgParser} to parse the next argument into the specified class 235 * <p> 236 * A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. 237 * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire 238 * {@link IArgConsumer}}. 239 * 240 * @param type The type to peek as 241 * @return An instance of the specified type 242 * @throws CommandInvalidTypeException If the parsing failed 243 * @see IArgParser 244 * @see #peekAs(Class, int) 245 * @see #peekAsOrDefault(Class, Object) 246 * @see #peekAsOrNull(Class) 247 */ 248 <T> T peekAs(Class<T> type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; 249 250 /** 251 * Tries to use a <b>stateless</b> {@link IArgParser} to parse the argument at the specified index into the specified 252 * class 253 * <p> 254 * A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. 255 * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire 256 * {@link IArgConsumer}}. 257 * 258 * @param type The type to peek as 259 * @param def The value to return if the argument can't be parsed 260 * @param index The index to peek 261 * @return An instance of the specified type, or {@code def} if it couldn't be parsed 262 * @see IArgParser 263 * @see #peekAsOrDefault(Class, Object) 264 * @see #peekAs(Class, int) 265 * @see #peekAsOrNull(Class, int) 266 */ 267 <T> T peekAsOrDefault(Class<T> type, T def, int index) throws CommandNotEnoughArgumentsException; 268 269 /** 270 * Tries to use a <b>stateless</b> {@link IArgParser} to parse the next argument into the specified class 271 * <p> 272 * A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. 273 * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire 274 * {@link IArgConsumer}}. 275 * 276 * @param type The type to peek as 277 * @param def The value to return if the argument can't be parsed 278 * @return An instance of the specified type, or {@code def} if it couldn't be parsed 279 * @see IArgParser 280 * @see #peekAsOrDefault(Class, Object, int) 281 * @see #peekAs(Class) 282 * @see #peekAsOrNull(Class) 283 */ 284 <T> T peekAsOrDefault(Class<T> type, T def) throws CommandNotEnoughArgumentsException; 285 286 /** 287 * Tries to use a <b>stateless</b> {@link IArgParser} to parse the argument at the specified index into the specified 288 * class 289 * <p> 290 * A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. 291 * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire 292 * {@link IArgConsumer}}. 293 * 294 * @param type The type to peek as 295 * @param index The index to peek 296 * @return An instance of the specified type, or {@code null} if it couldn't be parsed 297 * @see IArgParser 298 * @see #peekAsOrNull(Class) 299 * @see #peekAs(Class, int) 300 * @see #peekAsOrDefault(Class, Object, int) 301 */ 302 <T> T peekAsOrNull(Class<T> type, int index) throws CommandNotEnoughArgumentsException; 303 304 /** 305 * Tries to use a <b>stateless</b> {@link IArgParser} to parse the next argument into the specified class 306 * <p> 307 * A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. 308 * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire 309 * {@link IArgConsumer}}. 310 * 311 * @param type The type to peek as 312 * @return An instance of the specified type, or {@code null} if it couldn't be parsed 313 * @see IArgParser 314 * @see #peekAsOrNull(Class, int) 315 * @see #peekAs(Class) 316 * @see #peekAsOrDefault(Class, Object) 317 */ 318 <T> T peekAsOrNull(Class<T> type) throws CommandNotEnoughArgumentsException; 319 320 <T> T peekDatatype(IDatatypeFor<T> datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; 321 322 <T, O> T peekDatatype(IDatatypePost<T, O> datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; 323 324 <T, O> T peekDatatype(IDatatypePost<T, O> datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; 325 326 <T> T peekDatatypeOrNull(IDatatypeFor<T> datatype); 327 328 <T, O> T peekDatatypeOrNull(IDatatypePost<T, O> datatype); 329 330 <T, O, D extends IDatatypePost<T, O>> T peekDatatypePost(D datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; 331 332 <T, O, D extends IDatatypePost<T, O>> T peekDatatypePostOrDefault(D datatype, O original, T def); 333 334 <T, O, D extends IDatatypePost<T, O>> T peekDatatypePostOrNull(D datatype, O original); 335 336 /** 337 * Attempts to get the specified {@link IDatatypeFor} from this ArgConsumer 338 * <p> 339 * A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. 340 * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire 341 * {@link IArgConsumer}}. 342 * <p> 343 * Since this is a peek operation, this ArgConsumer will not be mutated by any call to this method. 344 * 345 * @param datatype The datatype to get 346 * @return The datatype instance 347 * @see IDatatype 348 * @see IDatatypeFor 349 */ 350 <T, D extends IDatatypeFor<T>> T peekDatatypeFor(Class<D> datatype); 351 352 /** 353 * Attempts to get the specified {@link IDatatypeFor} from this ArgConsumer 354 * <p> 355 * A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. 356 * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire 357 * {@link IArgConsumer}}. 358 * <p> 359 * Since this is a peek operation, this ArgConsumer will not be mutated by any call to this method. 360 * 361 * @param datatype The datatype to get 362 * @param def The default value 363 * @return The datatype instance, or {@code def} if it throws an exception 364 * @see IDatatype 365 * @see IDatatypeFor 366 */ 367 <T, D extends IDatatypeFor<T>> T peekDatatypeForOrDefault(Class<D> datatype, T def); 368 369 /** 370 * Attempts to get the specified {@link IDatatypeFor} from this ArgConsumer 371 * <p> 372 * A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. 373 * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire 374 * {@link IArgConsumer}}. 375 * <p> 376 * Since this is a peek operation, this ArgConsumer will not be mutated by any call to this method. 377 * 378 * @param datatype The datatype to get 379 * @return The datatype instance, or {@code null} if it throws an exception 380 * @see IDatatype 381 * @see IDatatypeFor 382 */ 383 <T, D extends IDatatypeFor<T>> T peekDatatypeForOrNull(Class<D> datatype); 384 385 /** 386 * Gets the next argument and returns it. This consumes the first argument so that subsequent calls will return 387 * later arguments 388 * 389 * @return The next argument 390 * @throws CommandNotEnoughArgumentsException If there's less than one argument left 391 */ 392 ICommandArgument get() throws CommandNotEnoughArgumentsException; 393 394 /** 395 * Gets the value of the next argument and returns it. This consumes the first argument so that subsequent calls 396 * will return later arguments 397 * 398 * @return The value of the next argument 399 * @throws CommandNotEnoughArgumentsException If there's less than one argument left 400 */ 401 String getString() throws CommandNotEnoughArgumentsException; 402 403 /** 404 * Gets an enum value from the enum class with the same name as the next argument's value 405 * <p> 406 * For example if you getEnum as an {@link Direction}, and the next argument's value is "up", this will return 407 * {@link Direction#UP} 408 * 409 * @param enumClass The enum class to search 410 * @return An enum constant of that class with the same name as the next argument's value 411 * @throws CommandInvalidTypeException If the constant couldn't be found 412 * @see #peekEnum(Class) 413 * @see #getEnumOrNull(Class) 414 * @see ICommandArgument#getEnum(Class) 415 */ 416 <E extends Enum<?>> E getEnum(Class<E> enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; 417 418 /** 419 * Gets an enum value from the enum class with the same name as the next argument's value 420 * <p> 421 * For example if you getEnum as an {@link Direction}, and the next argument's value is "up", this will return 422 * {@link Direction#UP} 423 * 424 * @param enumClass The enum class to search 425 * @param def The default value 426 * @return An enum constant of that class with the same name as the next argument's value, or {@code def} if it 427 * couldn't be found 428 * @see #getEnum(Class) 429 * @see #getEnumOrNull(Class) 430 * @see #peekEnumOrNull(Class) 431 * @see ICommandArgument#getEnum(Class) 432 */ 433 <E extends Enum<?>> E getEnumOrDefault(Class<E> enumClass, E def) throws CommandNotEnoughArgumentsException; 434 435 /** 436 * Gets an enum value from the enum class with the same name as the next argument's value 437 * <p> 438 * For example if you getEnum as an {@link Direction}, and the next argument's value is "up", this will return 439 * {@link Direction#UP} 440 * 441 * @param enumClass The enum class to search 442 * @return An enum constant of that class with the same name as the next argument's value, or {@code null} if it 443 * couldn't be found 444 * @see #getEnum(Class) 445 * @see #getEnumOrDefault(Class, Enum) 446 * @see #peekEnumOrNull(Class) 447 * @see ICommandArgument#getEnum(Class) 448 */ 449 <E extends Enum<?>> E getEnumOrNull(Class<E> enumClass) throws CommandNotEnoughArgumentsException; 450 451 /** 452 * Tries to use a <b>stateless</b> {@link IArgParser} to parse the next argument into the specified class 453 * <p> 454 * A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. 455 * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire 456 * {@link IArgConsumer}}. 457 * 458 * @param type The type to peek as 459 * @return An instance of the specified type 460 * @throws CommandInvalidTypeException If the parsing failed 461 * @see IArgParser 462 * @see #get() 463 * @see #getAsOrDefault(Class, Object) 464 * @see #getAsOrNull(Class) 465 * @see #peekAs(Class) 466 * @see #peekAsOrDefault(Class, Object, int) 467 * @see #peekAsOrNull(Class, int) 468 */ 469 <T> T getAs(Class<T> type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; 470 471 /** 472 * Tries to use a <b>stateless</b> {@link IArgParser} to parse the next argument into the specified class 473 * <p> 474 * A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. 475 * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire 476 * {@link IArgConsumer}}. 477 * 478 * @param type The type to peek as 479 * @param def The default value 480 * @return An instance of the specified type, or {@code def} if it couldn't be parsed 481 * @see IArgParser 482 * @see #get() 483 * @see #getAs(Class) 484 * @see #getAsOrNull(Class) 485 * @see #peekAs(Class) 486 * @see #peekAsOrDefault(Class, Object, int) 487 * @see #peekAsOrNull(Class, int) 488 */ 489 <T> T getAsOrDefault(Class<T> type, T def) throws CommandNotEnoughArgumentsException; 490 491 /** 492 * Tries to use a <b>stateless</b> {@link IArgParser} to parse the next argument into the specified class 493 * <p> 494 * A critical difference between {@link IDatatype}s and {@link IArgParser}s is how many arguments they can take. 495 * While {@link IArgParser}s always operate on a single argument's value, {@link IDatatype}s get access to the entire 496 * {@link IArgConsumer}}. 497 * 498 * @param type The type to peek as 499 * @return An instance of the specified type, or {@code null} if it couldn't be parsed 500 * @see IArgParser 501 * @see #get() 502 * @see #getAs(Class) 503 * @see #getAsOrDefault(Class, Object) 504 * @see #peekAs(Class) 505 * @see #peekAsOrDefault(Class, Object, int) 506 * @see #peekAsOrNull(Class, int) 507 */ 508 <T> T getAsOrNull(Class<T> type) throws CommandNotEnoughArgumentsException; 509 510 <T, O, D extends IDatatypePost<T, O>> T getDatatypePost(D datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; 511 512 <T, O, D extends IDatatypePost<T, O>> T getDatatypePostOrDefault(D datatype, O original, T _default); 513 514 <T, O, D extends IDatatypePost<T, O>> T getDatatypePostOrNull(D datatype, O original); 515 516 <T, D extends IDatatypeFor<T>> T getDatatypeFor(D datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException; 517 518 <T, D extends IDatatypeFor<T>> T getDatatypeForOrDefault(D datatype, T def); 519 520 <T, D extends IDatatypeFor<T>> T getDatatypeForOrNull(D datatype); 521 522 <T extends IDatatype> Stream<String> tabCompleteDatatype(T datatype); 523 524 /** 525 * Returns the "raw rest" of the string. For example, from a string <code>arg1 arg2 arg3</code>, split 526 * into three {@link ICommandArgument}s {@code "arg1"}, {@code "arg2"}, and {@code "arg3"}: 527 * 528 * <ul> 529 * <li>{@code rawRest()} would return <code>arg1 arg2 arg3</code></li> 530 * <li>After calling {@link #get()}, {@code rawRest()} would return <code>arg2 arg3</code> (note the 531 * double space - it is preserved!)</li> 532 * <li>After calling {@link #get()} again, {@code rawRest()} would return {@code "arg3"}</li> 533 * <li>After calling {@link #get()} one last time, {@code rawRest()} would return {@code ""}</li> 534 * </ul> 535 * 536 * @return The "raw rest" of the string. 537 */ 538 String rawRest(); 539 540 /** 541 * @param min The minimum amount of arguments to require. 542 * @throws CommandNotEnoughArgumentsException If there are less than {@code min} arguments left. 543 * @see #requireMax(int) 544 * @see #requireExactly(int) 545 */ 546 void requireMin(int min) throws CommandNotEnoughArgumentsException; 547 548 /** 549 * @param max The maximum amount of arguments allowed. 550 * @throws CommandTooManyArgumentsException If there are more than {@code max} arguments left. 551 * @see #requireMin(int) 552 * @see #requireExactly(int) 553 */ 554 void requireMax(int max) throws CommandTooManyArgumentsException; 555 556 /** 557 * @param args The exact amount of arguments to require. 558 * @throws CommandNotEnoughArgumentsException If there are less than {@code args} arguments left. 559 * @throws CommandTooManyArgumentsException If there are more than {@code args} arguments left. 560 * @see #requireMin(int) 561 * @see #requireMax(int) 562 */ 563 void requireExactly(int args) throws CommandException; 564 565 /** 566 * @return If this {@link IArgConsumer}} has consumed at least one argument. 567 * @see #consumed() 568 * @see #consumedString() 569 */ 570 boolean hasConsumed(); 571 572 /** 573 * @return The last argument this {@link IArgConsumer}} has consumed, or an "unknown" argument, indicated by a 574 * comamnd argument index that has a value of {@code -1}, if no arguments have been consumed yet. 575 * @see #consumedString() 576 * @see #hasConsumed() 577 */ 578 ICommandArgument consumed(); 579 580 /** 581 * @return The value of thelast argument this {@link IArgConsumer}} has consumed, or an empty string if no arguments 582 * have been consumed yet 583 * @see #consumed() 584 * @see #hasConsumed() 585 */ 586 String consumedString(); 587 588 /** 589 * @return A copy of this {@link IArgConsumer}}. It has the same arguments (both consumed and not), but does not 590 * affect or mutate this instance. Useful for the various {@code peek} functions 591 */ 592 IArgConsumer copy(); 593}