Class CommandAssertions
java.lang.Object
de.eldoria.eldoutilities.commands.command.util.CommandAssertions
Util class to throw exceptions based on conditions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
allowedSender
(CommandMeta meta, CommandSender sender) static void
console
(CommandSender sender) Assert that the sender is of typeConsoleCommandSender
.static <T extends Enum<T>>
voidChecks if a enum value is invalid.static void
evalAssertSilent
(boolean eval) static void
invalidArguments
(CommandMeta meta, Arguments args) Checks that the arguments have the required lengthstatic void
invalidArguments
(CommandMeta meta, Arguments arguments, Argument... args) Checks that the arguments have the required lengthstatic void
invalidArguments
(CommandMeta meta, String[] args) Checks that the arguments have the required lengthstatic void
invalidArguments
(Arguments arguments, Argument... args) Checks that the arguments have the required length.static void
invalidLength
(String input, int max) static void
static void
static void
static void
static void
isFalse
(boolean eval, String message, net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... replacements) Throws a command exception when the evaluation is truestatic void
static void
static void
isTrue
(boolean eval, String message, net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... replacements) Throws a command exception when the evaluation is false.static void
max
(double value, double max) Checks if a value is smaller.static void
max
(int value, int max) Checks if a value is smaller.static void
min
(double value, double min) Checks if a value is larger.static void
min
(int value, int min) Checks if a value value is larger.static void
missingArgument
(String[] args, int index) static void
missingArgument
(Collection<?> args, int index) static void
permission
(CommandSender sender, boolean silent, String... permissions) Checks if the user has at least one of the permissions inCommandMeta.permissions()
.static void
permission
(CommandSender sender, CommandMeta meta, boolean silent) Checks if the user has at least one of the permissions inCommandMeta.permissions()
.static void
player
(CommandSender sender) Assert that the sender is a playerstatic void
range
(double value, double min, double max) Checks if a value is in a invalid Range.static void
range
(int value, int min, int max) Checks if a value is in a invalid Range.static void
sender
(CommandSender sender, CommandMeta meta) Assert that the sender is one of theCommandMeta.allowedSender()
static void
unexpectedRouteEnd
(CommandMeta meta, Arguments arguments) static void
unexpectedRouteEnd
(CommandMeta meta, Optional<AdvancedCommand> command)
-
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
Checks that the arguments have the required length- Parameters:
meta
- metaargs
- arguments- Throws:
CommandException
- when the arguments are not sufficient.
-
invalidArguments
Checks that the arguments have the required length- Parameters:
meta
- metaargs
- 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
- metaargs
- argumentsarguments
- arguments which are required and optional in correct order- Throws:
CommandException
- when the arguments are not sufficient.
-
invalidArguments
Checks that the arguments have the required length.This method will not create a command call chain.
- Parameters:
args
- argumentsarguments
- arguments which are required and optional in correct order- Throws:
CommandException
- when the arguments are not sufficient.- See Also:
-
player
Assert that the sender is a player- Parameters:
sender
- sender- Throws:
CommandException
- when the sender is not a player
-
console
Assert that the sender is of typeConsoleCommandSender
.- Parameters:
sender
- sender- Throws:
CommandException
- when the sender is not the console
-
sender
Assert that the sender is one of theCommandMeta.allowedSender()
- Parameters:
sender
- sendermeta
- CommandMeta- Throws:
CommandException
- when the sender is not listed
-
permission
public static void permission(CommandSender sender, CommandMeta meta, boolean silent) throws CommandException Checks if the user has at least one of the permissions inCommandMeta.permissions()
.- Parameters:
sender
- sendermeta
- command metasilent
- 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(CommandSender sender, boolean silent, String... permissions) throws CommandException Checks if the user has at least one of the permissions inCommandMeta.permissions()
.- Parameters:
sender
- sendersilent
- true if the permission error should not be reportedpermissions
- permissions to check- Throws:
CommandException
- when the user has none of the required permissions
-
range
Checks if a value is in a invalid Range.- Parameters:
value
- current valuemin
- min valuemax
- max value- Throws:
CommandException
-
range
Checks if a value is in a invalid Range.- Parameters:
value
- current valuemin
- min valuemax
- max value- Throws:
CommandException
-
min
Checks if a value value is larger.- Parameters:
value
- current valuemin
- min value- Throws:
CommandException
-
min
Checks if a value is larger.- Parameters:
value
- current valuemin
- min value- Throws:
CommandException
-
max
Checks if a value is smaller.- Parameters:
value
- current valuemax
- max value (inclusive)- Throws:
CommandException
-
max
Checks if a value is smaller.- Parameters:
value
- current valuemax
- 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 onerror.invalidEnumValue
locale key which should provide a placeholder forVALUE
which will be replaced with an array of possible inputs- Type Parameters:
T
- type of enum- Parameters:
value
- value of enumclazz
- clazz of enum- Throws:
CommandException
-
invalidNumber
- Throws:
CommandException
-
isInteger
- Throws:
CommandException
-
isLong
- Throws:
CommandException
-
isDouble
- Throws:
CommandException
-
isBoolean
- Throws:
CommandException
-
isBoolean
- Throws:
CommandException
-
invalidLength
- Throws:
CommandException
-
missingArgument
- Throws:
CommandException
-
missingArgument
- 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
- valuemessage
- message to sendreplacements
- 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
- valuemessage
- message to sendreplacements
- replacements- Throws:
CommandException
- when eval is false
-
evalAssertSilent
- Throws:
CommandException
-
allowedSender
- Throws:
CommandException
-