From b94cc7476eb77cd68143da2dd28d38253209f0e4 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 16 Sep 2022 08:50:07 +0200 Subject: added support for links in player chat --- .../hannibal2/skyhanni/config/features/Chat.java | 6 ++++ .../skyhanni/features/chat/PlayerChatFormatter.kt | 38 +++++++++++++++------- 2 files changed, 33 insertions(+), 11 deletions(-) (limited to 'src') 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 @@ -107,6 +107,12 @@ public class Chat { @ConfigAccordionId(id = 1) 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") 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)) } } -- cgit