summaryrefslogtreewikicommitdiff
path: root/core/src/command/Top.kt
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2026-03-26 23:15:33 -0400
committerFreya Murphy <freya@freyacat.org>2026-03-27 23:09:23 -0400
commitf8322cd21cde68a72b05efbad3a05b8e67c0bdd0 (patch)
treed7e60bc8fedadc8fa7ae725571cad1f398eaf6dc /core/src/command/Top.kt
downloadkenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.gz
kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.bz2
kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.zip
initial
Diffstat (limited to 'core/src/command/Top.kt')
-rw-r--r--core/src/command/Top.kt49
1 files changed, 49 insertions, 0 deletions
diff --git a/core/src/command/Top.kt b/core/src/command/Top.kt
new file mode 100644
index 0000000..900f52f
--- /dev/null
+++ b/core/src/command/Top.kt
@@ -0,0 +1,49 @@
+package cat.freya.khs.command
+
+import cat.freya.khs.Khs
+import cat.freya.khs.command.util.Command
+import cat.freya.khs.player.Player
+
+class KhsTop : Command {
+ override val label = "top"
+ override val usage = listOf("*page")
+ override val description = "Shows the game leaderboard"
+
+ private fun getColor(index: UInt): Char {
+ return when (index) {
+ 0u -> 'e'
+ 1u -> '7'
+ 2u -> '6'
+ else -> 'f'
+ }
+ }
+
+ override fun execute(plugin: Khs, player: Player, args: List<String>) {
+ var page = args.firstOrNull()?.toUIntOrNull() ?: 0u
+ page = maxOf(page, 1u) - 1u
+
+ var pageSize = 5u
+ val entires = plugin.database?.getPlayers(page, pageSize)
+ if (entires == null || entires.isEmpty()) {
+ player.message(plugin.locale.prefix.default + plugin.locale.database.noInfo)
+ return
+ }
+
+ val message = buildString {
+ appendLine("&f------- &lLEADERBOARD &7(Page ${page + 1u}) &f-------")
+ for ((i, entry) in entires.withIndex()) {
+ val wins = entry.hiderWins + entry.seekerWins
+ val idx = (pageSize * page) + i.toUInt()
+ val color = getColor(idx)
+ val name = entry.name ?: continue
+ appendLine("&$color${idx + 1u}. &c$wins &f$name")
+ }
+ }
+
+ player.message(message)
+ }
+
+ override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> {
+ return listOf(parameter)
+ }
+}