diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-05-08 21:12:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-08 21:12:01 +0200 |
commit | f3bad6b63b3c4efbf3088d58b9f83944949ba367 (patch) | |
tree | 0e3b614dcf4afd587b908464d9e219936c63d24d /src | |
parent | c2fc248d9866a5601ee10057467669b22f16f79b (diff) | |
download | skyhanni-f3bad6b63b3c4efbf3088d58b9f83944949ba367.tar.gz skyhanni-f3bad6b63b3c4efbf3088d58b9f83944949ba367.tar.bz2 skyhanni-f3bad6b63b3c4efbf3088d58b9f83944949ba367.zip |
Fix: Spaces in chat formatting (#1704)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 54 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt | 6 |
2 files changed, 22 insertions, 38 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 4190b2e9d..961c17297 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -50,8 +50,6 @@ class PlayerNameFormatter { "(?<emblem>(?:§.){0,2}.) (?<author>.*)" ) - private val empty: IChatComponent = ChatComponentText("") - @SubscribeEvent fun onPlayerAllChat(event: PlayerAllChatEvent) { if (!isEnabled()) return @@ -131,7 +129,6 @@ class PlayerNameFormatter { }) ?: return } - @SubscribeEvent fun onPlayerShowItemChat(event: PlayerShowItemChatEvent) { if (!isEnabled()) return @@ -159,7 +156,7 @@ class PlayerNameFormatter { ): ChatComponentText { var cleanAuthor = cleanAuthor(author) - var emblemFormat = empty + var emblemFormat: IChatComponent? = null emblemPattern.matchStyledMatcher(author) { emblemFormat = componentOrThrow("emblem") cleanAuthor = groupOrThrow("author").stripHypixelMessage() @@ -167,19 +164,19 @@ class PlayerNameFormatter { val name = formatAuthor(cleanAuthor.getText(), levelColor).applyFormattingFrom(cleanAuthor) val levelFormat = formatLevel(levelColor, level) - val guildRankFormat = guildRank?.intoComponent() ?: empty - val privateIslandRankFormat = privateIslandRank?.intoComponent() ?: empty - val privateIslandGuestFormat = privateIslandGuest?.intoComponent() ?: empty + val guildRankFormat = guildRank?.intoComponent() + val privateIslandRankFormat = privateIslandRank?.intoComponent() + val privateIslandGuestFormat = privateIslandGuest?.intoComponent() val cleanName = cleanAuthor.getText().cleanPlayerName() val (faction, ironman, bingo) = AdvancedPlayerList.tabPlayerData[cleanName]?.let { - val faction = it.faction.icon.toCleanChatComponent() - val ironman = if (it.ironman) "§7♲".toCleanChatComponent() else empty - val bingo = it.bingoLevel?.let { level -> BingoAPI.getBingoIcon(level).toCleanChatComponent() } ?: empty + val faction = it.faction.icon?.toCleanChatComponent() + val ironman = if (it.ironman) "§7♲".toCleanChatComponent() else null + val bingo = it.bingoLevel?.let { level -> BingoAPI.getBingoIcon(level).toCleanChatComponent() } listOf(faction, ironman, bingo) - } ?: listOf(empty, empty, empty) + } ?: listOf(null, null, null) - val map = mutableMapOf<PlayerMessagesConfig.MessagePart, IChatComponent>() + val map = mutableMapOf<PlayerMessagesConfig.MessagePart, IChatComponent?>() map[PlayerMessagesConfig.MessagePart.SKYBLOCK_LEVEL] = levelFormat map[PlayerMessagesConfig.MessagePart.EMBLEM] = emblemFormat map[PlayerMessagesConfig.MessagePart.PLAYER_NAME] = name @@ -191,36 +188,23 @@ class PlayerNameFormatter { map[PlayerMessagesConfig.MessagePart.PRIVATE_ISLAND_GUEST] = privateIslandGuestFormat val all = ChatComponentText("") + var first = true for (text in config.partsOrder.mapNotNull { map[it] }) { - all.appendSibling(text) - if (!all.unformattedText.endsWith(" ")) { - all.appendText(" ") + if (first) { + first = false + } else { + if (!all.unformattedText.endsWith(" ")) { + all.appendText(" ") + } } + all.appendSibling(text) } return all -// return config.partsOrder.map { map[it] }.joinToString(" ").replaceAll(" ", " ").trim() } -// private fun String.add(iChatComponent: IChatComponent): ChatComponentText { -// val style = findStyle(iChatComponent) -// val text = ChatComponentText(this.trim()) -// text.chatStyle = style -// -// return text -// } -// -// private fun String.findStyle(iChatComponent: IChatComponent): ChatStyle? { -// for (sibling in iChatComponent.siblings) { -// if (sibling.unformattedText.contains(this)) { -// return sibling.chatStyle -// } -// } -// return null -// } - - private fun formatLevel(rawColor: String?, rawLevel: ComponentSpan?): IChatComponent { - val color = rawColor ?: return empty + private fun formatLevel(rawColor: String?, rawLevel: ComponentSpan?): IChatComponent? { + val color = rawColor ?: return null val level = rawLevel?.getText() ?: error("level is null, color is not null") val levelData = "$color$level" val result = if (config.hideLevelBrackets) levelData else "§8[${levelData}§8]" diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt index 76a5decd8..70571b5cc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt @@ -202,7 +202,7 @@ object AdvancedPlayerList { } if (IslandType.CRIMSON_ISLE.isInIsland() && !config.hideFactions) { - suffix += data.faction.icon + suffix += data.faction.icon ?: "" } return "$level $playerName ${suffix.trim()}" @@ -240,10 +240,10 @@ object AdvancedPlayerList { var faction: CrimsonIsleFaction = CrimsonIsleFaction.NONE } - enum class CrimsonIsleFaction(val icon: String) { + enum class CrimsonIsleFaction(val icon: String?) { BARBARIAN(" §c⚒"), MAGE(" §5ቾ"), - NONE("") + NONE(null) } enum class SocialIcon(val icon: () -> String, val score: Int) { |