Class CommandArgument<C,T>

java.lang.Object
cloud.commandframework.arguments.CommandArgument<C,T>
Type Parameters:
C - Command sender type
T - The type that the argument parses into
All Implemented Interfaces:
CloudKeyHolder<T>, Comparable<CommandArgument<?,?>>
Direct Known Subclasses:
BooleanArgument, ByteArgument, CharArgument, CompoundArgument, DoubleArgument, EnumArgument, FlagArgument, FloatArgument, IntegerArgument, LongArgument, ShortArgument, StaticArgument, StringArgument, StringArrayArgument, UUIDArgument

public class CommandArgument<C,T> extends Object implements Comparable<CommandArgument<?,?>>, CloudKeyHolder<T>
A argument that belongs to a command
  • Constructor Details

    • CommandArgument

      public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C,T> parser, @NonNull String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable BiFunction<CommandContext<C>,String,List<String>> suggestionsProvider, @NonNull ArgumentDescription defaultDescription, @NonNull Collection<@NonNull BiFunction<@NonNull CommandContext<C>,@NonNull Queue<@NonNull String>,@NonNull ArgumentParseResult<Boolean>>> argumentPreprocessors)
      Construct a new command argument
      Parameters:
      required - Whether or not the argument is required
      name - The argument name
      parser - The argument parser
      defaultValue - Default value used when no value is provided by the command sender
      valueType - Type produced by the parser
      suggestionsProvider - Suggestions provider
      defaultDescription - Default description to use when registering
      argumentPreprocessors - Argument preprocessors
      Since:
      1.4.0
    • CommandArgument

      public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C,T> parser, @NonNull String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable BiFunction<CommandContext<C>,String,List<String>> suggestionsProvider, @NonNull Collection<@NonNull BiFunction<@NonNull CommandContext<C>,@NonNull Queue<@NonNull String>,@NonNull ArgumentParseResult<Boolean>>> argumentPreprocessors)
      Construct a new command argument
      Parameters:
      required - Whether or not the argument is required
      name - The argument name
      parser - The argument parser
      defaultValue - Default value used when no value is provided by the command sender
      valueType - Type produced by the parser
      suggestionsProvider - Suggestions provider
      argumentPreprocessors - Argument preprocessors
    • CommandArgument

      public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C,T> parser, @NonNull String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable BiFunction<CommandContext<C>,String,List<String>> suggestionsProvider)
      Construct a new command argument
      Parameters:
      required - Whether or not the argument is required
      name - The argument name
      parser - The argument parser
      defaultValue - Default value used when no value is provided by the command sender
      valueType - Type produced by the parser
      suggestionsProvider - Suggestions provider
    • CommandArgument

      public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C,T> parser, @NonNull String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable BiFunction<CommandContext<C>,String,List<String>> suggestionsProvider, @NonNull ArgumentDescription defaultDescription)
      Construct a new command argument
      Parameters:
      required - Whether or not the argument is required
      name - The argument name
      parser - The argument parser
      defaultValue - Default value used when no value is provided by the command sender
      valueType - Type produced by the parser
      suggestionsProvider - Suggestions provider
      defaultDescription - Default description to use when registering
      Since:
      1.4.0
    • CommandArgument

      public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C,T> parser, @NonNull String defaultValue, @NonNull Class<T> valueType, @Nullable BiFunction<@NonNull CommandContext<C>,@NonNull String,@NonNull List<@NonNull String>> suggestionsProvider)
      Construct a new command argument
      Parameters:
      required - Whether or not the argument is required
      name - The argument name
      parser - The argument parser
      defaultValue - Default value used when no value is provided by the command sender
      valueType - Type produced by the parser
      suggestionsProvider - Suggestions provider
    • CommandArgument

      public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C,T> parser, @NonNull String defaultValue, @NonNull Class<T> valueType, @Nullable BiFunction<@NonNull CommandContext<C>,@NonNull String,@NonNull List<@NonNull String>> suggestionsProvider, @NonNull ArgumentDescription defaultDescription)
      Construct a new command argument
      Parameters:
      required - Whether or not the argument is required
      name - The argument name
      parser - The argument parser
      defaultValue - Default value used when no value is provided by the command sender
      valueType - Type produced by the parser
      suggestionsProvider - Suggestions provider
      defaultDescription - Default description to use when registering
      Since:
      1.4.0
    • CommandArgument

      public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C,T> parser, @NonNull Class<T> valueType)
      Construct a new command argument
      Parameters:
      required - Whether or not the argument is required
      name - The argument name
      parser - The argument parser
      valueType - Type produced by the parser
  • Method Details

    • ofType

      public static <C, T> @NonNull CommandArgument.Builder<C,T> ofType(@NonNull io.leangen.geantyref.TypeToken<T> clazz, @NonNull String name)
      Create a new command argument
      Type Parameters:
      C - Command sender type
      T - Argument Type. Used to make the compiler happy.
      Parameters:
      clazz - Argument class
      name - Argument name
      Returns:
      Argument builder
    • ofType

      public static <C, T> @NonNull CommandArgument.Builder<@NonNull C,@NonNull T> ofType(@NonNull Class<T> clazz, @NonNull String name)
      Create a new command argument
      Type Parameters:
      C - Command sender type
      T - Argument Type. Used to make the compiler happy.
      Parameters:
      clazz - Argument class
      name - Argument name
      Returns:
      Argument builder
    • getKey

      public final @NonNull CloudKey<T> getKey()
      Description copied from interface: CloudKeyHolder
      Get the key that identifies this object.
      Specified by:
      getKey in interface CloudKeyHolder<C>
      Returns:
      Identifying key.
    • isRequired

      public boolean isRequired()
      Check whether or not the command argument is required
      Returns:
      true if the argument is required, false if not
    • getName

      public @NonNull String getName()
      Get the command argument name;
      Returns:
      Argument name
    • getParser

      public @NonNull ArgumentParser<C,T> getParser()
      Get the parser that is used to parse the command input into the corresponding command type
      Returns:
      Command parser
    • toString

      public final @NonNull String toString()
      Overrides:
      toString in class Object
    • addPreprocessor

      public @NonNull CommandArgument<C,T> addPreprocessor(@NonNull BiFunction<@NonNull CommandContext<C>,@NonNull Queue<String>,@NonNull ArgumentParseResult<Boolean>> preprocessor)
      Register a new preprocessor. If all preprocessor has succeeding results that all return true, the argument will be passed onto the parser.

      It is important that the preprocessor doesn't pop any input. Instead, it should only peek.

      Parameters:
      preprocessor - Preprocessor
      Returns:
      this
    • preprocess

      public @NonNull ArgumentParseResult<Boolean> preprocess(@NonNull CommandContext<C> context, @NonNull Queue<String> input)
      Preprocess command input. This will immediately forward any failed argument parse results. If none fails, a true result will be returned
      Parameters:
      context - Command context
      input - Remaining command input. None will be popped
      Returns:
      Parsing error, or argument containing true
    • getOwningCommand

      public @Nullable Command<C> getOwningCommand()
      Get the owning command
      Returns:
      Owning command
    • setOwningCommand

      public void setOwningCommand(@NonNull Command<C> owningCommand)
      Set the owning command
      Parameters:
      owningCommand - Owning command
    • getSuggestionsProvider

      public final @NonNull BiFunction<@NonNull CommandContext<C>,@NonNull String,@NonNull List<String>> getSuggestionsProvider()
      Get the argument suggestions provider
      Returns:
      Suggestions provider
    • getDefaultDescription

      public final @NonNull ArgumentDescription getDefaultDescription()
      Get the default description to use when registering and no other is provided.
      Returns:
      the default description
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public final int compareTo(@NonNull CommandArgument<?,?> o)
      Specified by:
      compareTo in interface Comparable<C>
    • getDefaultValue

      public @NonNull String getDefaultValue()
      Get the default value
      Returns:
      Default value
    • hasDefaultValue

      public boolean hasDefaultValue()
      Check if the argument has a default value
      Returns:
      true if the argument has a default value, false if not
    • getValueType

      public @NonNull io.leangen.geantyref.TypeToken<T> getValueType()
      Get the type of this argument's value
      Returns:
      Value type
    • copy

      public @NonNull CommandArgument<C,T> copy()
      Create a copy of the command argument
      Returns:
      Copied argument
    • isArgumentRegistered

      public boolean isArgumentRegistered()
      Check whether or not the argument has been used in a command
      Returns:
      true if the argument has been used in a command, else false
    • setArgumentRegistered

      public void setArgumentRegistered()
      Indicate that the argument has been associated with a command