Package de.eldoria.eldoutilities.utils
Class ArgumentUtils
java.lang.Object
de.eldoria.eldoutilities.utils.ArgumentUtils
This class contains helpful methods for handling of command arguments.
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringescapeWorldName(String world) static StringescapeWorldName(String world, String replace) static StringescapeWorldName(org.bukkit.World world) static StringescapeWorldName(org.bukkit.World world, String replace) static StringGet the index from the string array .static <T> Optional<T>Get the index parsed.static <T> TgetDefaultFromPlayerOrArg(String[] args, int index, org.bukkit.command.CommandSender sender, Function<org.bukkit.entity.Player, T> playerFunction, Function<String, T> argFunction) static StringgetMessage(String[] strings, int from) Get a message from string array from 'from' to array.length().static StringgetMessage(String[] strings, int from, int to) Get a message from string array from 'from' to 'to'.static StringgetMessage(List<String> strings, int from) Get a message from string array from 'from' to array.length().static StringgetMessage(List<String> strings, int from, int to) Get a message from string array from 'from' to 'to'.static <T> TgetOptionalParameter(String[] arguments, int index, T defaultValue, Function<String, T> parse) Gets a optional parameter.static StringgetOrDefault(String[] arguments, int index, String defaultValue) Get a string value or a default value when the index does not exists.static <T> TgetOrDefault(String[] arguments, int index, Function<String, T> parse, T defaultValue) Get a value from string or a default value when the index does not exists or the parse result is null.static <T> List<T>getRangeAsList(List<T> objects, int from) Get a sublist from 'from' to list.size()static <T> List<T>getRangeAsList(List<T> objects, int from, int to) Get a sublist of a list.static <T> List<T>getRangeAsList(T[] objects, int from) Get a array as sublist from 'from' to array.length().static <T> List<T>getRangeAsList(T[] objects, int from, int to) Get a sublist from array from 'from' to 'to'.static StringgetRangeAsString(String[] strings, int from) Get a array as sublist from 'from' to array.length().static StringgetRangeAsString(String delimiter, String[] source, int from, int to) Returns a range of a string array as string.static org.bukkit.Worldstatic String[]parseQuotedArgs(String[] args) Parse arguments and keep quotes togetherstatic String[]parseQuotedArgs(String args, boolean strip) static StringunescapeWorldName(String world) static StringunescapeWorldName(String world, String replace)
-
Method Details
-
getOrDefault
Get a string value or a default value when the index does not exists.- Parameters:
arguments- array of string arguments.index- index of the requested parameterdefaultValue- default value which will be returned when the index does not exists.- Returns:
- string at index or default value if the index does not exists.
-
getOrDefault
public static <T> T getOrDefault(String[] arguments, int index, Function<String, T> parse, T defaultValue) Get a value from string or a default value when the index does not exists or the parse result is null.- Type Parameters:
T- return type- Parameters:
arguments- array of string arguments.index- index of the requested parameterparse- Function to parse the string to value. Returns null if not parseable.defaultValue- default value which will be returned when the index does not exists.- Returns:
- string at index or default value if the index does not exists.
-
get
Get the index from the string array .- Parameters:
arguments- array of string arguments.index- index of the requested parameter- Returns:
- string or null if the index does not exists
-
get
Get the index parsed.- Type Parameters:
T- type of optional return value- Parameters:
arguments- array of string arguments.index- index of the requested parameterparse- function to parse the string.- Returns:
- the string of the index after the parse function was applied or a empty optional when the index was not found.
-
getOptionalParameter
public static <T> T getOptionalParameter(String[] arguments, int index, T defaultValue, Function<String, T> parse) Gets a optional parameter. Will return the default value when the index is not inside the array.- Type Parameters:
T- type of the returned parameter.- Parameters:
arguments- array of string arguments.index- index of the requested parameterdefaultValue- default value which will be delivered when the index does not exists.parse- function to parse the string.- Returns:
- parsed string value at index or default value if the index does not exists
-
getDefaultFromPlayerOrArg
-
getRangeAsString
Returns a range of a string array as string.- Parameters:
delimiter- delimiter for string joinsource- source arrayfrom- start index (included). Use negative counts to count from the last index.to- end index (excluded). Use negative counts to count from the last index.- Returns:
- range as string
-
getRangeAsString
Get a array as sublist from 'from' to array.length().- Parameters:
strings- argumentsfrom- start index included- Returns:
- string array delimited with ' '
-
unescapeWorldName
-
unescapeWorldName
-
escapeWorldName
-
escapeWorldName
-
escapeWorldName
-
escapeWorldName
-
getWorld
-
parseQuotedArgs
-
parseQuotedArgs
Parse arguments and keep quotes together- Parameters:
args- args to parse- Returns:
- parsed args
-
getMessage
Get a message from string array from 'from' to array.length().- Parameters:
strings- array of strings.from- start index (included). Use negative counts to count from the last index.- Returns:
- array sequence as string
-
getMessage
Get a message from string array from 'from' to array.length().- Parameters:
strings- array of strings.from- start index (included). Use negative counts to count from the last index.- Returns:
- array sequence as string
-
getMessage
Get a message from string array from 'from' to 'to'.- Parameters:
strings- array of strings.from- start index (included). Use negative counts to count from the last index.to- end index (excluded). Use negative counts to count from the last index.- Returns:
- array sequence as string
-
getMessage
Get a message from string array from 'from' to 'to'.- Parameters:
strings- array of strings.from- start index (included). Use negative counts to count from the last index.to- end index (excluded). Use negative counts to count from the last index.- Returns:
- array sequence as string
-
getRangeAsList
Get a array as sublist from 'from' to array.length().- Type Parameters:
T- Type of objects- Parameters:
objects- argumentsfrom- start index included- Returns:
- sublist
-
getRangeAsList
Get a sublist from array from 'from' to 'to'.- Type Parameters:
T- Type of objects- Parameters:
objects- list of objects.from- start index (included). Use negative counts to count from the last index.to- end index (excluded). Use negative counts to count from the last index.- Returns:
- sublist.
-
getRangeAsList
Get a sublist from 'from' to list.size()- Type Parameters:
T- Type of objects- Parameters:
objects- list of objects.from- start index (included). Use negative counts to count from the last index.- Returns:
- sublist.
-
getRangeAsList
Get a sublist of a list.- Type Parameters:
T- Type of objects- Parameters:
objects- list of objects.from- start index (included). Use negative counts to count from the last index.to- end index (excluded). Use negative counts to count from the last index.- Returns:
- sublist.
-