From 6db98406d51c334653ff194743b436ca503e90e2 Mon Sep 17 00:00:00 2001 From: Cube Date: Sun, 4 Jun 2017 18:08:53 +0300 Subject: [PATCH] Overload valid_arg_length --- game/src/plugins/util/command/src/command.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/game/src/plugins/util/command/src/command.kt b/game/src/plugins/util/command/src/command.kt index bd693948..7746d948 100644 --- a/game/src/plugins/util/command/src/command.kt +++ b/game/src/plugins/util/command/src/command.kt @@ -4,16 +4,17 @@ import org.apollo.game.model.entity.Player * Checks whether the amount of arguments provided is correct, sending the player the specified * message if not. */ -fun valid_arg_length(args: Array, length: Any, player: Player, message: String): Boolean { - val valid = when (length) { - is Int -> length == args.size - is IntRange -> length.contains(args.size) - else -> { - throw IllegalArgumentException("length must be one of the following: Int, IntRange") - } - } +fun valid_arg_length(args: Array, length: IntRange, player: Player, message: String): Boolean { + val valid = length.contains(args.size) if (!valid) { player.sendMessage(message) } return valid -} \ No newline at end of file +} + +/** + * Checks whether the amount of arguments provided is correct, sending the player the specified + * message if not. + */ +fun valid_arg_length(args: Array, length: Int, player: Player, message: String) + = valid_arg_length(args, IntRange(length, length), player, message) \ No newline at end of file