diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/Chat.java | 6 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt | 38 |
3 files changed, 34 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 90c4416b0..d28c99f87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Added highlight Thunder Sparks after killing a Thunder - Added Thunder to damage indicator - Added support for links in player chat +- Option to enable that clicking on a player name in chat opens the profile viewer of NotEnoughUpdates (to fix SkyHanni breaking the default NEU feature). ## Version 0.8 diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java b/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java index 26e409c00..e8e424b0d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java @@ -108,6 +108,12 @@ public class Chat { public int channelDesign = 0; @Expose + @ConfigOption(name = "NEU Profile Viewer", desc = "Click on a player name to open the Profile Viewer from NotEnoughUpdates") + @ConfigEditorBoolean + @ConfigAccordionId(id = 1) + public boolean neuProfileViewer = false; + + @Expose @ConfigOption(name = "Test All Chat", desc = "Test the All Chat message format locally (no message gets sent to hypixel)") @ConfigEditorButton(runnableId = "testAllChat") @ConfigAccordionId(id = 1) diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt index 72ee33195..0317f9338 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.client.Minecraft import net.minecraft.event.ClickEvent +import net.minecraft.event.HoverEvent import net.minecraft.util.ChatComponentText import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Pattern @@ -109,7 +110,7 @@ class PlayerChatFormatter { ?: PlayerMessageChannel.ALL } - private fun grabName(rawName: String): String? { + private fun grabName(rawName: String, nameOnly: Boolean = false): String? { val nameSplit = rawName.removeColor().split(" ") val last = nameSplit.last() val cleanName = if (last.endsWith("]")) { @@ -125,6 +126,11 @@ class PlayerChatFormatter { return null } } + + if (nameOnly) { + return cleanName + } + return if (SkyHanniMod.feature.chat.playerRankHider) { "§b$cleanName" } else { @@ -140,7 +146,8 @@ class PlayerChatFormatter { levelColor: String, elitePrefix: String, ) { - loggerPlayerChat.log("[$channel] ${name.removeColor()}: $message") + val cleanName = grabName(name, true) + loggerPlayerChat.log("[$channel] $cleanName: $message") val event = PlayerSendChatEvent(channel, name, message) event.postAndCatch() @@ -153,20 +160,29 @@ class PlayerChatFormatter { val colon = if (SkyHanniMod.feature.chat.playerColonHider) "" else ":" val levelFormat = getLevelFormat(name, level, levelColor) - sendWithLink("$channelPrefix$elitePrefix$levelFormat§f$colon", event.message) - } + val nameText = ChatComponentText("$channelPrefix$elitePrefix$levelFormat§f$colon") + if (SkyHanniMod.feature.chat.neuProfileViewer) { + nameText.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/pv $cleanName") + nameText.chatStyle.chatHoverEvent = HoverEvent( + HoverEvent.Action.SHOW_TEXT, + ChatComponentText("§7Click to open the §cNEU Profile Viewer §7for $name") + ) + } - private fun sendWithLink(prefix: String, message: String) { - val fullText = ChatComponentText(prefix) + addChat(nameText, event.message) + } - for (lines in message.split(" ")) { + private fun addChat(text: ChatComponentText, message: String) { + val fullText = ChatComponentText("") + fullText.appendSibling(text) + for (word in message.split(" ")) { fullText.appendSibling(ChatComponentText(" ")) - if (patternUrl.matcher(lines).matches()) { - val oneWord = ChatComponentText(lines) - oneWord.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.OPEN_URL, lines) + if (patternUrl.matcher(word).matches()) { + val oneWord = ChatComponentText(word) + oneWord.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.OPEN_URL, word) fullText.appendSibling(oneWord) } else { - fullText.appendSibling(ChatComponentText(lines)) + fullText.appendSibling(ChatComponentText(word)) } } |