From b99ee9ba31a4ddc8d7412f9191dc7c8785990c31 Mon Sep 17 00:00:00 2001 From: Cube Date: Sat, 3 Jun 2017 18:55:40 +0300 Subject: [PATCH] Convert ::animate command to Kotlin --- game/src/plugins/cmd/meta.toml | 7 ++++++- .../plugins/cmd/src/animate-cmd.plugin.kts | 9 +++++++++ game/src/plugins/util/command/meta.toml | 5 +++++ game/src/plugins/util/command/src/command.kt | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 game/src/plugins/cmd/src/animate-cmd.plugin.kts create mode 100644 game/src/plugins/util/command/meta.toml create mode 100644 game/src/plugins/util/command/src/command.kt diff --git a/game/src/plugins/cmd/meta.toml b/game/src/plugins/cmd/meta.toml index 141c3a7b..84ece10b 100644 --- a/game/src/plugins/cmd/meta.toml +++ b/game/src/plugins/cmd/meta.toml @@ -1,6 +1,11 @@ name = "Chat commands" package = "org.apollo.game.plugin.cmd" -authors = [ "Graham", "cubeee" ] +dependencies = [ "command_utilities" ] +authors = [ + "Graham", + "Major", + "cubeee" +] [config] srcDir = "src/" diff --git a/game/src/plugins/cmd/src/animate-cmd.plugin.kts b/game/src/plugins/cmd/src/animate-cmd.plugin.kts new file mode 100644 index 00000000..55b71306 --- /dev/null +++ b/game/src/plugins/cmd/src/animate-cmd.plugin.kts @@ -0,0 +1,9 @@ +import org.apollo.game.model.Animation +import org.apollo.game.model.entity.setting.PrivilegeLevel + +on_command("animate", PrivilegeLevel.MODERATOR) + .then { player -> + if(valid_arg_length(arguments, 1, player, "Invalid syntax - ::animate [animation-id]")) { + player.playAnimation(Animation(arguments[0].toInt())) + } + } \ No newline at end of file diff --git a/game/src/plugins/util/command/meta.toml b/game/src/plugins/util/command/meta.toml new file mode 100644 index 00000000..2d962919 --- /dev/null +++ b/game/src/plugins/util/command/meta.toml @@ -0,0 +1,5 @@ +name = "command utilities" +package = "org.apollo.game.plugins.util" + +[config] +srcDir = "src/" \ No newline at end of file diff --git a/game/src/plugins/util/command/src/command.kt b/game/src/plugins/util/command/src/command.kt new file mode 100644 index 00000000..bd693948 --- /dev/null +++ b/game/src/plugins/util/command/src/command.kt @@ -0,0 +1,19 @@ +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") + } + } + if (!valid) { + player.sendMessage(message) + } + return valid +} \ No newline at end of file