Class CommandAssertions

java.lang.Object
de.eldoria.eldoutilities.commands.command.util.CommandAssertions

public final class CommandAssertions extends Object
Util class to throw exceptions based on conditions.
  • Method Details

    • unexpectedRouteEnd

      public static void unexpectedRouteEnd(CommandMeta meta, Arguments arguments) throws CommandException
      Throws:
      CommandException
    • unexpectedRouteEnd

      public static void unexpectedRouteEnd(CommandMeta meta, Optional<AdvancedCommand> command) throws CommandException
      Throws:
      CommandException
    • invalidArguments

      public static void invalidArguments(CommandMeta meta, String[] args) throws CommandException
      Checks that the arguments have the required length
      Parameters:
      meta - meta
      args - arguments
      Throws:
      CommandException - when the arguments are not sufficient.
    • invalidArguments

      public static void invalidArguments(CommandMeta meta, Arguments args) throws CommandException
      Checks that the arguments have the required length
      Parameters:
      meta - meta
      args - arguments
      Throws:
      CommandException - when the arguments are not sufficient.
    • invalidArguments

      public static void invalidArguments(CommandMeta meta, Arguments arguments, Argument... args) throws CommandException
      Checks that the arguments have the required length
      Parameters:
      meta - meta
      args - arguments
      arguments - arguments which are required and optional in correct order
      Throws:
      CommandException - when the arguments are not sufficient.
    • invalidArguments

      public static void invalidArguments(Arguments arguments, Argument... args) throws CommandException
      Checks that the arguments have the required length.

      This method will not create a command call chain.

      Parameters:
      args - arguments
      arguments - arguments which are required and optional in correct order
      Throws:
      CommandException - when the arguments are not sufficient.
      See Also:
    • player

      public static void player(org.bukkit.command.CommandSender sender) throws CommandException
      Assert that the sender is a player
      Parameters:
      sender - sender
      Throws:
      CommandException - when the sender is not a player
    • console

      public static void console(org.bukkit.command.CommandSender sender) throws CommandException
      Assert that the sender is of type ConsoleCommandSender.
      Parameters:
      sender - sender
      Throws:
      CommandException - when the sender is not the console
    • sender

      public static void sender(org.bukkit.command.CommandSender sender, CommandMeta meta) throws CommandException
      Assert that the sender is one of the CommandMeta.allowedSender()
      Parameters:
      sender - sender
      meta - CommandMeta
      Throws:
      CommandException - when the sender is not listed
    • permission

      public static void permission(org.bukkit.command.CommandSender sender, CommandMeta meta, boolean silent) throws CommandException
      Checks if the user has at least one of the permissions in CommandMeta.permissions().
      Parameters:
      sender - sender
      meta - command meta
      silent - true if the permission error should not be reported
      Throws:
      CommandException - when the user has none of the required permissions
    • permission

      public static void permission(org.bukkit.command.CommandSender sender, boolean silent, String... permissions) throws CommandException
      Checks if the user has at least one of the permissions in CommandMeta.permissions().
      Parameters:
      sender - sender
      silent - true if the permission error should not be reported
      permissions - permissions to check
      Throws:
      CommandException - when the user has none of the required permissions
    • range

      public static void range(double value, double min, double max) throws CommandException
      Checks if a value is in a invalid Range.
      Parameters:
      value - current value
      min - min value
      max - max value
      Throws:
      CommandException
    • range

      public static void range(int value, int min, int max) throws CommandException
      Checks if a value is in a invalid Range.
      Parameters:
      value - current value
      min - min value
      max - max value
      Throws:
      CommandException
    • min

      public static void min(int value, int min) throws CommandException
      Checks if a value value is larger.
      Parameters:
      value - current value
      min - min value
      Throws:
      CommandException
    • min

      public static void min(double value, double min) throws CommandException
      Checks if a value is larger.
      Parameters:
      value - current value
      min - min value
      Throws:
      CommandException
    • max

      public static void max(int value, int max) throws CommandException
      Checks if a value is smaller.
      Parameters:
      value - current value
      max - max value (inclusive)
      Throws:
      CommandException
    • max

      public static void max(double value, double max) throws CommandException
      Checks if a value is smaller.
      Parameters:
      value - current value
      max - max value (inclusive)
      Throws:
      CommandException
    • enumValue

      public static <T extends Enum<T>> void enumValue(String value, Class<T> clazz) throws CommandException
      Checks if a enum value is invalid. Will send a message based on error.invalidEnumValue locale key which should provide a placeholder for VALUE which will be replaced with an array of possible inputs
      Type Parameters:
      T - type of enum
      Parameters:
      value - value of enum
      clazz - clazz of enum
      Throws:
      CommandException
    • invalidNumber

      public static void invalidNumber() throws CommandException
      Throws:
      CommandException
    • isInteger

      public static void isInteger(String value) throws CommandException
      Throws:
      CommandException
    • isLong

      public static void isLong(String value) throws CommandException
      Throws:
      CommandException
    • isDouble

      public static void isDouble(String value) throws CommandException
      Throws:
      CommandException
    • isBoolean

      public static void isBoolean(String value) throws CommandException
      Throws:
      CommandException
    • isBoolean

      public static void isBoolean(String value, String isTrue, String isFalse) throws CommandException
      Throws:
      CommandException
    • invalidLength

      public static void invalidLength(String input, int max) throws CommandException
      Throws:
      CommandException
    • missingArgument

      public static void missingArgument(String[] args, int index) throws CommandException
      Throws:
      CommandException
    • missingArgument

      public static void missingArgument(Collection<?> args, int index) throws CommandException
      Throws:
      CommandException
    • isFalse

      public static void isFalse(boolean eval, String message, net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... replacements) throws CommandException
      Throws a command exception when the evaluation is true
      Parameters:
      eval - value
      message - message to send
      replacements - replacements
      Throws:
      CommandException - when eval is true
    • isTrue

      public static void isTrue(boolean eval, String message, net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... replacements) throws CommandException
      Throws a command exception when the evaluation is false.
      Parameters:
      eval - value
      message - message to send
      replacements - replacements
      Throws:
      CommandException - when eval is false
    • evalAssertSilent

      public static void evalAssertSilent(boolean eval) throws CommandException
      Throws:
      CommandException
    • allowedSender

      public static void allowedSender(CommandMeta meta, org.bukkit.command.CommandSender sender) throws CommandException
      Throws:
      CommandException