summaryrefslogtreewikicommitdiff
path: root/core/src/command/map/blockhunt/Disguise.kt
blob: 8ee715a5a174bf8fccdb8cfb44b40b3818ee03cd (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
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 KhsMapBlockHuntDisguise : Command {
    override val label = "disguise"
    override val usage = listOf("block")
    override val description = "Disguise oneself as any block"

    override fun execute(plugin: Khs, player: Player, args: List<String>) {
        val (blockName) = args
        runChecks(plugin, player) { blockHuntSupported() }

        val material = plugin.shim.parseMaterial(blockName)
        if (material == null) {
            player.message(plugin.locale.prefix.error + plugin.locale.blockHunt.block.unknown)
            return
        }

        player.disguise(material)
    }

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