From f8322cd21cde68a72b05efbad3a05b8e67c0bdd0 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 26 Mar 2026 23:15:33 -0400 Subject: initial --- core/src/command/Help.kt | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 core/src/command/Help.kt (limited to 'core/src/command/Help.kt') diff --git a/core/src/command/Help.kt b/core/src/command/Help.kt new file mode 100644 index 0000000..168b69c --- /dev/null +++ b/core/src/command/Help.kt @@ -0,0 +1,39 @@ +package cat.freya.khs.command + +import cat.freya.khs.Khs +import cat.freya.khs.command.util.Command +import cat.freya.khs.player.Player +import kotlin.text.toUInt + +class KhsHelp : Command { + override val label = "help" + override val usage = listOf("*page") + override val description = "Lists the commands you can use" + + override fun execute(plugin: Khs, player: Player, args: List) { + val commands = plugin.commandGroup.commandsFor(player) + val pageSize = 4u + val pages = (commands.size.toUInt() + pageSize - 1u) / pageSize + val page = maxOf(minOf(args.firstOrNull().let { it?.toUIntOrNull() } ?: 0u, pages), 1u) + + player.message( + buildString { + appendLine( + "&b=================== &fHelp: Page ($page/$pages) &b===================" + ) + for ((label, command) in commands.chunked(pageSize.toInt()).get(page.toInt() - 1)) { + val cmd = label.substring(3) + val usage = command.usage.joinToString(" ") + val description = command.description + appendLine("&7?&f &b/hs &f$cmd &9$usage") + appendLine("&7?&f &7&o$description") + } + appendLine("&b=====================================================") + } + ) + } + + override fun autoComplete(plugin: Khs, parameter: String, typed: String): List { + return listOf(parameter) + } +} -- cgit v1.2.3-freya