From b8b35e54f8ec6293ed7a24e421575c51727f6397 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Fri, 29 Nov 2024 00:18:42 +0100 Subject: [PATCH] Improvement + Fix: HelpCommand (#2993) --- .../skyhanni/config/commands/Commands.kt | 7 +----- .../skyhanni/features/commands/HelpCommand.kt | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 28cf47bbb643..cea7f1080408 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -18,7 +18,6 @@ import at.hannibal2.skyhanni.features.bingo.card.nextstephelper.BingoNextStepHel import at.hannibal2.skyhanni.features.chat.ColorFormattingHelper import at.hannibal2.skyhanni.features.chat.translation.Translator import at.hannibal2.skyhanni.features.combat.endernodetracker.EnderNodeTracker -import at.hannibal2.skyhanni.features.commands.HelpCommand import at.hannibal2.skyhanni.features.commands.PartyChatCommands import at.hannibal2.skyhanni.features.commands.PartyCommands import at.hannibal2.skyhanni.features.commands.WikiManager @@ -128,10 +127,6 @@ object Commands { description = "Opens the Farming Fortune Guide" callback { FFGuideGUI.onCommand() } } - event.register("shcommands") { - description = "Shows this list" - callback { HelpCommand.onCommand(it) } - } event.register("shdefaultoptions") { description = "Select default options" callback { DefaultConfigFeatures.onCommand(it) } @@ -163,7 +158,7 @@ object Commands { private fun usersNormal(event: CommandRegistrationEvent) { event.register("shcroptime") { description = - "Calculates with your current crop per second speed " + "how long you need to farm a crop to collect this amount of items" + "Calculates with your current crop per second speed how long you need to farm a crop to collect this amount of items" category = CommandCategory.USERS_ACTIVE callback { GardenCropTimeCommand.onCommand(it) } } 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 f544770985b3..514d0b5fd968 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/HelpCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/HelpCommand.kt @@ -1,13 +1,17 @@ package at.hannibal2.skyhanni.features.commands +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.config.commands.CommandBuilder +import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent import at.hannibal2.skyhanni.config.commands.Commands.commandList +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.StringUtils.splitLines import at.hannibal2.skyhanni.utils.chat.Text import at.hannibal2.skyhanni.utils.chat.Text.hover import at.hannibal2.skyhanni.utils.chat.Text.suggest import net.minecraft.util.IChatComponent +@SkyHanniModule object HelpCommand { private const val COMMANDS_PER_PAGE = 15 @@ -18,10 +22,12 @@ object HelpCommand { val color = category.color val description = command.description.splitLines(200).replace("§r", "§7") val categoryDescription = category.description.splitLines(200).replace("§r", "§7") + val aliases = command.aliases return Text.text("§7 - $color${command.name}") { this.hover = Text.multiline( "§e/${command.name}", + if (aliases.isNotEmpty()) "§7Aliases: ${aliases.joinToString(", ")}" else null, if (description.isNotEmpty()) description.prependIndent(" ") else null, "", "$color§l${category.categoryName}", @@ -33,7 +39,9 @@ object HelpCommand { private fun showPage(page: Int, search: String, commands: List) { val filtered = commands.filter { - it.name.contains(search, ignoreCase = true) || it.description.contains(search, ignoreCase = true) + it.name.contains(search, ignoreCase = true) || + it.aliases.any { alias -> alias.contains(search, ignoreCase = true) } || + it.description.contains(search, ignoreCase = true) } val title = if (search.isBlank()) "SkyHanni Commands" else "SkyHanni Commands Matching: \"$search\"" @@ -48,7 +56,7 @@ object HelpCommand { ) { createCommandEntry(it) } } - fun onCommand(args: Array) { + private fun onCommand(args: Array) { val page: Int val search: String if (args.firstOrNull() == "-p") { @@ -58,6 +66,15 @@ object HelpCommand { page = 1 search = args.joinToString(" ") } - showPage(page, search, commandList) + showPage(page, search, commandList.sortedWith(compareBy({ it.category.ordinal }, { it.name }))) + } + + @HandleEvent + fun onCommandRegistration(event: CommandRegistrationEvent) { + event.register("shcommands") { + description = "Shows this list" + aliases = listOf("shhelp", "shcommand", "shcmd", "shc") + callback { onCommand(it) } + } } }