Class ArgumentTypes

java.lang.Object
net.forthecrown.grenadier.types.ArgumentTypes

public final class ArgumentTypes extends Object
Static factory and instance provider methods for argument types
  • Method Details

    • item

      public static ItemArgument item()
      Gets the item argument
      Returns:
      Item argument
    • itemFilter

      public static ItemFilterArgument itemFilter()
      Gets the item filter argument
      Returns:
      Item filter argument
    • component

      public static ComponentArgument component()
      Gets the chat component argument
      Returns:
      Chat component argument
    • key

      public static KeyArgument key()
      Gets the namespaced key argument
      Returns:
      Namespaced key argument
    • world

      public static WorldArgument world()
      Gets the world argument
      Returns:
      World argument
    • binaryTag

      public static NbtArgument<BinaryTag> binaryTag()
      Gets the binary tag argument
      Returns:
      Binary tag argument
    • compoundTag

      public static NbtArgument<CompoundTag> compoundTag()
      Gets the compound tag argument
      Returns:
      Compound tag argument
    • tagPath

      public static TagPathArgument tagPath()
      Gets the NBT path argument
      Returns:
      NBT path argument
    • gameMode

      public static GameModeArgument gameMode()
      Gets the gamemode argument
      Returns:
      Gamemode argument
    • time

      public static TimeArgument time()
      Gets the time duration argument
      Returns:
      Time duration argument
    • getDuration

      public static Duration getDuration(CommandContext<?> context, String argument) throws IllegalArgumentException
      Gets a parsed duration
      Parameters:
      context - Command context
      argument - Name of the argument
      Returns:
      Found duration
      Throws:
      IllegalArgumentException - If the specified argument doesn't exist, or if it isn't a Duration
    • getMillis

      public static long getMillis(CommandContext<?> context, String argument) throws IllegalArgumentException
      Gets a parsed duration, in milliseconds
      Parameters:
      context - Command context
      argument - Name of the argument
      Returns:
      Found duration, in milliseconds
      Throws:
      IllegalArgumentException - If the specified argument doesn't exist, or if it isn't a Duration
    • getTicks

      public static long getTicks(CommandContext<?> context, String argument) throws IllegalArgumentException
      Gets a parsed duration, in game ticks
      Parameters:
      context - Command context
      argument - Name of the argument
      Returns:
      Found duration, in game ticks
      Throws:
      IllegalArgumentException - If the specified argument doesn't exist, or if it isn't a Duration
    • objective

      public static ObjectiveArgument objective()
      Gets the scoreboard objective argument
      Returns:
      Scoreboard objective argument
    • team

      public static TeamArgument team()
      Gets the scoreboard team argument
      Returns:
      Scoreboard team argument
    • localDate

      public static LocalDateArgument localDate()
      Gets the local date argument
      Returns:
      Local date argument
    • block

      public static BlockArgument block()
      Gets the block argument
      Returns:
      Block argument
    • blockFilter

      public static BlockFilterArgument blockFilter()
      Gets the block filter argument
      Returns:
      Block filter argument
    • entity

      public static EntityArgument entity()
      Gets an entity selector argument that is allowed to only return 1 entity
      Returns:
      Entity selector argument
    • getSelector

      public static EntitySelector getSelector(CommandContext<?> context, String argument) throws IllegalArgumentException
      Gets an entity selector from a specified context
      Parameters:
      context - Command context
      argument - Name of the argument
      Returns:
      Found entity selector
      Throws:
      IllegalArgumentException - If the specified argument doesn't exist, or if it isn't an EntitySelector
    • getEntity

      public static Entity getEntity(CommandContext<CommandSource> context, String argument) throws CommandSyntaxException, IllegalArgumentException
      Gets a single entity from parsed a entity selector
      Parameters:
      context - Command context
      argument - Name of the argument
      Returns:
      Found entity
      Throws:
      IllegalArgumentException - If the specified argument doesn't exist, or if it isn't an EntitySelector
      CommandSyntaxException - If no entity was found, or if the command source in the provided context isn't allowed to access entity selectors
    • entities

      public static EntityArgument entities()
      Gets an entity selector argument that allows for multiple entities to be returned
      Returns:
      Entity selector argument
    • getEntities

      public static List<Entity> getEntities(CommandContext<CommandSource> context, String argument) throws CommandSyntaxException, IllegalArgumentException
      Gets a list of entities from a parsed entity selector
      Parameters:
      context - Command context
      argument - Name of the argument
      Returns:
      Found entities
      Throws:
      IllegalArgumentException - If the specified argument doesn't exist, or if it isn't an EntitySelector
      CommandSyntaxException - If no entity was found, or if the command source in the provided context isn't allowed to access entity selectors
    • player

      public static EntityArgument player()
      Gets an entity selector argument that only allows a single player to be returned
      Returns:
      Entity selector argument
    • getPlayer

      public static Player getPlayer(CommandContext<CommandSource> context, String argument) throws CommandSyntaxException, IllegalArgumentException
      Gets a single player from a parsed entity selector
      Parameters:
      context - Command context
      argument - Name of the argument
      Returns:
      Found player
      Throws:
      IllegalArgumentException - If the specified argument doesn't exist, or if it isn't an EntitySelector
      CommandSyntaxException - If no entity was found, or if the command source in the provided context isn't allowed to access entity selectors
    • players

      public static EntityArgument players()
      Gets and entity selector argument that is only allowed to return players
      Returns:
      Entity selector argument
    • getPlayers

      public static List<Player> getPlayers(CommandContext<CommandSource> context, String argument) throws CommandSyntaxException, IllegalArgumentException
      Gets a list of players from a parsed entity selector
      Parameters:
      context - Command context
      argument - Name of the argument
      Returns:
      Found players
      Throws:
      IllegalArgumentException - If the specified argument doesn't exist, or if it isn't an EntitySelector
      CommandSyntaxException - If no entity was found, or if the command source in the provided context isn't allowed to access entity selectors
    • lootTable

      public static LootTableArgument lootTable()
      Gets the loot table argument
      Returns:
      Loot table argument
    • particle

      public static ParticleArgument particle()
      Gets the particle argument
      Returns:
      Particle argument
    • uuid

      public static UuidArgument uuid()
      Gets the UUID argument
      Returns:
      UUID argument
    • doubleRange

      public static DoubleRangeArgument doubleRange()
      Gets the double range argument.

      Argument type that returns a range between 2 double values. The range parsed by this argument type is inclusive on both ends.

      Input examples:

       1..2  = Between 1 and 2
       ..2.5 = At most 2.5
       3.1.. = At least 3.1
       
      Returns:
      Double range argument
    • intRange

      public static IntRangeArgument intRange()
      Gets the double range argument.

      Argument type that returns a range between 2 integer values. The range parsed by this argument type is inclusive on both ends.

      Input examples:

       15..35 = Between 15 and 35
       ..17   = At most 17
       7..    = At least 7
       
      Returns:
      Int range argument
    • position

      public static PositionArgument position()
      Gets an argument that parses a 3D floating point position
      Returns:
      Position argument
    • blockPosition

      public static PositionArgument blockPosition()
      Gets an argument that parses a 3D integer position
      Returns:
      Block position argument
    • position2d

      public static PositionArgument position2d()
      Gets an argument that parses a 2D floating point position
      Returns:
      2D position argument
    • blockPosition2d

      public static PositionArgument blockPosition2d()
      Gets an argument that parses a 2D integer position
      Returns:
      2D block position argument
    • getLocation

      public static Location getLocation(CommandContext<CommandSource> context, String argument) throws IllegalArgumentException
      Gets a parsed location.

      Gets the parsed position from the specified context and t hen calls ParsedPosition.apply(CommandSource) with the command source in the context

      Parameters:
      context - Command context
      argument - Name of the argument
      Returns:
      Gotten location
      Throws:
      IllegalArgumentException - If the specified argument doesn't exist, or if it isn't a ParsedPosition
    • enchantment

      public static RegistryArgument<Enchantment> enchantment()
      Returns:
      Created argument type
    • potionType

      public static RegistryArgument<PotionEffectType> potionType()
      Returns:
      Created argument type
    • registry

      public static <T extends Keyed> RegistryArgument<T> registry(Registry<T> registry, RegistryArgument.UnknownFactory factory)
      Creates a registry argument with the specified backing registry and specified exception factory
      Type Parameters:
      T - Registry type
      Parameters:
      registry - Backing registry
      factory - Exception factory used to create exceptions for unknown elements
      Returns:
      Created argument type
    • registry

      public static <T extends Keyed> RegistryArgument<T> registry(Registry<T> registry, String name)
      Creates a registry argument with the specified backing registry and specified name

      Uses ExceptionProvider.unknownResource(NamespacedKey, String, StringReader) to create the error messages

      Type Parameters:
      T - Registry type
      Parameters:
      registry - Backing registry
      name - Registry name
      Returns:
      Created argument type
      See Also:
    • enumType

      public static <E extends Enum<E>> EnumArgument<E> enumType(Class<E> enumType)
      Creates an enum argument for the specified enumType
      Type Parameters:
      E - Enum type
      Parameters:
      enumType - Enum class that will be parsed
      Returns:
      Created argument type
    • map

      public static <T> MapArgument<T> map(Map<String,T> values) throws IllegalArgumentException
      Creates a map-based argument type with the specified backing map.

      Note: no key in the specified values map may feature a whitespace character, as whitespace characters are used to detect when to stop reading input

      Type Parameters:
      T - Map values
      Parameters:
      values - Parse values
      Returns:
      Created argument type
      Throws:
      IllegalArgumentException - If any key in the backing map contained a whitespace character
    • array

      public static <T> ArrayArgument<T> array(ArgumentType<T> type)
      Creates an array argument for the specified type
      Type Parameters:
      T - Array type
      Parameters:
      type - Individual element parser
      Returns:
      Created array argument
    • map

      public static <F, T> ArgumentType<T> map(ArgumentType<F> fromType, Function<F,T> translator)
      Maps one argument types results to another type.

      For example, say we want to map a TimeArgument's result from a Duration to milliseconds, we would this like so:

      
       final TimeArgument time = ArgumentTypes.time();
      
       final ArgumentType<Long> mapped
           = ArgumentTypes.map(time, Duration::toMillis);
       
      The mapped type will use the same parser and provide the same suggestions as the specified fromType
      Type Parameters:
      F - Base type that will be mapped
      T - Target type
      Parameters:
      fromType - The base type that will parse and provide suggestions
      translator - The function that translates the base's type
      Returns:
      Mapped argument type