Skip to content

Commit

Permalink
Improvelement: Cleanup /shcommand hover description (#1531)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
hannibal002 and hannibal002 authored Apr 25, 2024
1 parent 2c4ce94 commit 64c502e
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -544,6 +545,21 @@ object Commands {
ChatUtils.multiComponentMessage(components)
}

private fun MutableList<String>.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) {
Expand Down Expand Up @@ -588,7 +604,11 @@ object Commands {
name,
createCommand(function),
object : SimpleCommand.TabCompleteRunnable {
override fun tabComplete(sender: ICommandSender?, args: Array<String>?, pos: BlockPos?): List<String> {
override fun tabComplete(
sender: ICommandSender?,
args: Array<String>?,
pos: BlockPos?,
): List<String> {
return autoComplete(args ?: emptyArray())
}
}
Expand Down

0 comments on commit 64c502e

Please sign in to comment.