summaryrefslogtreewikicommitdiff
path: root/core/src/command/Send.kt
blob: bca4467ac429beaaec319f804450c07c92718f27 (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
package cat.freya.khs.command

import cat.freya.khs.Khs
import cat.freya.khs.command.util.Command
import cat.freya.khs.player.Player
import cat.freya.khs.runChecks

class KhsSend : Command {
    override val label = "send"
    override val usage = listOf("map")
    override val description = "Send the current lobby to another map"

    override fun execute(plugin: Khs, player: Player, args: List<String>) {
        val map = plugin.maps.get(args.first())

        runChecks(plugin, player) {
            gameNotInProgress()
            playerInGame()
            mapSetup(map)
        }

        plugin.game.setMap(map)
    }

    override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> =
        when (parameter) {
            "map" -> plugin.maps.keys.filter { it.startsWith(typed) }
            else -> listOf()
        }
}