diff options
Diffstat (limited to 'core/src/command/map/set/Spawn.kt')
| -rw-r--r-- | core/src/command/map/set/Spawn.kt | 38 |
1 files changed, 38 insertions, 0 deletions
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() + } +} |