Class ArgType<T,V>

java.lang.Object
redempt.ordinate.command.ArgType<T,V>
Type Parameters:
T - The sender type
V - The argument type
All Implemented Interfaces:
Named

public class ArgType<T,V> extends Object implements Named
Represents a parsable type that can be used in command arguments
  • Constructor Details

    • ArgType

      public ArgType(String name, BiFunction<CommandContext<T>,String,V> converter)
      Parameters:
      name - The name of the ArgType
      converter - A function to parse the type
    • ArgType

      public ArgType(String name, Function<String,V> converter)
      Parameters:
      name - The name of the ArgType
      converter - A function to parse the type
  • Method Details

    • of

      public static <T, V> ArgType<T,V> of(String name, Map<String,V> map)
    • getName

      public String getName()
      Specified by:
      getName in interface Named
    • convert

      public V convert(CommandContext<T> context, String arg)
      Convert an argument
      Parameters:
      context - The context of the command's execution
      arg - The string value of the argument
      Returns:
      The parsed value
    • complete

      public Collection<String> complete(CommandContext<T> context, String partial)
      Get completions for a given partial string
      Parameters:
      context - The context of the command's execution
      partial - The partial argument
      Returns:
      A collection of completions
    • constraint

      public ArgType<T,V> constraint(ConstraintParser<T,V> constraintParser)
      Assign a ConstraintParser, which can be used to set constraints for this type in the command file
      Parameters:
      constraintParser - The constraint parser
      Returns:
      Itself
    • completer

      public ArgType<T,V> completer(BiFunction<CommandContext<T>,String,Collection<String>> completer)
      Set how completions for this type should be computed
      Parameters:
      completer - A function which provides completions
      Returns:
      Itself
    • completer

      public ArgType<T,V> completer(Function<CommandContext<T>,Collection<String>> completer)
      Set how completions for this type should be computed
      Parameters:
      completer - A function which provides completions
      Returns:
      Itself
    • completerStream

      public ArgType<T,V> completerStream(BiFunction<CommandContext<T>,String,Stream<String>> completer)
      Set how completions for this type should be computed
      Parameters:
      completer - A function which provides completions
      Returns:
      Itself
    • completerStream

      public ArgType<T,V> completerStream(Function<CommandContext<T>,Stream<String>> completer)
      Set how completions for this type should be computed
      Parameters:
      completer - A function which provides completions
      Returns:
      Itself
    • getConstraintParser

      public ConstraintParser<T,V> getConstraintParser()
      Returns:
      The constraint parser for this type