diff options
| author | Linnea Gräf <nea@nea.moe> | 2024-10-31 21:57:08 +0100 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2024-10-31 22:12:29 +0100 |
| commit | 52b1664281e2d9a5614f233a826317fbf37c9321 (patch) | |
| tree | fd4466fcd830dd739eca72ccc2f31dcf06d9596e /src/main/java/at/hannibal2/skyhanni | |
| parent | 1aca377197b41e0fb0b6469b8251265a76072dd8 (diff) | |
| download | SkyHanni-fix/chatformattingissueswhite.tar.gz SkyHanni-fix/chatformattingissueswhite.tar.bz2 SkyHanni-fix/chatformattingissueswhite.zip | |
Fix white and too liberal (woke) player chat name replacementfix/chatformattingissueswhite
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt | 11 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 14 |
2 files changed, 20 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index eb48bb4e9..01ec9d563 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -16,7 +16,9 @@ import at.hannibal2.skyhanni.utils.ComponentMatcher import at.hannibal2.skyhanni.utils.ComponentMatcherUtils.intoSpan import at.hannibal2.skyhanni.utils.ComponentMatcherUtils.matchStyledMatcher import at.hannibal2.skyhanni.utils.ComponentSpan +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -36,7 +38,7 @@ object PlayerChatManager { */ private val globalPattern by patternGroup.pattern( "global", - "(?:\\[(?<level>\\d+)] )?(?<author>.+?)(?<chatColor>§f|§7|): (?<message>.*)" + "^(?:\\[(?<level>\\d+)] )?(?<author>(?:[^ ] )?(?:(?:§.)?\\[[^\\]]+\\] )?[^ ]+?)(?<chatColor>§f|§7|): (?<message>.*)\$", ) /** @@ -169,6 +171,11 @@ object PlayerChatManager { private fun ComponentMatcher.isGlobalChat(event: LorenzChatEvent): Boolean { var author = groupOrThrow("author") + val chatColor = groupOrThrow("chatColor") + if (chatColor.length == 0 && !author.getText().removeColor().endsWith(LorenzUtils.getPlayerName())) { + // The last format string is always present, unless this is the players own message + return false + } val message = groupOrThrow("message").removePrefix("§f") if (author.getText().contains("[NPC]")) { NpcChatEvent(author, message, event.chatComponent).postChat(event) @@ -196,7 +203,7 @@ object PlayerChatManager { levelComponent = group("level"), privateIslandRank = privateIslandRank, privateIslandGuest = privateIslandGuest, - chatColor = groupOrThrow("chatColor").getText(), + chatColor = chatColor.getText(), authorComponent = author, messageComponent = message, chatComponent = event.chatComponent, 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 bd7a407df..b2a09fa90 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 @@ -30,6 +30,7 @@ import at.hannibal2.skyhanni.utils.chat.Text.style import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import com.google.gson.JsonArray import com.google.gson.JsonNull +import net.minecraft.client.gui.FontRenderer import net.minecraft.util.ChatComponentText import net.minecraft.util.EnumChatFormatting import net.minecraft.util.IChatComponent @@ -242,7 +243,9 @@ object PlayerNameFormatter { if (author.getText().contains("ADMIN")) return author if (config.ignoreYouTube && author.getText().contains("YOUTUBE")) return author val (rank, name) = author.splitPlayerNameAndExtras() - val coloredName = createColoredName(name, levelColor, name.getText().removeColor()) + val rankColor = + if (rank != null && rank.sampleAtStart() === name.sampleAtStart()) FontRenderer.getFormatFromString(rank.getText()) else "" + val coloredName = createColoredName(name, levelColor, name.getText().removeColor(), rankColor) return if (config.playerRankHider || rank == null) coloredName else rank + coloredName } @@ -250,9 +253,10 @@ object PlayerNameFormatter { name: ComponentSpan, levelColor: String?, removeColor: String, + rankColor: String, ): ComponentSpan = when { MarkedPlayerManager.isMarkedPlayer(removeColor) && MarkedPlayerManager.config.highlightInChat -> - ChatComponentText(MarkedPlayerManager.replaceInChat(removeColor)) + ChatComponentText(MarkedPlayerManager.replaceInChat(rankColor + removeColor)) .setChatStyle(name.sampleStyleAtStart()).intoSpan() levelColor != null && config.useLevelColorForName -> @@ -266,7 +270,11 @@ object PlayerNameFormatter { .style { color = EnumChatFormatting.AQUA } .intoSpan() - else -> name + else -> + if (rankColor.isEmpty()) name + else ChatComponentText(rankColor + removeColor) + .setChatStyle(name.sampleStyleAtStart()) + .intoSpan() } fun isEnabled() = LorenzUtils.inSkyBlock && config.enable |
