Package redempt.redlib.commandmanager
Class ArgType<T>
java.lang.Object
redempt.redlib.commandmanager.ArgType<T>
- Type Parameters:
T
- The type this ArgType converts to
- Direct Known Subclasses:
ArgSubtype
A command argument type, which converts a String argument to another type
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
-
Constructor Summary
ModifierConstructorDescriptionArgType
(String name, BiFunction<org.bukkit.command.CommandSender, String, T> convert) Create an ArgType from a name and converterCreate an ArgType from a name and converterprotected
ArgType
(String name, ArgType<?> parent, ArgType.ArgConverter<T, ?> convert) -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkConstraint
(org.bukkit.command.CommandSender sender, Constraint<T> constraint, T value) constraint
(Function<String, Constraint<T>> constraint) Set the handler to check constraints for this typeConverts an argument to another typegetConstraint
(String constraintContents) static ArgType<?>
getDefault
(String name) Gets a default ArgType by namegetName()
ArgType<?>
<K> ArgType<K>
map
(String name, BiFunction<org.bukkit.command.CommandSender, T, K> func) Creates a new ArgType based on this one which converts from this type to another<K> ArgType<K>
Creates a new ArgType based on this one which converts from this type to anotherCreates an ArgType for an enum, which will accept all of the enum's values as arguments and offer all enum values as tab completionsCreates an ArgType for a set of possible string inputsstatic <T> ArgType<T>
Creates an ArgType for a map of a String to another typesetTab
(BiFunction<org.bukkit.command.CommandSender, String[], List<String>> tab) Sets the tab completer for this typeSets the tab completer for this typesetTab
(ArgType.TabCompleter<?> tab) <K> ArgSubtype<K,
T> subType
(String name, BiFunction<String, T, K> convert) Creates a new ArgSubtype with this ArgType as its parent.<K> ArgSubtype<K,
T> subType
(String name, ArgType.ArgConverter<K, T> convert) Creates a new ArgSubtype with this ArgType as its parent.tabComplete
(org.bukkit.command.CommandSender sender, String[] args, Object prev) Gets tab completionstabStream
(BiFunction<org.bukkit.command.CommandSender, String[], Stream<String>> tab) Sets the tab completer for this type, can be used instead of tabSets the tab completer for this type, can be used instead of tab
-
Constructor Details
-
ArgType
-
ArgType
Create an ArgType from a name and converter- Parameters:
name
- The name of this command argument type, to be used in the command fileconvert
- TheFunction
to convert from a String to whatever type this converts to
-
ArgType
Create an ArgType from a name and converter- Parameters:
name
- The name of this command argument type, to be used in the command fileconvert
- TheBiFunction
to convert from a String to whatever type this converts to
-
-
Method Details
-
getDefault
Gets a default ArgType by name- Parameters:
name
- The name of the default ArgType- Returns:
- The ArgType, or null if there is not a default one by that name
-
of
Creates an ArgType for an enum, which will accept all of the enum's values as arguments and offer all enum values as tab completions- Type Parameters:
T
- The enum type- Parameters:
name
- The name of the ArgTypeclazz
- The enum class to make an ArgType from- Returns:
- An ArgType for the given enum
-
of
Creates an ArgType for a set of possible string inputs- Parameters:
name
- The name of the ArgTypevalues
- The list of possible inputs- Returns:
- An ArgType for the given inputs, which will offer tab completion and accept any of the supplied strings, or return null if the given argument does not match any of them
-
of
Creates an ArgType for a map of a String to another type- Type Parameters:
T
- The type this ArgType will provide- Parameters:
name
- The name of the ArgTypemap
- The map from String to the type this ArgType will provide- Returns:
- The constructed ArgType
-
getParent
- Returns:
- The parent type of this ArgType, or null
-
setTab
Sets the tab completer for this type- Parameters:
tab
- The function returning a List of all completions for this sender- Returns:
- itself
-
constraint
Set the handler to check constraints for this type- Parameters:
constraint
- A predicate to check constraints - return false to fail- Returns:
- itself
-
checkConstraint
public boolean checkConstraint(org.bukkit.command.CommandSender sender, Constraint<T> constraint, T value) -
setTab
Sets the tab completer for this type- Parameters:
tab
- The function returning a List of all completions for this sender- Returns:
- itself
-
setTab
-
tabStream
Sets the tab completer for this type, can be used instead of tab- Parameters:
tab
- The function returning a Stream of all completions for this sender- Returns:
- itself
-
tabStream
public ArgType<T> tabStream(BiFunction<org.bukkit.command.CommandSender, String[], Stream<String>> tab) Sets the tab completer for this type, can be used instead of tab- Parameters:
tab
- The function returning a Stream of all completions for this sender- Returns:
- itself
-
tabComplete
public List<String> tabComplete(org.bukkit.command.CommandSender sender, String[] args, Object prev) Gets tab completions- Parameters:
sender
- The sender of the commandargs
- The previous argumentsprev
- The previous value- Returns:
- The tab completions
-
getName
- Returns:
- The name of this argument type
-
convert
Converts an argument to another type- Parameters:
sender
- The sender of the commandprevious
- The value of the previous argumentargument
- The argument to be converted- Returns:
- The converted argument for use in a method hook
-
getConstraint
-
map
Creates a new ArgType based on this one which converts from this type to another- Type Parameters:
K
- The type of the resulting ArgType- Parameters:
name
- The name of the ArgType being createdfunc
- The function to convert from the type this ArgType returns to the type the new one will- Returns:
- The resulting ArgType
-
map
Creates a new ArgType based on this one which converts from this type to another- Type Parameters:
K
- The type of the resulting ArgType- Parameters:
name
- The name of the ArgType being createdfunc
- The function to convert from the type this ArgType returns to the type the new one will- Returns:
- The resulting ArgType
-
subType
Creates a new ArgSubtype with this ArgType as its parent. ArgSubtypes are argument types which must follow another argument type, and use info from the previous argument to determine their values for conversion and tab completion.- Type Parameters:
K
- The type the new ArgSubtype will convert to- Parameters:
name
- The name of the new ArgSubtypeconvert
- The function to convert using the previous argument value- Returns:
- The created ArgSubtype
-
subType
Creates a new ArgSubtype with this ArgType as its parent. ArgSubtypes are argument types which must follow another argument type, and use info from the previous argument to determine their values for conversion and tab completion.- Type Parameters:
K
- The type the new ArgSubtype will convert to- Parameters:
name
- The name of the new ArgSubtypeconvert
- The function to convert using the previous argument value- Returns:
- The created ArgSubtype
-