blob: c39cee92e18f8990283a69ecad685be429e0718e (
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
46
47
48
49
50
51
52
53
54
55
|
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 KhsMapBlockHuntBlockAdd : Command {
override val label = "add"
override val usage = listOf("map", "block")
override val description = "Add a block to a block hunt map"
override fun execute(plugin: Khs, player: Player, args: List<String>) {
val (name, blockName) = args
runChecks(plugin, player) {
blockHuntSupported()
blockHuntEnabled(name)
gameNotInProgress()
lobbyEmpty()
}
val material = plugin.shim.parseMaterial(blockName)
if (material == null) {
player.message(plugin.locale.prefix.error + plugin.locale.blockHunt.block.unknown)
return
}
val map = plugin.maps.get(name) ?: return
if (map.config.blockHunt.blocks.contains(material)) {
player.message(
plugin.locale.prefix.error + plugin.locale.blockHunt.block.exists.with(material)
)
return
}
map.config.blockHunt.blocks += material
map.reloadConfig()
plugin.saveConfig()
player.message(
plugin.locale.prefix.default + plugin.locale.blockHunt.block.added.with(material)
)
}
override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> =
when (parameter) {
"map" ->
plugin.maps
.filter { it.value.config.blockHunt.enabled }
.map { it.key }
.filter { it.startsWith(typed) }
"block" -> plugin.shim.blocks.filter { it.startsWith(typed) }
else -> listOf()
}
}
|