From 34f06b20c49b957e48baaf49ba7ed35735d37e95 Mon Sep 17 00:00:00 2001 From: Caleb Foust Date: Sun, 1 Apr 2018 18:17:11 -0700 Subject: [PATCH] Add teleportation to places using ::tele [name] --- game/plugin/cmd/src/teleport-cmd.plugin.kts | 60 ++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/game/plugin/cmd/src/teleport-cmd.plugin.kts b/game/plugin/cmd/src/teleport-cmd.plugin.kts index 712fb720c..bd1162ccc 100644 --- a/game/plugin/cmd/src/teleport-cmd.plugin.kts +++ b/game/plugin/cmd/src/teleport-cmd.plugin.kts @@ -18,12 +18,68 @@ on_command("pos", PrivilegeLevel.MODERATOR) player.sendMessage("You are at: ($x, $y, $z) in region (${region.x}, ${region.y}).") } +val TELEPORT_DESTINATIONS = listOf( + "alkharid" to Position(3292, 3171, 0), + "ardougne" to Position(2662, 3304, 0), + "barrows" to Position(3565, 3314, 0), + "brimhaven" to Position(2802, 3179, 0), + "burthorpe" to Position(2898, 3545, 0), + "camelot" to Position(2757, 3478, 0), + "canifis" to Position(3493, 3489, 0), + "cw" to Position(2442, 3090, 0), + "draynor" to Position(3082, 3249, 0), + "duelarena" to Position(3370, 3267, 0), + "edgeville" to Position(3087, 3504, 0), + "entrana" to Position(2827, 3343, 0), + "falador" to Position(2965, 3379, 0), + "ge" to Position(3164, 3476, 0), + "kbd" to Position(2273, 4680, 0), + "keldagrim" to Position(2845, 10210, 0), + "kq" to Position(3507, 9494, 0), + "lumbridge" to Position(3222, 3219, 0), + "lunar" to Position(2113, 3915, 0), + "misc" to Position(2515, 3866, 0), + "neit" to Position(2332, 3804, 0), + "pc" to Position(2658, 2660, 0), + "rellekka" to Position(2660, 3657, 0), + "shilo" to Position(2852, 2955, 0), + "taverley" to Position(2895, 3443, 0), + "tutorial" to Position(3094, 3107, 0), + "tzhaar" to Position(2480, 5175, 0), + "varrock" to Position(3212, 3423, 0), + "yanille" to Position(2605, 3096, 0), + "zanaris" to Position(2452, 4473, 0) +) + /** * Teleports the player to the specified position. */ on_command("tele", PrivilegeLevel.ADMINISTRATOR) .then { player -> - val invalidSyntax = "Invalid syntax - ::tele [x] [y] [optional-z]" + val invalidSyntax = "Invalid syntax - ::tele [x] [y] [optional-z] or ::tele [place name]" + + if (arguments.size == 1) { + val query = arguments[0] + val results = TELEPORT_DESTINATIONS.filter { + (name, _) -> name.startsWith(query) + } + + if (results.size == 0) { + player.sendMessage("No destinations matching '$query'.") + return@then + } else if (results.size > 1) { + player.sendMessage("Ambiguous query '$query' (could " + + "be $results). Please disambiguate.") + return@then + } + + val (name, dest) = results[0] + player.sendMessage("Teleporting to $name.") + player.teleport(dest) + + return@then + } + if (!valid_arg_length(arguments, 2..3, player, invalidSyntax)) { return@then } @@ -53,4 +109,4 @@ on_command("tele", PrivilegeLevel.ADMINISTRATOR) if (z in 0..4) { player.teleport(Position(x, y, z)) } - } \ No newline at end of file + }