summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/chat
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-09-23 21:36:29 +1000
committerGitHub <noreply@github.com>2023-09-23 13:36:29 +0200
commitf617d59f1c52ad77f23ce28fb14bf44986e38ed1 (patch)
tree46d622e473a60ffe6d457cc426765f4213fbcb57 /src/main/java/at/hannibal2/skyhanni/features/chat
parent9ff6418d5fc3c4c866cb98e31a9ff38d788d9f77 (diff)
downloadskyhanni-f617d59f1c52ad77f23ce28fb14bf44986e38ed1.tar.gz
skyhanni-f617d59f1c52ad77f23ce28fb14bf44986e38ed1.tar.bz2
skyhanni-f617d59f1c52ad77f23ce28fb14bf44986e38ed1.zip
chat message changes #482
* add chat component functions * reword + remove empty text * remove type * isPlayerMessage * include the other stuff in the translator pr plus format * Merge branch 'hannibal002:beta' into chat_component_stuff * Merge remote-tracking branch 'origin/chat_component_stuff' into chat_… * allow to work with priv messages + get ready for future
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/chat')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt
index 1274fbdf2..300f8805b 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt
@@ -1,16 +1,17 @@
package at.hannibal2.skyhanni.features.chat
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.test.command.CopyErrorCommand
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.OSUtils
+import at.hannibal2.skyhanni.utils.StringUtils.getPlayerName
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import com.google.gson.*
import net.minecraft.event.ClickEvent
import net.minecraft.event.HoverEvent
import net.minecraft.util.ChatComponentText
import net.minecraft.util.ChatStyle
-import net.minecraftforge.client.event.ClientChatReceivedEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.apache.http.client.config.RequestConfig
@@ -23,26 +24,24 @@ import java.net.URLDecoder
import java.net.URLEncoder
class Translator {
-
private val messageContentRegex = Regex(".*: (.*)")
// Logic for listening for a user click on a chat message is from NotEnoughUpdates
- @SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
- fun onGuiChat(e: ClientChatReceivedEvent) {
+ @SubscribeEvent(priority = EventPriority.LOWEST)
+ fun onGuiChat(e: LorenzChatEvent) {
if (!SkyHanniMod.feature.chat.translator) return
- if (e.type != 0.toByte()) return // If this is not a player-sent message, return
- val chatComponent = e.message
- val message = chatComponent.unformattedText
- if (!messageContentRegex.matches(message.removeColor())) return
+ val message = e.message
+ if (message.getPlayerName() == "-") return
+
+ val editedComponent = if (e.chatComponent.siblings.size > 0) e.chatComponent.siblings.last() else e.chatComponent
- val clickStyle = createClickStyle(message)
- chatComponent.siblings.last().setChatStyle(clickStyle)
+ val clickStyle = createClickStyle(message.removeColor(), editedComponent.chatStyle)
+ editedComponent.setChatStyle(clickStyle)
}
- private fun createClickStyle(message: String): ChatStyle {
- val style = ChatStyle()
+ private fun createClickStyle(message: String, style: ChatStyle): ChatStyle {
style.setChatClickEvent(
ClickEvent(
ClickEvent.Action.RUN_COMMAND,
@@ -212,5 +211,4 @@ class Translator {
OSUtils.copyToClipboard(translation)
}
}
-
} \ No newline at end of file