From 64c502ef79a8fd309a1a4654285a77632e02068c Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:52:05 +0200 Subject: [PATCH] Improvelement: Cleanup /shcommand hover description (#1531) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../skyhanni/config/commands/Commands.kt | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 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 36494c359ee1..6212c35b0239 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -75,6 +75,7 @@ import at.hannibal2.skyhanni.utils.APIUtil import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.StringUtils.splitLines import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.repopatterns.RepoPatternGui import net.minecraft.command.ICommandSender @@ -528,11 +529,11 @@ object Commands { val hoverText = buildList { add("§e/$name") if (command.description.isNotEmpty()) { - add(" §7${command.description}") + addDescription(command.description) } add("") add("$color${category.categoryName}") - add(" §7${category.description}") + addDescription(category.description) } val commandInfo = ChatUtils.createHoverableChat("$color/$name", hoverText, "/$name", false) @@ -544,6 +545,21 @@ object Commands { ChatUtils.multiComponentMessage(components) } + private fun MutableList.addDescription(description: String) { + val lines = description.splitLines(200).removeSuffix("§r").replace("§r", "§7").addOptionalDot() + for (line in lines.split("\n")) { + add(" §7${line}") + } + } + + private fun String.addOptionalDot(): String { + if (endsWith(".")) return this + if (endsWith("?")) return this + if (endsWith("!")) return this + + return "$this." + } + @JvmStatic fun openFortuneGuide() { if (!LorenzUtils.inSkyBlock) { @@ -588,7 +604,11 @@ object Commands { name, createCommand(function), object : SimpleCommand.TabCompleteRunnable { - override fun tabComplete(sender: ICommandSender?, args: Array?, pos: BlockPos?): List { + override fun tabComplete( + sender: ICommandSender?, + args: Array?, + pos: BlockPos?, + ): List { return autoComplete(args ?: emptyArray()) } }