summaryrefslogtreewikicommitdiff
path: root/core/src/command/map/Status.kt
blob: 596f3065da00fd5a7d4771c8089ea5ab8b8cb5cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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()
        }
}