aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-08-08 16:33:34 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-08-08 16:33:34 +0200
commit91f9f44815fbd902a8c134cffe3c902e1f122737 (patch)
tree7b628d153b879ca2c64f9b6f7b21c1b4f3f3dea2 /src/main/java/at/hannibal2
parent66e1d1ff31a32532a301eeefa0f592c0fb3ad703 (diff)
downloadskyhanni-91f9f44815fbd902a8c134cffe3c902e1f122737.tar.gz
skyhanni-91f9f44815fbd902a8c134cffe3c902e1f122737.tar.bz2
skyhanni-91f9f44815fbd902a8c134cffe3c902e1f122737.zip
fixed /shcommands error when no match
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/commands/HelpCommand.kt37
1 files changed, 21 insertions, 16 deletions
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.CommandInfo>
+ commands: List<Commands.CommandInfo>,
) {
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()) {