Skip to content

Commit

Permalink
Improvement + Fix: HelpCommand (#2993)
Browse files Browse the repository at this point in the history
  • Loading branch information
j10a1n15 authored Nov 28, 2024
1 parent 755f7f5 commit b8b35e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -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) }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}",
Expand All @@ -33,7 +39,9 @@ object HelpCommand {

private fun showPage(page: Int, search: String, commands: List<CommandBuilder>) {
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\""
Expand All @@ -48,7 +56,7 @@ object HelpCommand {
) { createCommandEntry(it) }
}

fun onCommand(args: Array<String>) {
private fun onCommand(args: Array<String>) {
val page: Int
val search: String
if (args.firstOrNull() == "-p") {
Expand All @@ -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) }
}
}
}

0 comments on commit b8b35e5

Please sign in to comment.