summaryrefslogtreewikicommitdiff
path: root/core/src/command/map/blockhunt/Enabled.kt
blob: a2ccdb75673975a5853733a5e72b7873ae39b2f2 (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
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()
        }
}