aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2022-09-16 08:50:07 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2022-09-16 08:50:07 +0200
commitb94cc7476eb77cd68143da2dd28d38253209f0e4 (patch)
tree51bbfb539e286dc97f103615606f8813f49cef30 /src
parentd32e0c37b6b514b31cd2e21294c81b3e56e3050f (diff)
downloadskyhanni-b94cc7476eb77cd68143da2dd28d38253209f0e4.tar.gz
skyhanni-b94cc7476eb77cd68143da2dd28d38253209f0e4.tar.bz2
skyhanni-b94cc7476eb77cd68143da2dd28d38253209f0e4.zip
added support for links in player chat
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Chat.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt38
2 files changed, 33 insertions, 11 deletions
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))
}
}