Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement + Fix: HelpCommand #2993

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) }
}
}
}
Loading