From 91f9f44815fbd902a8c134cffe3c902e1f122737 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 8 Aug 2024 16:33:34 +0200 Subject: fixed /shcommands error when no match --- .../skyhanni/features/commands/HelpCommand.kt | 37 ++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/HelpCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/HelpCommand.kt index 4d4c5d341..1890c6293 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/HelpCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/HelpCommand.kt @@ -37,7 +37,7 @@ object HelpCommand { if (description.isNotEmpty()) description.prependIndent(" ") else null, "", "$color§l${category.categoryName}", - categoryDescription.prependIndent(" ") + categoryDescription.prependIndent(" "), ) this.suggest = "/${command.name}" } @@ -46,12 +46,15 @@ object HelpCommand { private fun showPage( page: Int, search: String, - commands: List + commands: List, ) { val filtered = commands.filter { it.name.contains(search, ignoreCase = true) || it.description.contains(search, ignoreCase = true) } - val maxPage = ceil(filtered.size.toDouble() / COMMANDS_PER_PAGE).toInt() + + val maxPage = if (filtered.isNotEmpty()) { + ceil(filtered.size.toDouble() / COMMANDS_PER_PAGE).toInt() + } else 1 val page = page.coerceIn(1, maxPage) val title = if (search.isEmpty()) "§6SkyHanni Commands" else "§6SkyHanni Commands matching '$search'" @@ -59,19 +62,21 @@ object HelpCommand { text.add(createDivider()) text.add(title.asComponent().center()) - text.add(Text.join( - if (page > 1) "§6§l<<".asComponent { - this.hover = "§eClick to view page ${page - 1}".asComponent() - this.onClick { showPage(page - 1, search, commands) } - } else null, - " ", - "§6(Page $page of $maxPage)", - " ", - if (page < maxPage) "§6§l>>".asComponent { - this.hover = "§eClick to view page ${page + 1}".asComponent() - this.onClick { showPage(page + 1, search, commands) } - } else null - ).center()) + text.add( + Text.join( + if (page > 1) "§6§l<<".asComponent { + this.hover = "§eClick to view page ${page - 1}".asComponent() + this.onClick { showPage(page - 1, search, commands) } + } else null, + " ", + "§6(Page $page of $maxPage)", + " ", + if (page < maxPage) "§6§l>>".asComponent { + this.hover = "§eClick to view page ${page + 1}".asComponent() + this.onClick { showPage(page + 1, search, commands) } + } else null, + ).center(), + ) text.add(createDivider()) if (filtered.isEmpty()) { -- cgit