aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt70
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabStringType.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt34
4 files changed, 61 insertions, 49 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java
index 16a9761b0..9b515dbd9 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java
@@ -669,8 +669,8 @@ public class MiscConfig {
@Expose
@ConfigOption(name = "Enabled", desc = "Adds extra symbols to the chat such as those from ironman, " +
- "stranded, bingo or nether factions and places them next to your regular player emblems. " +
- "Also allows emblems without sb level in chat.")
+ "stranded, bingo or nether factions and places them next to your regular player emblems. §eDoes" +
+ " not work with hide rank hider!")
@ConfigEditorBoolean
@FeatureToggle
public boolean enabled = true;
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt
index b826c5077..80ec276db 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt
@@ -6,10 +6,10 @@ 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.getPlayerNameAndRankFromChatMessage
import at.hannibal2.skyhanni.utils.StringUtils.getPlayerNameFromChatMessage
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.minecraft.util.IChatComponent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -18,6 +18,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class PlayerChatSymbols {
private val config get() = SkyHanniMod.feature.misc.chatSymbols
private val nameSymbols = mutableMapOf<String, String>()
+ private val symbolsPattern = "^(?<symbols>(?:(?:§\\w)+\\S)+) ".toPattern()
+ private val symbolPattern = "((?:§\\w)+\\S)".toPattern()
@SubscribeEvent
fun onChatReceived(event: LorenzChatEvent) {
@@ -26,55 +28,57 @@ class PlayerChatSymbols {
val username = event.message.getPlayerNameFromChatMessage() ?: return
- updateSymbolFromTabList(username)
+ var usernameWithSymbols = TabListData.getTabList()
+ .find { playerName -> TabStringType.usernameFromLine(playerName) == username }
- val usernameWithSymbols = nameSymbols[username] ?: return
+ if (usernameWithSymbols != null) {
+ nameSymbols[username] = usernameWithSymbols
+ }
+
+ usernameWithSymbols = nameSymbols[username] ?: return
val split = usernameWithSymbols.split("$username ")
- var emblemText = if (split.size > 1) split[1] else ""
- emblemText = emblemText.removeResets()
+ var emblemText = if (split.size > 1) split[1].removeResets() else ""
- if (emblemText == "") return
- event.chatComponent = StringUtils.replaceFirstChatText(event.chatComponent, "$emblemText ", "")
+ var matcher = symbolsPattern.matcher("$emblemText ")
+ emblemText = if (matcher.find()) {
+ matcher.group("symbols")
+ } else ""
- StringUtils.modifyFirstChatComponent(event.chatComponent) { component ->
- modify(component, username, emblemText)
+ if (emblemText == "") {
+ return
}
- }
- private fun updateSymbolFromTabList(username: String) {
- val talkingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(username)
- nameSymbols[username] = if (talkingPlayer != null) {
- talkingPlayer.displayName.siblings[0].unformattedText
- } else {
- TabListData.getTabList()
- .find { playerName -> TabStringType.usernameFromLine(playerName) == username } ?: return
+ val emblems = mutableListOf<String>()
+ matcher = symbolPattern.matcher(emblemText)
+ while (matcher.find()) {
+ emblems.add(matcher.group(1))
+ }
+
+ for (emblem in emblems) {
+ event.chatComponent = StringUtils.replaceFirstChatText(event.chatComponent, "$emblem ", "")
+ }
+
+ val rankAndName = event.message.getPlayerNameAndRankFromChatMessage() ?: return
+
+ StringUtils.modifyFirstChatComponent(event.chatComponent) { component ->
+ modify(component, emblemText, rankAndName)
}
}
- private fun modify(component: IChatComponent, username: String, emblemText: String): Boolean {
+ private fun modify(component: IChatComponent, emblemText: String, rankAndName: String): Boolean {
if (component !is ChatComponentText) return false
component as AccessorChatComponentText
- if (!component.text_skyhanni().contains(username)) return false
+ if (!component.text_skyhanni().contains(rankAndName)) return false
val oldText = component.text_skyhanni()
- component.setText_skyhanni(component.text_skyhanni().replace(oldText, getNewText(emblemText, oldText)))
+ component.setText_skyhanni(component.text_skyhanni().replace(oldText, getNewText(emblemText, oldText, rankAndName)))
return true
}
- private fun getNewText(emblemText: String, oldText: String): String = when (config.symbolLocation) {
- 0 -> "$emblemText $oldText"
- 1 -> iconAfterName(oldText, emblemText)
-
+ private fun getNewText(emblemText: String, oldText: String, rankAndName: String): String = when (config.symbolLocation) {
+ 0 -> oldText.replace(rankAndName, "$emblemText $rankAndName")
+ 1 -> oldText.replace(rankAndName, "$rankAndName $emblemText ")
else -> oldText
}
-
- private fun iconAfterName(oldText: String, emblemText: String): String {
- if (!oldText.contains("§f:")) return "$oldText $emblemText "
-
- // fixing it for when you type a message as the chat isn't split the same
- val ownChatSplit = oldText.split("§f:")
- if (ownChatSplit.size <= 1) return oldText
- return "${ownChatSplit[0]} $emblemText §f:${ownChatSplit[1]}"
- }
} \ 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 996379041..344a21ae1 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 {
- val usernamePattern = "^\\[(?<sblevel>\\d+)] (?:\\[\\w+] )?(?<username>\\w+)".toPattern()
+ private val usernamePattern = "^\\[(?<sblevel>\\d+)] (?:\\[\\w+] )?(?<username>\\w+)".toPattern()
fun fromLine(line: String): TabStringType {
val strippedLine: String = line.removeColor()
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
index 2e0a57c53..187407cbf 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
@@ -15,8 +15,8 @@ import java.util.regex.Matcher
import java.util.regex.Pattern
object StringUtils {
- private val playerChatPattern = ".*§[f7]: .*".toPattern()
- private val chatUsernamePattern = "^(?:\\[\\d+] )?(?:\\S )?(?:\\[\\w.+] )?(?<username>\\w+)(?: \\[.+?])?\$".toPattern()
+ private val playerChatPattern = "(?<important>.*?)(?:§[f7r])*: .*".toPattern()
+ private val chatUsernamePattern = "^(?:§\\w\\[§\\w\\d+§\\w] )?(?:(?:§\\w)+\\S )?(?<rankedName>(?:§\\w\\[\\w.+] )?(?:§\\w)?(?<username>\\w+))(?: (?:§\\w)?\\[.+?])?".toPattern()
private val whiteSpaceResetPattern = "^(?:\\s|§r)*|(?:\\s|§r)*$".toPattern()
private val resetPattern = "(?i)§R".toPattern()
@@ -201,24 +201,32 @@ object StringUtils {
}
fun String.getPlayerNameFromChatMessage(): String? {
- if (!playerChatPattern.matcher(this).matches()) return null
+ val matcher = matchPlayerChatMessage(this) ?: return null
+ return matcher.group("username")
+ }
- var username = this.removeColor().split(":")[0]
+ fun String.getPlayerNameAndRankFromChatMessage(): String? {
+ val matcher = matchPlayerChatMessage(this) ?: return null
+ return matcher.group("rankedName")
+ }
+
+ private fun matchPlayerChatMessage(string: String): Matcher? {
+ var username = ""
+ var matcher = playerChatPattern.matcher(string)
+ if (matcher.matches()) {
+ username = matcher.group("important").removeResets()
+ }
+ if (username == "") return null
if (username.contains(">")) {
username = username.substring(username.indexOf('>') + 1).trim()
}
- if (username.startsWith("From ")) {
- username = username.removePrefix("From ")
- }
- if (username.startsWith("To ")) {
- username = username.removePrefix("To ")
- }
- val matcher = chatUsernamePattern.matcher(username)
+ username = username.removePrefix("§dFrom ")
+ username = username.removePrefix("§dTo ")
- if (!matcher.matches()) return null
- return matcher.group("username")
+ matcher = chatUsernamePattern.matcher(username)
+ return if (matcher.matches()) matcher else null
}
fun String.convertToFormatted(): String {