From 7df948e12f1195460d306379638c9cca81f6b063 Mon Sep 17 00:00:00 2001 From: Cube Date: Sat, 3 Jun 2017 19:08:52 +0300 Subject: [PATCH] Convert ::item command to Kotlin --- game/src/plugins/cmd/src/item-cmd.plugin.kts | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 game/src/plugins/cmd/src/item-cmd.plugin.kts diff --git a/game/src/plugins/cmd/src/item-cmd.plugin.kts b/game/src/plugins/cmd/src/item-cmd.plugin.kts new file mode 100644 index 00000000..7f6f2255 --- /dev/null +++ b/game/src/plugins/cmd/src/item-cmd.plugin.kts @@ -0,0 +1,24 @@ +import org.apollo.cache.def.ItemDefinition +import org.apollo.game.model.entity.setting.PrivilegeLevel + +on_command("item", PrivilegeLevel.ADMINISTRATOR) + .then { player -> + if (!valid_arg_length(arguments, 1..2, player, "Invalid syntax - ::item [id] [amount]")) { + return@then + } + + val id = arguments[0].toInt() + val amount = if (arguments.size == 2) arguments[1].toInt() else 1 + + if (id < 0 || id >= ItemDefinition.count()) { + player.sendMessage("The item id you specified is out of bounds!") + return@then + } + + if (amount < 0) { + player.sendMessage("The amount you specified is out of bounds!") + return@then + } + + player.inventory.add(id, amount) + } \ No newline at end of file