aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/misc
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-10-12 23:09:41 +1100
committerGitHub <noreply@github.com>2023-10-12 14:09:41 +0200
commit006d59f7c0613dd282e88ba41a21c0f74e1d1ae9 (patch)
tree4aef2950593948e030beebd73600105ce2524842 /src/main/java/at/hannibal2/skyhanni/features/misc
parent04d130775715d351f5be19c40378963819442dfd (diff)
downloadskyhanni-006d59f7c0613dd282e88ba41a21c0f74e1d1ae9.tar.gz
skyhanni-006d59f7c0613dd282e88ba41a21c0f74e1d1ae9.tar.bz2
skyhanni-006d59f7c0613dd282e88ba41a21c0f74e1d1ae9.zip
Feature: Player symbols in chat (#467)
Adds chat symbols such as ironman/bingo/nether faction like SBA had/has #467
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt83
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabStringType.kt2
2 files changed, 84 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt
new file mode 100644
index 000000000..2d411c5c3
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt
@@ -0,0 +1,83 @@
+package at.hannibal2.skyhanni.features.misc
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.features.misc.compacttablist.TabStringType
+import at.hannibal2.skyhanni.mixins.transformers.AccessorChatComponentText
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.StringUtils
+import at.hannibal2.skyhanni.utils.StringUtils.getPlayerName
+import at.hannibal2.skyhanni.utils.StringUtils.removeResets
+import at.hannibal2.skyhanni.utils.TabListData
+import net.minecraft.client.Minecraft
+import net.minecraft.util.ChatComponentText
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+// code inspired by SBA but heavily modified to be more functional and actually work
+class PlayerChatSymbols {
+ private val config get() = SkyHanniMod.feature.misc.chatSymbols
+ private val nameSymbols = mutableMapOf<String, String>()
+
+ @SubscribeEvent
+ fun onChatReceived(event: LorenzChatEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (!config.enabled) return
+
+ val message = event.message
+
+ val username = message.getPlayerName()
+ if (username == "-") return
+
+ val talkingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(username)
+
+ if (talkingPlayer != null) {
+ nameSymbols[username] = talkingPlayer.displayName.siblings[0].unformattedText
+ } else {
+ val result = TabListData.getTabList()
+ .find { playerName -> TabStringType.usernameFromLine(playerName) == username }
+
+ if (result != null) {
+ nameSymbols[username] = result
+ }
+ }
+
+ if (nameSymbols.contains(username)) {
+ val usernameWithSymbols = nameSymbols[username]!!
+
+ val split = usernameWithSymbols.split("$username ")
+ var emblemText = if (split.size > 1) split[1] else ""
+ emblemText = emblemText.removeResets()
+
+ if (emblemText != "") {
+ event.chatComponent = StringUtils.replaceFirstChatText(event.chatComponent, "$emblemText ", "")
+
+ StringUtils.modifyFirstChatComponent(event.chatComponent) { component ->
+ if (component is ChatComponentText) {
+ component as AccessorChatComponentText
+ if ( component.text_skyhanni().contains(username)) {
+ val oldText = component.text_skyhanni()
+
+ val newText = when (config.symbolLocation) {
+ 0 -> "$emblemText $oldText"
+ 1 -> {
+ // fixing it for when you type a message as the chat isn't split the same
+ if (oldText.contains("§f:")) {
+ val ownChatSplit = oldText.split("§f:")
+ if (ownChatSplit.size > 1) {
+ "${ownChatSplit[0]} $emblemText §f:${ownChatSplit[1]}"
+ } else oldText
+ } else "$oldText $emblemText "
+ }
+ else -> oldText
+ }
+ component.setText_skyhanni(component.text_skyhanni().replace(oldText, newText))
+ return@modifyFirstChatComponent true
+ }
+ return@modifyFirstChatComponent false
+ }
+ return@modifyFirstChatComponent false
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabStringType.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabStringType.kt
index 344a21ae1..996379041 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabStringType.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabStringType.kt
@@ -9,7 +9,7 @@ enum class TabStringType {
PLAYER;
companion object {
- private val usernamePattern = "^\\[(?<sblevel>\\d+)] (?:\\[\\w+] )?(?<username>\\w+)".toPattern()
+ val usernamePattern = "^\\[(?<sblevel>\\d+)] (?:\\[\\w+] )?(?<username>\\w+)".toPattern()
fun fromLine(line: String): TabStringType {
val strippedLine: String = line.removeColor()