Class ContextProvider<T>

java.lang.Object
redempt.redlib.commandmanager.ContextProvider<T>
Type Parameters:
T - The type this ContextProvider provides

public class ContextProvider<T> extends Object
Used to provide context arguments to command method hooks
  • Field Details

    • mainHand

      public static ContextProvider<org.bukkit.inventory.ItemStack> 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

      public static ContextProvider<org.bukkit.entity.Player> self
      Deprecated.
      Now included by default, there is no need to add it yourself
      Use "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

      public ContextProvider(String name, Function<org.bukkit.entity.Player,T> provider)
      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 ContextProvider
      provider - The function to get the needed context for the given sender
    • ContextProvider

      public ContextProvider(String name, String error, Function<org.bukkit.entity.Player,T> provider)
      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 ContextProvider
      error - The error message to be shown to the user if the provider returns null
      provider - 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 created
      error - The error message to be shown to the user if the predicate returns false
      assertion - 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 created
      assertion - The predicate which tests the assertion
      Returns:
      A ContextProvider which asserts that the given condition is met, and returns false otherwise
    • getName

      public String getName()
      Returns:
      The name of this sender
    • getErrorMessage

      public String getErrorMessage()
      Returns:
      The error message shown to a user if a command using this ContextProvider is run and this ContextProvider returns null
    • map

      public <K> ContextProvider<K> map(String name, String error, Function<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 created
      error - The error message to be shown to the user if the provider returns null
      func - 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 created
      error - The error message to be shown to the user if the provider returns null
      func - 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, Function<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 created
      func - 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, 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 created
      func - The function to convert from the type this ContextProvider returns to the type the new one will
      Returns:
      The resulting ContextProvider
    • provide

      protected T provide(org.bukkit.entity.Player sender)