Package redempt.redlib.commandmanager
Class ContextProvider<T>
java.lang.Object
redempt.redlib.commandmanager.ContextProvider<T>
- Type Parameters:
T
- The type this ContextProvider provides
Used to provide context arguments to command method hooks
-
Field Summary
Modifier and TypeFieldDescriptionstatic ContextProvider<org.bukkit.inventory.ItemStack>
Use "mainhand" in the command file.static ContextProvider<org.bukkit.entity.Player>
Deprecated.Now included by default, there is no need to add it yourself -
Constructor Summary
ConstructorDescriptionContextProvider
(String name, String error, Function<org.bukkit.entity.Player, T> provider) Constructs a ContextProvider.ContextProvider
(String name, Function<org.bukkit.entity.Player, T> provider) Constructs a ContextProvider. -
Method Summary
Modifier and TypeMethodDescriptionstatic ContextProvider<Boolean>
assertProvider
(String name, String error, Predicate<org.bukkit.entity.Player> assertion) Creates a ContextProvider which returns true if the predicate's condition is met, and null otherwise, which will cause the command to fail.static ContextProvider<Boolean>
assertProvider
(String name, Predicate<org.bukkit.entity.Player> assertion) Creates a ContextProvider which returns true if the predicate's condition is met, and null otherwise, which will cause the command to fail.getName()
<K> ContextProvider<K>
map
(String name, String error, BiFunction<org.bukkit.entity.Player, T, K> func) Creates a new ContextProvider based on this one which converts from this type to another<K> ContextProvider<K>
Creates a new ContextProvider based on this one which converts from this type to another<K> ContextProvider<K>
map
(String name, BiFunction<org.bukkit.entity.Player, T, K> func) Creates a new ContextProvider based on this one which converts from this type to another<K> ContextProvider<K>
Creates a new ContextProvider based on this one which converts from this type to anotherprotected T
provide
(org.bukkit.entity.Player sender)
-
Field Details
-
mainHand
Use "mainhand" in the command file. Assumes the sender is a player. Returns the item in the player's main hand, or errors if it is air. -
self
Deprecated.Now included by default, there is no need to add it yourselfUse "self" in the command file. Returns the player that ran the command. Useful when you need an optional argument of type player to have a default value of the sender
-
-
Constructor Details
-
ContextProvider
Constructs a ContextProvider. If this constructor is used, the sender will be shown the help menu if the provider returns null- Parameters:
name
- The name of this ContextProviderprovider
- The function to get the needed context for the given sender
-
ContextProvider
Constructs a ContextProvider. If this constructor is used, the sender will be shown the given error message if the provider returns null- Parameters:
name
- The name of this ContextProvidererror
- The error message to be shown to the user if the provider returns nullprovider
- The function to get the needed context for the given sender
-
-
Method Details
-
assertProvider
public static ContextProvider<Boolean> assertProvider(String name, String error, Predicate<org.bukkit.entity.Player> assertion) Creates a ContextProvider which returns true if the predicate's condition is met, and null otherwise, which will cause the command to fail.- Parameters:
name
- The name of the ContextProvider to be createderror
- The error message to be shown to the user if the predicate returns falseassertion
- The predicate which tests the assertion- Returns:
- A ContextProvider which asserts that the given condition is met, and returns false otherwise
-
assertProvider
public static ContextProvider<Boolean> assertProvider(String name, Predicate<org.bukkit.entity.Player> assertion) Creates a ContextProvider which returns true if the predicate's condition is met, and null otherwise, which will cause the command to fail.- Parameters:
name
- The name of the ContextProvider to be createdassertion
- The predicate which tests the assertion- Returns:
- A ContextProvider which asserts that the given condition is met, and returns false otherwise
-
getName
- Returns:
- The name of this sender
-
getErrorMessage
- Returns:
- The error message shown to a user if a command using this ContextProvider is run and this ContextProvider returns null
-
map
Creates a new ContextProvider based on this one which converts from this type to another- Type Parameters:
K
- The type of the resulting ContextProvider- Parameters:
name
- The name of the ContextProvider being createderror
- The error message to be shown to the user if the provider returns nullfunc
- The function to convert from the type this ContextProvider returns to the type the new one will- Returns:
- The resulting ContextProvider
-
map
public <K> ContextProvider<K> map(String name, String error, BiFunction<org.bukkit.entity.Player, T, K> func) Creates a new ContextProvider based on this one which converts from this type to another- Type Parameters:
K
- The type of the resulting ContextProvider- Parameters:
name
- The name of the ContextProvider being createderror
- The error message to be shown to the user if the provider returns nullfunc
- The function to convert from the type this ContextProvider returns to the type the new one will- Returns:
- The resulting ContextProvider
-
map
Creates a new ContextProvider based on this one which converts from this type to another- Type Parameters:
K
- The type of the resulting ContextProvider- Parameters:
name
- The name of the ContextProvider being createdfunc
- The function to convert from the type this ContextProvider returns to the type the new one will- Returns:
- The resulting ContextProvider
-
map
Creates a new ContextProvider based on this one which converts from this type to another- Type Parameters:
K
- The type of the resulting ContextProvider- Parameters:
name
- The name of the ContextProvider being createdfunc
- The function to convert from the type this ContextProvider returns to the type the new one will- Returns:
- The resulting ContextProvider
-
provide
-