diff options
| author | Freya Murphy <freya@freyacat.org> | 2026-03-26 23:15:33 -0400 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2026-03-27 23:09:23 -0400 |
| commit | f8322cd21cde68a72b05efbad3a05b8e67c0bdd0 (patch) | |
| tree | d7e60bc8fedadc8fa7ae725571cad1f398eaf6dc /core/src/command/map/blockhunt/block/Add.kt | |
| download | kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.gz kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.bz2 kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.zip | |
initial
Diffstat (limited to 'core/src/command/map/blockhunt/block/Add.kt')
| -rw-r--r-- | core/src/command/map/blockhunt/block/Add.kt | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/core/src/command/map/blockhunt/block/Add.kt b/core/src/command/map/blockhunt/block/Add.kt new file mode 100644 index 0000000..6ed17be --- /dev/null +++ b/core/src/command/map/blockhunt/block/Add.kt @@ -0,0 +1,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" -> listOf(parameter) + else -> listOf() + } +} |