diff options
| author | Freya Murphy <freya@freyacat.org> | 2026-03-26 23:15:33 -0400 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2026-03-27 23:09:23 -0400 |
| commit | f8322cd21cde68a72b05efbad3a05b8e67c0bdd0 (patch) | |
| tree | d7e60bc8fedadc8fa7ae725571cad1f398eaf6dc /core/src/command/map | |
| download | kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.gz kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.bz2 kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.zip | |
initial
Diffstat (limited to 'core/src/command/map')
| -rw-r--r-- | core/src/command/map/Add.kt | 35 | ||||
| -rw-r--r-- | core/src/command/map/GoTo.kt | 40 | ||||
| -rw-r--r-- | core/src/command/map/List.kt | 32 | ||||
| -rw-r--r-- | core/src/command/map/Remove.kt | 32 | ||||
| -rw-r--r-- | core/src/command/map/Save.kt | 31 | ||||
| -rw-r--r-- | core/src/command/map/Status.kt | 45 | ||||
| -rw-r--r-- | core/src/command/map/blockhunt/Debug.kt | 35 | ||||
| -rw-r--r-- | core/src/command/map/blockhunt/Enabled.kt | 39 | ||||
| -rw-r--r-- | core/src/command/map/blockhunt/block/Add.kt | 55 | ||||
| -rw-r--r-- | core/src/command/map/blockhunt/block/List.kt | 46 | ||||
| -rw-r--r-- | core/src/command/map/blockhunt/block/Remove.kt | 56 | ||||
| -rw-r--r-- | core/src/command/map/set/Border.kt | 64 | ||||
| -rw-r--r-- | core/src/command/map/set/Bounds.kt | 57 | ||||
| -rw-r--r-- | core/src/command/map/set/Lobby.kt | 37 | ||||
| -rw-r--r-- | core/src/command/map/set/SeekerLobby.kt | 38 | ||||
| -rw-r--r-- | core/src/command/map/set/Spawn.kt | 38 | ||||
| -rw-r--r-- | core/src/command/map/unset/Border.kt | 39 |
17 files changed, 719 insertions, 0 deletions
diff --git a/core/src/command/map/Add.kt b/core/src/command/map/Add.kt new file mode 100644 index 0000000..8505849 --- /dev/null +++ b/core/src/command/map/Add.kt @@ -0,0 +1,35 @@ +package cat.freya.khs.command.map + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.config.MapConfig +import cat.freya.khs.game.KhsMap +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapAdd : Command { + override val label = "add" + override val usage = listOf("name", "world") + override val description = "Add a map to the plugin" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name, world) = args + runChecks(plugin, player) { + mapDoesNotExist(name) + mapNameValid(name) + worldValid(world) + } + + plugin.maps[name] = KhsMap(name, MapConfig(world), plugin) + plugin.saveConfig() + + player.message(plugin.locale.prefix.default + plugin.locale.map.created.with(name)) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "name" -> listOf("name") + "world" -> plugin.shim.worlds.filter { it.startsWith(typed) } + else -> listOf() + } +} diff --git a/core/src/command/map/GoTo.kt b/core/src/command/map/GoTo.kt new file mode 100644 index 0000000..20444cc --- /dev/null +++ b/core/src/command/map/GoTo.kt @@ -0,0 +1,40 @@ +package cat.freya.khs.command.map + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapGoTo : Command { + override val label = "goto" + override val usage = listOf("map", "spawn") + override val description = "Goes to a spawn location for a map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name, spawn) = args + runChecks(plugin, player) { mapExists(name) } + + var map = plugin.maps.get(name) ?: return + val loc = + when (spawn) { + "spawn" -> map.gameSpawn + "lobby" -> map.lobbySpawn + "seekerlobby" -> map.seekerLobbySpawn + else -> null + } + + if (loc == null) { + player.message(plugin.locale.prefix.error + plugin.locale.map.error.locationNotSet) + return + } + + loc.teleport(player) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> plugin.maps.keys.filter { it.startsWith(typed) } + "spawn" -> listOf("spawn", "lobby", "seekerlobby").filter { it.startsWith(typed) } + else -> listOf() + } +} diff --git a/core/src/command/map/List.kt b/core/src/command/map/List.kt new file mode 100644 index 0000000..8bc7a81 --- /dev/null +++ b/core/src/command/map/List.kt @@ -0,0 +1,32 @@ +package cat.freya.khs.command.map + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player + +class KhsMapList : Command { + override val label = "list" + override val usage = listOf<String>() + override val description = "List maps known to the plugin" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + if (plugin.maps.isEmpty()) { + player.message(plugin.locale.prefix.default + plugin.locale.map.none) + return + } + + player.message( + buildString { + appendLine(plugin.locale.prefix.default + plugin.locale.map.list) + for ((name, map) in plugin.maps) { + append("&e- &f$name: ") + appendLine(if (map.setup) "&aSETUP" else "&cNOT SETUP") + } + } + ) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> { + return listOf() + } +} diff --git a/core/src/command/map/Remove.kt b/core/src/command/map/Remove.kt new file mode 100644 index 0000000..f8aab4f --- /dev/null +++ b/core/src/command/map/Remove.kt @@ -0,0 +1,32 @@ +package cat.freya.khs.command.map + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapRemove : Command { + override val label = "remove" + override val usage = listOf("map") + override val description = "Remove a map from the plugin" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name) = args + runChecks(plugin, player) { + mapExists(name) + gameNotInProgress() + lobbyEmpty() + } + + plugin.maps.remove(name) + plugin.saveConfig() + + player.message(plugin.locale.prefix.default + plugin.locale.map.deleted.with(name)) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> plugin.maps.keys.filter { it.startsWith(typed) } + else -> listOf() + } +} diff --git a/core/src/command/map/Save.kt b/core/src/command/map/Save.kt new file mode 100644 index 0000000..a68b6cc --- /dev/null +++ b/core/src/command/map/Save.kt @@ -0,0 +1,31 @@ +package cat.freya.khs.command.map + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.game.mapSave +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapSave : Command { + override val label = "save" + override val usage = listOf("map") + override val description = "Save the map backup used for gameplay" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name) = args + runChecks(plugin, player) { + mapExists(name) + gameNotInProgress() + lobbyEmpty() + } + + var map = plugin.maps.get(name) ?: return + mapSave(plugin, map) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> plugin.maps.keys.filter { it.startsWith(typed) } + else -> listOf() + } +} diff --git a/core/src/command/map/Status.kt b/core/src/command/map/Status.kt new file mode 100644 index 0000000..596f306 --- /dev/null +++ b/core/src/command/map/Status.kt @@ -0,0 +1,45 @@ +package cat.freya.khs.command.map + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapStatus : Command { + override val label = "status" + override val usage = listOf("map") + override val description = "Says what is needed to fully setup the map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name) = args + runChecks(plugin, player) { mapExists(name) } + + val map = plugin.maps.get(name) ?: return + + if (map.setup) { + player.message(plugin.locale.prefix.default + plugin.locale.map.setup.complete) + return + } + + player.message( + buildString { + appendLine(plugin.locale.map.setup.header) + if (map.gameSpawn == null) appendLine(plugin.locale.map.setup.game) + if (map.lobbySpawn == null) appendLine(plugin.locale.map.setup.lobby) + if (map.seekerLobbySpawn == null) appendLine(plugin.locale.map.setup.seekerLobby) + if (plugin.config.exit == null) appendLine(plugin.locale.map.setup.exit) + if (map.bounds() == null) appendLine(plugin.locale.map.setup.bounds) + if (plugin.config.mapSaveEnabled && !map.hasMapSave()) + appendLine(plugin.locale.map.setup.saveMap) + if (map.config.blockHunt.enabled && map.config.blockHunt.blocks.isEmpty()) + appendLine(plugin.locale.map.setup.blockHunt) + } + ) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> plugin.maps.keys.filter { it.startsWith(typed) } + else -> listOf() + } +} diff --git a/core/src/command/map/blockhunt/Debug.kt b/core/src/command/map/blockhunt/Debug.kt new file mode 100644 index 0000000..0620e3d --- /dev/null +++ b/core/src/command/map/blockhunt/Debug.kt @@ -0,0 +1,35 @@ +package cat.freya.khs.command.map.blockhunt + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.inv.createBlockHuntPicker +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapBlockHuntDebug : Command { + override val label = "debug" + override val usage = listOf("map") + override val description = "Manually open the blockhunt picker for a map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name) = args + runChecks(plugin, player) { + blockHuntSupported() + blockHuntEnabled(name) + } + + val map = plugin.maps.get(name) ?: return + val inv = createBlockHuntPicker(plugin, map) ?: return + player.showInventory(inv) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> + plugin.maps + .filter { it.value.config.blockHunt.enabled } + .map { it.key } + .filter { it.startsWith(typed) } + else -> listOf() + } +} diff --git a/core/src/command/map/blockhunt/Enabled.kt b/core/src/command/map/blockhunt/Enabled.kt new file mode 100644 index 0000000..a2ccdb7 --- /dev/null +++ b/core/src/command/map/blockhunt/Enabled.kt @@ -0,0 +1,39 @@ +package cat.freya.khs.command.map.blockhunt + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapBlockHuntEnabled : Command { + override val label = "enabled" + override val usage = listOf("map", "bool") + override val description = "Enable/disable blockhunt on a map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name, enabled) = args + runChecks(plugin, player) { + blockHuntSupported() + mapExists(name) + gameNotInProgress() + } + + val map = plugin.maps.get(name) ?: return + map.config.blockHunt.enabled = (enabled.lowercase() == "true") + map.reloadConfig() + + val msg = + if (map.config.blockHunt.enabled) plugin.locale.blockHunt.enabled + else plugin.locale.blockHunt.disabled + + plugin.saveConfig() + player.message(plugin.locale.prefix.default + msg) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> plugin.maps.keys.filter { it.startsWith(typed) } + "bool" -> listOf("true", "false").filter { it.startsWith(typed) } + else -> listOf() + } +} diff --git a/core/src/command/map/blockhunt/block/Add.kt b/core/src/command/map/blockhunt/block/Add.kt new file mode 100644 index 0000000..6ed17be --- /dev/null +++ b/core/src/command/map/blockhunt/block/Add.kt @@ -0,0 +1,55 @@ +package cat.freya.khs.command.map.blockhunt.block + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapBlockHuntBlockAdd : Command { + override val label = "add" + override val usage = listOf("map", "block") + override val description = "Add a block to a block hunt map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name, blockName) = args + runChecks(plugin, player) { + blockHuntSupported() + blockHuntEnabled(name) + gameNotInProgress() + lobbyEmpty() + } + + val material = plugin.shim.parseMaterial(blockName) + if (material == null) { + player.message(plugin.locale.prefix.error + plugin.locale.blockHunt.block.unknown) + return + } + + val map = plugin.maps.get(name) ?: return + if (map.config.blockHunt.blocks.contains(material)) { + player.message( + plugin.locale.prefix.error + plugin.locale.blockHunt.block.exists.with(material) + ) + return + } + + map.config.blockHunt.blocks += material + map.reloadConfig() + + plugin.saveConfig() + player.message( + plugin.locale.prefix.default + plugin.locale.blockHunt.block.added.with(material) + ) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> + plugin.maps + .filter { it.value.config.blockHunt.enabled } + .map { it.key } + .filter { it.startsWith(typed) } + "block" -> listOf(parameter) + else -> listOf() + } +} diff --git a/core/src/command/map/blockhunt/block/List.kt b/core/src/command/map/blockhunt/block/List.kt new file mode 100644 index 0000000..b7df70d --- /dev/null +++ b/core/src/command/map/blockhunt/block/List.kt @@ -0,0 +1,46 @@ +package cat.freya.khs.command.map.blockhunt.block + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapBlockHuntBlockList : Command { + override val label = "list" + override val usage = listOf("map") + override val description = "List blocks in use on a block hunt map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name) = args + runChecks(plugin, player) { + blockHuntSupported() + blockHuntEnabled(name) + } + + val map = plugin.maps.get(name) ?: return + val blocks = map.config.blockHunt.blocks + if (blocks.isEmpty()) { + player.message(plugin.locale.prefix.default + plugin.locale.blockHunt.block.none) + return + } + + val message = buildString { + appendLine(plugin.locale.blockHunt.block.list) + for (block in blocks) { + appendLine("&e- &f$block") + } + } + + player.message(message) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> + plugin.maps + .filter { it.value.config.blockHunt.enabled } + .map { it.key } + .filter { it.startsWith(typed) } + else -> listOf() + } +} diff --git a/core/src/command/map/blockhunt/block/Remove.kt b/core/src/command/map/blockhunt/block/Remove.kt new file mode 100644 index 0000000..3e81371 --- /dev/null +++ b/core/src/command/map/blockhunt/block/Remove.kt @@ -0,0 +1,56 @@ +package cat.freya.khs.command.map.blockhunt.block + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapBlockHuntBlockRemove : Command { + override val label = "remove" + override val usage = listOf("map", "block") + override val description = "Remove a block from a block hunt map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name, blockName) = args + runChecks(plugin, player) { + blockHuntSupported() + blockHuntEnabled(name) + gameNotInProgress() + lobbyEmpty() + } + + val material = plugin.shim.parseMaterial(blockName) + if (material == null) { + player.message(plugin.locale.prefix.error + plugin.locale.blockHunt.block.unknown) + return + } + + val map = plugin.maps.get(name) ?: return + if (!map.config.blockHunt.blocks.contains(material)) { + player.message( + plugin.locale.prefix.error + + plugin.locale.blockHunt.block.doesntExist.with(material) + ) + return + } + + map.config.blockHunt.blocks -= material + map.reloadConfig() + + plugin.saveConfig() + player.message( + plugin.locale.prefix.default + plugin.locale.blockHunt.block.removed.with(material) + ) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> + plugin.maps + .filter { it.value.config.blockHunt.enabled } + .map { it.key } + .filter { it.startsWith(typed) } + "block" -> listOf(parameter) + else -> listOf() + } +} diff --git a/core/src/command/map/set/Border.kt b/core/src/command/map/set/Border.kt new file mode 100644 index 0000000..75a3f27 --- /dev/null +++ b/core/src/command/map/set/Border.kt @@ -0,0 +1,64 @@ +package cat.freya.khs.command.map.set + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapSetBorder : Command { + override val label = "border" + override val usage = listOf("map", "size", "delay", "move") + override val description = "Enable the world border for a map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name, sizeS, delayS, moveS) = args + runChecks(plugin, player) { + mapExists(name) + inMapWorld(name) + gameNotInProgress() + } + + val size = sizeS.toULong() + val delay = delayS.toULong() + val move = moveS.toULong() + + if (size < 100u) { + player.message(plugin.locale.prefix.error + plugin.locale.worldBorder.minSize) + return + } + + if (move < 1u) { + player.message(plugin.locale.prefix.error + plugin.locale.worldBorder.minChange) + return + } + + var map = plugin.maps.get(name) ?: return + val config = map.config.worldBorder + config.enabled = true + config.pos = player.location.position + config.size = size + config.delay = delay + config.move = move + + runChecks(plugin, player) { + // note this is not error, only warn + spawnsInRange(map) + } + + map.reloadConfig() + + plugin.saveConfig() + player.message( + plugin.locale.prefix.default + plugin.locale.worldBorder.enable.with(size, delay, move) + ) + + val loc = player.location.position + map.world?.border?.move(loc.x, loc.z, size, 0UL) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> plugin.maps.keys.filter { it.startsWith(typed) } + else -> listOf(parameter) + } +} diff --git a/core/src/command/map/set/Bounds.kt b/core/src/command/map/set/Bounds.kt new file mode 100644 index 0000000..7c13802 --- /dev/null +++ b/core/src/command/map/set/Bounds.kt @@ -0,0 +1,57 @@ +package cat.freya.khs.command.map.set + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.config.BoundConfig +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapSetBounds : Command { + override val label = "bounds" + override val usage = listOf("map") + override val description = "Sets the map bounds for a map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name) = args + runChecks(plugin, player) { + mapExists(name) + inMapWorld(name) + gameNotInProgress() + } + + var map = plugin.maps.get(name) ?: return + val config = map.config.bounds + + val pos = player.location.position + val num: Int + + if (config.min == null || config.max != null) { + config.min = BoundConfig(pos.x, pos.z) + config.max == null + num = 1 + } else { + val minX = minOf(config.min?.x ?: 0.0, pos.x) + val minZ = minOf(config.min?.z ?: 0.0, pos.z) + val maxX = maxOf(config.min?.x ?: 0.0, pos.x) + val maxZ = maxOf(config.min?.z ?: 0.0, pos.z) + config.min = BoundConfig(minX, minZ) + config.max = BoundConfig(maxX, maxZ) + num = 2 + } + + runChecks(plugin, player) { + // note this is not error, only warn + spawnsInRange(map) + } + + map.reloadConfig() + plugin.saveConfig() + player.message(plugin.locale.prefix.default + plugin.locale.map.set.bounds.with(num)) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> plugin.maps.keys.filter { it.startsWith(typed) } + else -> listOf() + } +} diff --git a/core/src/command/map/set/Lobby.kt b/core/src/command/map/set/Lobby.kt new file mode 100644 index 0000000..a90259a --- /dev/null +++ b/core/src/command/map/set/Lobby.kt @@ -0,0 +1,37 @@ +package cat.freya.khs.command.map.set + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapSetLobby : Command { + override val label = "lobby" + override val usage = listOf("map") + override val description = "Sets the lobby spawn location for a map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name) = args + runChecks(plugin, player) { + mapExists(name) + inMapWorld(name) + gameNotInProgress() + } + + var map = plugin.maps.get(name) ?: return + val pos = player.location.position + + runChecks(plugin, player) { spawnInRange(map, pos) } + + map.config.spawns.lobby = pos + map.reloadConfig() + plugin.saveConfig() + player.message(plugin.locale.prefix.default + plugin.locale.map.set.lobby) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> plugin.maps.keys.filter { it.startsWith(typed) } + else -> listOf() + } +} diff --git a/core/src/command/map/set/SeekerLobby.kt b/core/src/command/map/set/SeekerLobby.kt new file mode 100644 index 0000000..71122cb --- /dev/null +++ b/core/src/command/map/set/SeekerLobby.kt @@ -0,0 +1,38 @@ +package cat.freya.khs.command.map.set + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapSetSeekerLobby : Command { + override val label = "seekerlobby" + override val usage = listOf("map") + override val description = "Sets the seeker lobby spawn location for a map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name) = args + runChecks(plugin, player) { + mapExists(name) + inMapWorld(name) + gameNotInProgress() + } + + var map = plugin.maps.get(name) ?: return + val pos = player.location.position + + runChecks(plugin, player) { spawnInRange(map, pos) } + + map.config.spawns.seeker = pos + map.reloadConfig() + + plugin.saveConfig() + player.message(plugin.locale.prefix.default + plugin.locale.map.set.seekerSpawn) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> plugin.maps.keys.filter { it.startsWith(typed) } + else -> listOf() + } +} diff --git a/core/src/command/map/set/Spawn.kt b/core/src/command/map/set/Spawn.kt new file mode 100644 index 0000000..4eff730 --- /dev/null +++ b/core/src/command/map/set/Spawn.kt @@ -0,0 +1,38 @@ +package cat.freya.khs.command.map.set + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapSetSpawn : Command { + override val label = "spawn" + override val usage = listOf("map") + override val description = "Sets the game spawn location for a map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name) = args + runChecks(plugin, player) { + mapExists(name) + inMapWorld(name) + gameNotInProgress() + } + + var map = plugin.maps.get(name) ?: return + val pos = player.location.position + + runChecks(plugin, player) { spawnInRange(map, pos) } + + map.config.spawns.game = pos.toLegacy() + map.reloadConfig() + + plugin.saveConfig() + player.message(plugin.locale.prefix.default + plugin.locale.map.set.gameSpawn) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> plugin.maps.keys.filter { it.startsWith(typed) } + else -> listOf() + } +} diff --git a/core/src/command/map/unset/Border.kt b/core/src/command/map/unset/Border.kt new file mode 100644 index 0000000..87e7b85 --- /dev/null +++ b/core/src/command/map/unset/Border.kt @@ -0,0 +1,39 @@ +package cat.freya.khs.command.map.unset + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import cat.freya.khs.runChecks + +class KhsMapUnsetBorder : Command { + override val label = "border" + override val usage = listOf("map") + override val description = "Disable the world border for a map" + + override fun execute(plugin: Khs, player: Player, args: List<String>) { + val (name) = args + runChecks(plugin, player) { + mapExists(name) + gameNotInProgress() + } + + var map = plugin.maps.get(name) ?: return + val config = map.config.worldBorder + config.enabled = false + config.pos = null + config.size = null + config.delay = null + config.move = null + + plugin.saveConfig() + player.message(plugin.locale.prefix.default + plugin.locale.worldBorder.disable) + + map.world?.border?.move(0.0, 0.0, 30_000_000UL, 0UL) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> = + when (parameter) { + "map" -> plugin.maps.keys.filter { it.startsWith(typed) } + else -> listOf() + } +} |