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 voidallowedSender(CommandMeta meta, org.bukkit.command.CommandSender sender) static voidconsole(org.bukkit.command.CommandSender sender) Assert that the sender is of typeConsoleCommandSender.static <T extends Enum<T>>
voidChecks if a enum value is invalid.static voidevalAssertSilent(boolean eval) static voidinvalidArguments(CommandMeta meta, Arguments args) Checks that the arguments have the required lengthstatic voidinvalidArguments(CommandMeta meta, Arguments arguments, Argument... args) Checks that the arguments have the required lengthstatic voidinvalidArguments(CommandMeta meta, String[] args) Checks that the arguments have the required lengthstatic voidinvalidArguments(Arguments arguments, Argument... args) Checks that the arguments have the required length.static voidinvalidLength(String input, int max) static voidstatic voidstatic voidstatic voidstatic voidisFalse(boolean eval, String message, net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... replacements) Throws a command exception when the evaluation is truestatic voidstatic voidstatic voidisTrue(boolean eval, String message, net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... replacements) Throws a command exception when the evaluation is false.static voidmax(double value, double max) Checks if a value is smaller.static voidmax(int value, int max) Checks if a value is smaller.static voidmin(double value, double min) Checks if a value is larger.static voidmin(int value, int min) Checks if a value value is larger.static voidmissingArgument(String[] args, int index) static voidmissingArgument(Collection<?> args, int index) static voidpermission(org.bukkit.command.CommandSender sender, boolean silent, String... permissions) Checks if the user has at least one of the permissions inCommandMeta.permissions().static voidpermission(org.bukkit.command.CommandSender sender, CommandMeta meta, boolean silent) Checks if the user has at least one of the permissions inCommandMeta.permissions().static voidplayer(org.bukkit.command.CommandSender sender) Assert that the sender is a playerstatic voidrange(double value, double min, double max) Checks if a value is in a invalid Range.static voidrange(int value, int min, int max) Checks if a value is in a invalid Range.static voidsender(org.bukkit.command.CommandSender sender, CommandMeta meta) Assert that the sender is one of theCommandMeta.allowedSender()static voidunexpectedRouteEnd(CommandMeta meta, Arguments arguments) static voidunexpectedRouteEnd(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
public static void sender(org.bukkit.command.CommandSender sender, CommandMeta meta) throws CommandException 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(org.bukkit.command.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(org.bukkit.command.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.invalidEnumValuelocale key which should provide a placeholder forVALUEwhich 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
public static void allowedSender(CommandMeta meta, org.bukkit.command.CommandSender sender) throws CommandException - Throws:
CommandException
-