From 86088270882d4842bc2f9b9eb22e3142c2fe46a3 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:13:53 +0200 Subject: [PATCH 01/46] create PlayerChatEvent --- .../data/hypixel/chat/PlayerChatEvent.kt | 11 +++++++ .../data/hypixel/chat/PlayerChatManager.kt | 33 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatEvent.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatEvent.kt new file mode 100644 index 000000000000..8834b28cb054 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatEvent.kt @@ -0,0 +1,11 @@ +package at.hannibal2.skyhanni.data.hypixel.chat + +import at.hannibal2.skyhanni.events.LorenzEvent + +class PlayerChatEvent( + val levelColor: String?, + val level: Int?, + val author: String, + val message: String, + var blockedReason: String? = null, +) : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt new file mode 100644 index 000000000000..34676677e578 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -0,0 +1,33 @@ +package at.hannibal2.skyhanni.data.hypixel.chat + +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.utils.LorenzUtils.groupOrNull +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class PlayerChatManager { + + private val patternGroup = RepoPattern.group("data.chat.player") + private val globalPattern by patternGroup.pattern( + "global", + "(?:§8\\[§r(?§.)(?\\d+)§r§8] §r)?(?§.+)(?:§f|§7§r§7): (?.*)" + ) + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + globalPattern.matchMatcher(event.message) { + val levelColor = groupOrNull("levelColor") + val level = groupOrNull("levelevellColor")?.formatInt() + val author = group("author") + val message = group("message") + val playerChatEvent = PlayerChatEvent(levelColor, level, author, message) + playerChatEvent.postAndCatch() + playerChatEvent.blockedReason?.let { + event.blockedReason = it + } + return + } + } +} From 0e70bcff9750a6eea12be0e00b284d37d997a49a Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:19:29 +0200 Subject: [PATCH 02/46] move party chat event into player chat manager --- .../at/hannibal2/skyhanni/data/PartyAPI.kt | 25 ++++++------------- .../data/hypixel/chat/PartyChatEvent.kt | 10 ++++++++ .../data/hypixel/chat/PlayerChatManager.kt | 18 ++++++++++++- .../skyhanni/events/PartyChatEvent.kt | 7 ------ .../features/commands/PartyChatCommands.kt | 2 +- 5 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PartyChatEvent.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/events/PartyChatEvent.kt diff --git a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt index 44a778292469..cbc923fddf7f 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.data +import at.hannibal2.skyhanni.data.hypixel.chat.PartyChatEvent import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.PartyChatEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils @@ -78,16 +78,6 @@ object PartyAPI { "§dParty Finder §f> (?.*?) §ejoined the dungeon group! \\(§[a-fA-F0-9].* Level \\d+§[a-fA-F0-9]\\)" ) - /** - * REGEX-TEST: §9Party §8> §b§l⚛ §b[MVP§f+§b] Dankbarkeit§f: §rx: -190, y: 5, z: -163 - * REGEX-TEST: §9Party §8> §6⚔ §6[MVP§3++§6] RealBacklight§f: §r!warp - * REGEX-TEST: §9Party §8> §b[MVP§3+§b] Eisengolem§f: §r!pt - */ - private val partyChatMessagePattern by patternGroup.pattern( - "chat.message", - "§9Party §8> (?[^:]*): §r(?.*)" - ) - val partyMembers = mutableListOf() var partyLeader: String? = null @@ -113,17 +103,16 @@ object PartyAPI { } } + @SubscribeEvent + fun onPartyCommand(event: PartyChatEvent) { + val name = event.author.cleanPlayerName() + addPlayer(name) + } + @SubscribeEvent fun onChat(event: LorenzChatEvent) { val message = event.message.trimWhiteSpace().removeResets() - partyChatMessagePattern.matchMatcher(event.message) { - val name = group("name").cleanPlayerName() - val message = group("message") - addPlayer(name) - PartyChatEvent(name, message, event).postAndCatch() - } - // new member joined youJoinedPartyPattern.matchMatcher(message) { val name = group("name").cleanPlayerName() diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PartyChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PartyChatEvent.kt new file mode 100644 index 000000000000..7ef364bd7f0f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PartyChatEvent.kt @@ -0,0 +1,10 @@ +package at.hannibal2.skyhanni.data.hypixel.chat + +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzEvent + +class PartyChatEvent( + val author: String, + val text: String, + val trigger: LorenzChatEvent, +) : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 34676677e578..5f1689e7befb 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -15,11 +15,21 @@ class PlayerChatManager { "(?:§8\\[§r(?§.)(?\\d+)§r§8] §r)?(?§.+)(?:§f|§7§r§7): (?.*)" ) + /** + * REGEX-TEST: §9Party §8> §b§l⚛ §b[MVP§f+§b] Dankbarkeit§f: §rx: -190, y: 5, z: -163 + * REGEX-TEST: §9Party §8> §6⚔ §6[MVP§3++§6] RealBacklight§f: §r!warp + * REGEX-TEST: §9Party §8> §b[MVP§3+§b] Eisengolem§f: §r!pt + */ + private val partyPattern by patternGroup.pattern( + "party", + "§9Party §8> (?[^:]*): §r(?.*)" + ) + @SubscribeEvent fun onChat(event: LorenzChatEvent) { globalPattern.matchMatcher(event.message) { val levelColor = groupOrNull("levelColor") - val level = groupOrNull("levelevellColor")?.formatInt() + val level = groupOrNull("level")?.formatInt() val author = group("author") val message = group("message") val playerChatEvent = PlayerChatEvent(levelColor, level, author, message) @@ -29,5 +39,11 @@ class PlayerChatManager { } return } + partyPattern.matchMatcher(event.message) { + val author = group("author") + val message = group("author") + PartyChatEvent(author, message, event).postAndCatch() + return + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/events/PartyChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/PartyChatEvent.kt deleted file mode 100644 index 76630583e975..000000000000 --- a/src/main/java/at/hannibal2/skyhanni/events/PartyChatEvent.kt +++ /dev/null @@ -1,7 +0,0 @@ -package at.hannibal2.skyhanni.events - -data class PartyChatEvent( - val author: String, - val text: String, - val trigger: LorenzChatEvent, -) : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt index b2de36a7a74b..251733b39dc4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt @@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.features.misc.PartyCommandsConfig import at.hannibal2.skyhanni.data.FriendAPI import at.hannibal2.skyhanni.data.PartyAPI -import at.hannibal2.skyhanni.events.PartyChatEvent +import at.hannibal2.skyhanni.data.hypixel.chat.PartyChatEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraftforge.fml.common.eventhandler.SubscribeEvent From 0b166880e738d04ab0c28fd3a2dbace917f5f7f1 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:29:02 +0200 Subject: [PATCH 03/46] creating NpcChatEvent and using shared AbstractChatEvent --- ...layerChatEvent.kt => AbstractChatEvent.kt} | 4 +-- .../data/hypixel/chat/NpcChatEvent.kt | 7 ++++++ .../data/hypixel/chat/PartyChatEvent.kt | 11 +++----- .../data/hypixel/chat/PlayerAllChatEvent.kt | 9 +++++++ .../data/hypixel/chat/PlayerChatManager.kt | 25 +++++++++++++------ .../features/commands/PartyChatCommands.kt | 4 +-- 6 files changed, 41 insertions(+), 19 deletions(-) rename src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/{PlayerChatEvent.kt => AbstractChatEvent.kt} (73%) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/NpcChatEvent.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerAllChatEvent.kt diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/AbstractChatEvent.kt similarity index 73% rename from src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatEvent.kt rename to src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/AbstractChatEvent.kt index 8834b28cb054..cacfbfe3b92d 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/AbstractChatEvent.kt @@ -2,9 +2,7 @@ package at.hannibal2.skyhanni.data.hypixel.chat import at.hannibal2.skyhanni.events.LorenzEvent -class PlayerChatEvent( - val levelColor: String?, - val level: Int?, +open class AbstractChatEvent( val author: String, val message: String, var blockedReason: String? = null, diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/NpcChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/NpcChatEvent.kt new file mode 100644 index 000000000000..e3fa42c8102b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/NpcChatEvent.kt @@ -0,0 +1,7 @@ +package at.hannibal2.skyhanni.data.hypixel.chat + +class NpcChatEvent( + author: String, + message: String, + blockedReason: String? = null, +) : AbstractChatEvent(author, message, blockedReason) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PartyChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PartyChatEvent.kt index 7ef364bd7f0f..a34dc2c31e7f 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PartyChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PartyChatEvent.kt @@ -1,10 +1,7 @@ package at.hannibal2.skyhanni.data.hypixel.chat -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.LorenzEvent - class PartyChatEvent( - val author: String, - val text: String, - val trigger: LorenzChatEvent, -) : LorenzEvent() + author: String, + message: String, + blockedReason: String? = null, +) : AbstractChatEvent(author, message, blockedReason) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerAllChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerAllChatEvent.kt new file mode 100644 index 000000000000..5ccdc1ed4171 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerAllChatEvent.kt @@ -0,0 +1,9 @@ +package at.hannibal2.skyhanni.data.hypixel.chat + +class PlayerAllChatEvent( + val levelColor: String?, + val level: Int?, + author: String, + message: String, + blockedReason: String? = null, +) : AbstractChatEvent(author, message, blockedReason) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 5f1689e7befb..b7bd51772712 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.data.hypixel.chat import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.groupOrNull import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher @@ -31,19 +32,29 @@ class PlayerChatManager { val levelColor = groupOrNull("levelColor") val level = groupOrNull("level")?.formatInt() val author = group("author") - val message = group("message") - val playerChatEvent = PlayerChatEvent(levelColor, level, author, message) - playerChatEvent.postAndCatch() - playerChatEvent.blockedReason?.let { - event.blockedReason = it + val message = LorenzUtils.stripVanillaMessage(group("message")) + if (author.contains("[NPC]")) { + NpcChatEvent(author, message.removePrefix("§f")).postChat(event) + NpcChatEvent(author, message.removePrefix("§f")).postChat(event) + } else { + PlayerAllChatEvent(levelColor, level, author, message).postChat(event) } return } partyPattern.matchMatcher(event.message) { val author = group("author") - val message = group("author") - PartyChatEvent(author, message, event).postAndCatch() + val message = group("message") + PartyChatEvent(author, message).postChat(event) return } } + + private fun AbstractChatEvent.postChat(event: LorenzChatEvent) { + if (postAndCatch()) { + event.cancel() + } + blockedReason?.let { + event.blockedReason = it + } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt index 251733b39dc4..b4730b3413f9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt @@ -60,9 +60,9 @@ object PartyChatCommands { @SubscribeEvent fun onPartyCommand(event: PartyChatEvent) { - if (event.text.firstOrNull() !in commandBeginChars) + if (event.message.firstOrNull() !in commandBeginChars) return - val commandLabel = event.text.substring(1).substringBefore(' ') + val commandLabel = event.message.substring(1).substringBefore(' ') val command = indexedPartyChatCommands[commandLabel.lowercase()] ?: return if (event.author == LorenzUtils.getPlayerName()) { return From ca07044d39a0a8996df0ab09df0207a3ac17dc91 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:31:37 +0200 Subject: [PATCH 04/46] add regex test to global --- .../skyhanni/data/hypixel/chat/PlayerChatManager.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index b7bd51772712..06492ce12828 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -11,6 +11,16 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class PlayerChatManager { private val patternGroup = RepoPattern.group("data.chat.player") + + /** + * REGEX-TEST: §8[§r§6428§r§8] §r§b[MVP§5+§b] Alea1337§f: t + * REGEX-TEST: §8[§r§e102§r§8] §r§7☠ §r§b[MVP§d+§b] cobyjoey§f§r§f: first person to type "halo0011 is my favorite player on the game I love halo0011!!!" + * REGEX-TEST: §8[§r§5396§r§8] §r§7☢ §r§b[MVP§c+§b] hannibal2§f: hello + * REGEX-TEST: §8[§r§e97§r§8] §r§7☃ §r§7Tambaloo§7§r§7: i did capital i + * REGEX-TEST: §8[§r§f76§r§8] §r§7❂ §r§a[VIP] Asymmetrically§f§r§f: i need to put on my necron + * REGEX-TEST: §8[§r§c446§r§8] §r§b§l⚛ §r§6[MVP§1++§6] XueRuu§f§r§f: TROPHY FISH! You caught a Lavahorse DIAMOND. + * REGEX-TEST: §b[MVP§c+§b] hannibal2§f: test + */ private val globalPattern by patternGroup.pattern( "global", "(?:§8\\[§r(?§.)(?\\d+)§r§8] §r)?(?§.+)(?:§f|§7§r§7): (?.*)" From 32b1adf783fd3ae2b288f5b1d41a7e19ea53c560 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:43:59 +0200 Subject: [PATCH 05/46] cleanup --- .../hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 06492ce12828..301def44e6af 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -39,14 +39,14 @@ class PlayerChatManager { @SubscribeEvent fun onChat(event: LorenzChatEvent) { globalPattern.matchMatcher(event.message) { - val levelColor = groupOrNull("levelColor") - val level = groupOrNull("level")?.formatInt() val author = group("author") val message = LorenzUtils.stripVanillaMessage(group("message")) if (author.contains("[NPC]")) { NpcChatEvent(author, message.removePrefix("§f")).postChat(event) NpcChatEvent(author, message.removePrefix("§f")).postChat(event) } else { + val levelColor = groupOrNull("levelColor") + val level = groupOrNull("level")?.formatInt() PlayerAllChatEvent(levelColor, level, author, message).postChat(event) } return From ef59df619af49bea28fe6163ef4f49d151452f00 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:49:52 +0200 Subject: [PATCH 06/46] adding PlayerShowItemChatEvent --- .../data/hypixel/chat/PlayerChatManager.kt | 26 +++++++++++++++++++ .../chat/event/PlayerShowItemChatEvent.kt | 13 ++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerShowItemChatEvent.kt diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 301def44e6af..55199066cea2 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.data.hypixel.chat +import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerShowItemChatEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.groupOrNull @@ -36,8 +37,33 @@ class PlayerChatManager { "§9Party §8> (?[^:]*): §r(?.*)" ) + /** + * REGEX-TEST: §b[MVP§c+§b] hannibal2§f§7 is holding §r§8[§6Heroic Aspect of the Void§8] + * REGEX-TEST: §b[MVP§c+§b] hannibal2§f§7 is holding §r§8[§7[Lvl 2] §dSpider§8] + * REGEX-TEST: §b[MVP§c+§b] hannibal2§f§7 is friends with a §r§8[§7[Lvl 200] §8[§6103§8§4✦§8] §6Golden Dragon§8] + * REGEX-TEST: §b[MVP§c+§b] hannibal2§f§7 is wearing §r§8[§5Glistening Implosion Belt§8] + * REGEX-TEST: §b[MVP§c+§b] hannibal2§f§7 is friends with a §r§8[§7[Lvl 100] §dEnderman§8] + * REGEX-TEST: §b[MVP§c+§b] hannibal2§f§7 has §r§8[§6Heroic Aspect of the Void§8] + * REGEX-TEST: §8[§5396§8] §7☢ §r§b[MVP§c+§b] hannibal2§f§7 is holding §r§8[§6Buzzing InfiniVacuum™ Hooverius§8] + */ + private val itemShowPattern by patternGroup.pattern( + "party", + "(?:§8\\[(?§.)(?\\d+)§8] )?(?.*)§f§7 (?is (?:holding|friends with a|wearing)|has) §r(?.*)" + ) + @SubscribeEvent fun onChat(event: LorenzChatEvent) { + itemShowPattern.matchMatcher(event.message) { + val levelColor = groupOrNull("levelColor") + val level = groupOrNull("level")?.formatInt() + val author = group("author") + val action = group("action") + val itemName = group("itemName") + + // for consistency + val message = "§7$action §r$itemName" + PlayerShowItemChatEvent(levelColor, level, author, message, action, itemName).postChat(event) + } globalPattern.matchMatcher(event.message) { val author = group("author") val message = LorenzUtils.stripVanillaMessage(group("message")) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerShowItemChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerShowItemChatEvent.kt new file mode 100644 index 000000000000..4bcff90044b1 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerShowItemChatEvent.kt @@ -0,0 +1,13 @@ +package at.hannibal2.skyhanni.data.hypixel.chat.event + +import at.hannibal2.skyhanni.data.hypixel.chat.AbstractChatEvent + +class PlayerShowItemChatEvent( + val levelColor: String?, + val level: Int?, + author: String, + message: String, + val action: String, + val itemName: String, + blockedReason: String? = null, +) : AbstractChatEvent(author, message, blockedReason) From 6871c8aecea65ae84a0f31fd917e12498e7f5232 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:58:07 +0200 Subject: [PATCH 07/46] adding GuildChatEvent --- .../data/hypixel/chat/PlayerChatManager.kt | 17 +++++++++++++++++ .../data/hypixel/chat/event/GuildChatEvent.kt | 9 +++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 55199066cea2..5dbb74250fe9 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.data.hypixel.chat +import at.hannibal2.skyhanni.data.hypixel.chat.event.GuildChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerShowItemChatEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils @@ -37,6 +38,16 @@ class PlayerChatManager { "§9Party §8> (?[^:]*): §r(?.*)" ) + /** + * REGEX-TEST: §9Party §8> §b§l⚛ §b[MVP§f+§b] Dankbarkeit§f: §rx: -190, y: 5, z: -163 + * REGEX-TEST: §9Party §8> §6⚔ §6[MVP§3++§6] RealBacklight§f: §r!warp + * REGEX-TEST: §9Party §8> §b[MVP§3+§b] Eisengolem§f: §r!pt + */ + private val guildPattern by patternGroup.pattern( + "party", + "§2Guild > (?[^:]*): (?.*)" + ) + /** * REGEX-TEST: §b[MVP§c+§b] hannibal2§f§7 is holding §r§8[§6Heroic Aspect of the Void§8] * REGEX-TEST: §b[MVP§c+§b] hannibal2§f§7 is holding §r§8[§7[Lvl 2] §dSpider§8] @@ -83,6 +94,12 @@ class PlayerChatManager { PartyChatEvent(author, message).postChat(event) return } + guildPattern.matchMatcher(event.message) { + val author = group("author") + val message = group("message") + GuildChatEvent(author, message).postChat(event) + return + } } private fun AbstractChatEvent.postChat(event: LorenzChatEvent) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt new file mode 100644 index 000000000000..746b033f143e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt @@ -0,0 +1,9 @@ +package at.hannibal2.skyhanni.data.hypixel.chat.event + +import at.hannibal2.skyhanni.data.hypixel.chat.AbstractChatEvent + +class GuildChatEvent( + author: String, + message: String, + blockedReason: String? = null, +) : AbstractChatEvent(author, message, blockedReason) From 98d658074e60a6a0a0c96260e364e5f5cc348b55 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:58:58 +0200 Subject: [PATCH 08/46] move packets around --- src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt | 2 +- .../hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt | 4 ++++ .../data/hypixel/chat/{ => event}/AbstractChatEvent.kt | 2 +- .../skyhanni/data/hypixel/chat/event/GuildChatEvent.kt | 2 -- .../skyhanni/data/hypixel/chat/{ => event}/NpcChatEvent.kt | 2 +- .../skyhanni/data/hypixel/chat/{ => event}/PartyChatEvent.kt | 2 +- .../data/hypixel/chat/{ => event}/PlayerAllChatEvent.kt | 2 +- .../data/hypixel/chat/event/PlayerShowItemChatEvent.kt | 2 -- .../hannibal2/skyhanni/features/commands/PartyChatCommands.kt | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) rename src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/{ => event}/AbstractChatEvent.kt (77%) rename src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/{ => event}/NpcChatEvent.kt (73%) rename src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/{ => event}/PartyChatEvent.kt (73%) rename src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/{ => event}/PlayerAllChatEvent.kt (79%) diff --git a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt index cbc923fddf7f..239305caf466 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.data -import at.hannibal2.skyhanni.data.hypixel.chat.PartyChatEvent +import at.hannibal2.skyhanni.data.hypixel.chat.event.PartyChatEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 5dbb74250fe9..0a55ee0b33d1 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -1,6 +1,10 @@ package at.hannibal2.skyhanni.data.hypixel.chat +import at.hannibal2.skyhanni.data.hypixel.chat.event.AbstractChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.GuildChatEvent +import at.hannibal2.skyhanni.data.hypixel.chat.event.NpcChatEvent +import at.hannibal2.skyhanni.data.hypixel.chat.event.PartyChatEvent +import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerAllChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerShowItemChatEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/AbstractChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/AbstractChatEvent.kt similarity index 77% rename from src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/AbstractChatEvent.kt rename to src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/AbstractChatEvent.kt index cacfbfe3b92d..69c5d79714ee 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/AbstractChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/AbstractChatEvent.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.data.hypixel.chat +package at.hannibal2.skyhanni.data.hypixel.chat.event import at.hannibal2.skyhanni.events.LorenzEvent diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt index 746b033f143e..27e1d252d93d 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt @@ -1,7 +1,5 @@ package at.hannibal2.skyhanni.data.hypixel.chat.event -import at.hannibal2.skyhanni.data.hypixel.chat.AbstractChatEvent - class GuildChatEvent( author: String, message: String, diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/NpcChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/NpcChatEvent.kt similarity index 73% rename from src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/NpcChatEvent.kt rename to src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/NpcChatEvent.kt index e3fa42c8102b..c9f541173aad 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/NpcChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/NpcChatEvent.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.data.hypixel.chat +package at.hannibal2.skyhanni.data.hypixel.chat.event class NpcChatEvent( author: String, diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PartyChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PartyChatEvent.kt similarity index 73% rename from src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PartyChatEvent.kt rename to src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PartyChatEvent.kt index a34dc2c31e7f..4aec61533c08 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PartyChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PartyChatEvent.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.data.hypixel.chat +package at.hannibal2.skyhanni.data.hypixel.chat.event class PartyChatEvent( author: String, diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerAllChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt similarity index 79% rename from src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerAllChatEvent.kt rename to src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt index 5ccdc1ed4171..40c4a0188076 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerAllChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.data.hypixel.chat +package at.hannibal2.skyhanni.data.hypixel.chat.event class PlayerAllChatEvent( val levelColor: String?, diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerShowItemChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerShowItemChatEvent.kt index 4bcff90044b1..e43a1a67d948 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerShowItemChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerShowItemChatEvent.kt @@ -1,7 +1,5 @@ package at.hannibal2.skyhanni.data.hypixel.chat.event -import at.hannibal2.skyhanni.data.hypixel.chat.AbstractChatEvent - class PlayerShowItemChatEvent( val levelColor: String?, val level: Int?, diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt index b4730b3413f9..8ead93fcf86b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt @@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.features.misc.PartyCommandsConfig import at.hannibal2.skyhanni.data.FriendAPI import at.hannibal2.skyhanni.data.PartyAPI -import at.hannibal2.skyhanni.data.hypixel.chat.PartyChatEvent +import at.hannibal2.skyhanni.data.hypixel.chat.event.PartyChatEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraftforge.fml.common.eventhandler.SubscribeEvent From 13ce9877e12784f95ce9c207a8bce1a8025be121 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:02:56 +0200 Subject: [PATCH 09/46] create PrivateMessageChatEvent --- .../data/hypixel/chat/PlayerChatManager.kt | 17 +++++++++++++++++ .../chat/event/PrivateMessageChatEvent.kt | 8 ++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PrivateMessageChatEvent.kt diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 0a55ee0b33d1..42b9031d569e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.data.hypixel.chat.event.NpcChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PartyChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerAllChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerShowItemChatEvent +import at.hannibal2.skyhanni.data.hypixel.chat.event.PrivateMessageChatEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.groupOrNull @@ -52,6 +53,15 @@ class PlayerChatManager { "§2Guild > (?[^:]*): (?.*)" ) + /** + * REGEX-TEST: §dFrom §r§b[MVP§r§3+§r§b] Eisengolem§r§7: §r§7Baum + * REGEX-TEST: §dTo §r§b[MVP§r§3+§r§b] Eisengolem§r§7: §r§7hey + */ + private val privateMessagePattern by patternGroup.pattern( + "party", + "§d(?From|To) §r(?[^:]*)§7: §r§7(?.*)" + ) + /** * REGEX-TEST: §b[MVP§c+§b] hannibal2§f§7 is holding §r§8[§6Heroic Aspect of the Void§8] * REGEX-TEST: §b[MVP§c+§b] hannibal2§f§7 is holding §r§8[§7[Lvl 2] §dSpider§8] @@ -104,6 +114,13 @@ class PlayerChatManager { GuildChatEvent(author, message).postChat(event) return } + privateMessagePattern.matchMatcher(event.message) { + val direction = group("direction") + val author = group("author") + val message = group("message") + PrivateMessageChatEvent(direction, author, message).postChat(event) + return + } } private fun AbstractChatEvent.postChat(event: LorenzChatEvent) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PrivateMessageChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PrivateMessageChatEvent.kt new file mode 100644 index 000000000000..949ecc1f6555 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PrivateMessageChatEvent.kt @@ -0,0 +1,8 @@ +package at.hannibal2.skyhanni.data.hypixel.chat.event + +class PrivateMessageChatEvent( + val direction: String?, + author: String, + message: String, + blockedReason: String? = null, +) : AbstractChatEvent(author, message, blockedReason) From 029b920f181521388f918aacbe944e031c76f8d6 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:04:24 +0200 Subject: [PATCH 10/46] add boop support --- .../hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 42b9031d569e..81825b301d64 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -56,10 +56,11 @@ class PlayerChatManager { /** * REGEX-TEST: §dFrom §r§b[MVP§r§3+§r§b] Eisengolem§r§7: §r§7Baum * REGEX-TEST: §dTo §r§b[MVP§r§3+§r§b] Eisengolem§r§7: §r§7hey + * REGEX-TEST: §dTo §r§b[MVP§r§5+§r§b] Alea1337§r§7: §r§d§lBoop! */ private val privateMessagePattern by patternGroup.pattern( "party", - "§d(?From|To) §r(?[^:]*)§7: §r§7(?.*)" + "§d(?From|To) §r(?[^:]*)§7: §r(?.*)" ) /** From 75c88fc0c6002eea53c250839b287a657821a1cb Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:07:48 +0200 Subject: [PATCH 11/46] add SystemMessageEvent --- .../skyhanni/data/hypixel/chat/PlayerChatManager.kt | 13 +++++++++++++ .../data/hypixel/chat/event/SystemMessageEvent.kt | 8 ++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/SystemMessageEvent.kt diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 81825b301d64..4f52d4b9be87 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.hypixel.chat.event.PartyChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerAllChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerShowItemChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PrivateMessageChatEvent +import at.hannibal2.skyhanni.data.hypixel.chat.event.SystemMessageEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.groupOrNull @@ -122,6 +123,18 @@ class PlayerChatManager { PrivateMessageChatEvent(direction, author, message).postChat(event) return } + + sendSystemMessage(event) + } + + private fun sendSystemMessage(event: LorenzChatEvent) { + val systemEvent = SystemMessageEvent(event.message) + if (systemEvent.postAndCatch()) { + event.cancel() + } + systemEvent.blockedReason?.let { + event.blockedReason = it + } } private fun AbstractChatEvent.postChat(event: LorenzChatEvent) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/SystemMessageEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/SystemMessageEvent.kt new file mode 100644 index 000000000000..6f62e5ec0dc1 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/SystemMessageEvent.kt @@ -0,0 +1,8 @@ +package at.hannibal2.skyhanni.data.hypixel.chat.event + +import at.hannibal2.skyhanni.events.LorenzEvent + +class SystemMessageEvent( + val message: String, + var blockedReason: String? = null, +) : LorenzEvent() From cf5e78e8eb6d30af1e9567475da6b71d4ce2b071 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:24:12 +0200 Subject: [PATCH 12/46] allow modifying of chatComponent --- .../data/hypixel/chat/PlayerChatManager.kt | 40 +++++++++++-------- .../hypixel/chat/event/AbstractChatEvent.kt | 2 + .../data/hypixel/chat/event/GuildChatEvent.kt | 5 ++- .../data/hypixel/chat/event/NpcChatEvent.kt | 5 ++- .../data/hypixel/chat/event/PartyChatEvent.kt | 5 ++- .../hypixel/chat/event/PlayerAllChatEvent.kt | 5 ++- .../chat/event/PlayerShowItemChatEvent.kt | 5 ++- .../chat/event/PrivateMessageChatEvent.kt | 5 ++- .../hypixel/chat/event/SystemMessageEvent.kt | 2 + 9 files changed, 52 insertions(+), 22 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 4f52d4b9be87..686fe4f5d188 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -14,6 +14,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.groupOrNull import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class PlayerChatManager { @@ -80,6 +81,7 @@ class PlayerChatManager { @SubscribeEvent fun onChat(event: LorenzChatEvent) { + val chatComponent = event.chatComponent itemShowPattern.matchMatcher(event.message) { val levelColor = groupOrNull("levelColor") val level = groupOrNull("level")?.formatInt() @@ -89,38 +91,37 @@ class PlayerChatManager { // for consistency val message = "§7$action §r$itemName" - PlayerShowItemChatEvent(levelColor, level, author, message, action, itemName).postChat(event) + PlayerShowItemChatEvent(levelColor, level, author, message, action, itemName, chatComponent).postChat(event) } globalPattern.matchMatcher(event.message) { val author = group("author") val message = LorenzUtils.stripVanillaMessage(group("message")) if (author.contains("[NPC]")) { - NpcChatEvent(author, message.removePrefix("§f")).postChat(event) - NpcChatEvent(author, message.removePrefix("§f")).postChat(event) + NpcChatEvent(author, message.removePrefix("§f"), chatComponent).postChat(event) } else { val levelColor = groupOrNull("levelColor") val level = groupOrNull("level")?.formatInt() - PlayerAllChatEvent(levelColor, level, author, message).postChat(event) + PlayerAllChatEvent(levelColor, level, author, message, chatComponent).postChat(event) } return } partyPattern.matchMatcher(event.message) { val author = group("author") val message = group("message") - PartyChatEvent(author, message).postChat(event) + PartyChatEvent(author, message, chatComponent).postChat(event) return } guildPattern.matchMatcher(event.message) { val author = group("author") val message = group("message") - GuildChatEvent(author, message).postChat(event) + GuildChatEvent(author, message, chatComponent).postChat(event) return } privateMessagePattern.matchMatcher(event.message) { val direction = group("direction") val author = group("author") val message = group("message") - PrivateMessageChatEvent(direction, author, message).postChat(event) + PrivateMessageChatEvent(direction, author, message, chatComponent).postChat(event) return } @@ -128,21 +129,28 @@ class PlayerChatManager { } private fun sendSystemMessage(event: LorenzChatEvent) { - val systemEvent = SystemMessageEvent(event.message) - if (systemEvent.postAndCatch()) { - event.cancel() - } - systemEvent.blockedReason?.let { - event.blockedReason = it + with(SystemMessageEvent(event.message, event.chatComponent)) { + val cancelled = postAndCatch() + event.handleChat(cancelled, blockedReason, chatComponent) } } private fun AbstractChatEvent.postChat(event: LorenzChatEvent) { - if (postAndCatch()) { - event.cancel() + val cancelled = postAndCatch() + event.handleChat(cancelled, blockedReason, chatComponent) + } + + private fun LorenzChatEvent.handleChat( + cancelled: Boolean, + blockedReason: String?, + chatComponent: IChatComponent, + ) { + if (cancelled) { + this.cancel() } blockedReason?.let { - event.blockedReason = it + this.blockedReason = it } + this.chatComponent = chatComponent } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/AbstractChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/AbstractChatEvent.kt index 69c5d79714ee..cd0a8f92b57e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/AbstractChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/AbstractChatEvent.kt @@ -1,9 +1,11 @@ package at.hannibal2.skyhanni.data.hypixel.chat.event import at.hannibal2.skyhanni.events.LorenzEvent +import net.minecraft.util.IChatComponent open class AbstractChatEvent( val author: String, val message: String, + var chatComponent: IChatComponent, var blockedReason: String? = null, ) : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt index 27e1d252d93d..9e453cdc5ca1 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt @@ -1,7 +1,10 @@ package at.hannibal2.skyhanni.data.hypixel.chat.event +import net.minecraft.util.IChatComponent + class GuildChatEvent( author: String, message: String, + chatComponent: IChatComponent, blockedReason: String? = null, -) : AbstractChatEvent(author, message, blockedReason) +) : AbstractChatEvent(author, message, chatComponent, blockedReason) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/NpcChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/NpcChatEvent.kt index c9f541173aad..574324520162 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/NpcChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/NpcChatEvent.kt @@ -1,7 +1,10 @@ package at.hannibal2.skyhanni.data.hypixel.chat.event +import net.minecraft.util.IChatComponent + class NpcChatEvent( author: String, message: String, + chatComponent: IChatComponent, blockedReason: String? = null, -) : AbstractChatEvent(author, message, blockedReason) +) : AbstractChatEvent(author, message, chatComponent, blockedReason) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PartyChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PartyChatEvent.kt index 4aec61533c08..dc9e921cc66f 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PartyChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PartyChatEvent.kt @@ -1,7 +1,10 @@ package at.hannibal2.skyhanni.data.hypixel.chat.event +import net.minecraft.util.IChatComponent + class PartyChatEvent( author: String, message: String, + chatComponent: IChatComponent, blockedReason: String? = null, -) : AbstractChatEvent(author, message, blockedReason) +) : AbstractChatEvent(author, message, chatComponent, blockedReason) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt index 40c4a0188076..69f0a407095b 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt @@ -1,9 +1,12 @@ package at.hannibal2.skyhanni.data.hypixel.chat.event +import net.minecraft.util.IChatComponent + class PlayerAllChatEvent( val levelColor: String?, val level: Int?, author: String, message: String, + chatComponent: IChatComponent, blockedReason: String? = null, -) : AbstractChatEvent(author, message, blockedReason) +) : AbstractChatEvent(author, message, chatComponent, blockedReason) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerShowItemChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerShowItemChatEvent.kt index e43a1a67d948..229264b27831 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerShowItemChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerShowItemChatEvent.kt @@ -1,5 +1,7 @@ package at.hannibal2.skyhanni.data.hypixel.chat.event +import net.minecraft.util.IChatComponent + class PlayerShowItemChatEvent( val levelColor: String?, val level: Int?, @@ -7,5 +9,6 @@ class PlayerShowItemChatEvent( message: String, val action: String, val itemName: String, + chatComponent: IChatComponent, blockedReason: String? = null, -) : AbstractChatEvent(author, message, blockedReason) +) : AbstractChatEvent(author, message, chatComponent, blockedReason) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PrivateMessageChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PrivateMessageChatEvent.kt index 949ecc1f6555..f23b1d0b0068 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PrivateMessageChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PrivateMessageChatEvent.kt @@ -1,8 +1,11 @@ package at.hannibal2.skyhanni.data.hypixel.chat.event +import net.minecraft.util.IChatComponent + class PrivateMessageChatEvent( val direction: String?, author: String, message: String, + chatComponent: IChatComponent, blockedReason: String? = null, -) : AbstractChatEvent(author, message, blockedReason) +) : AbstractChatEvent(author, message, chatComponent, blockedReason) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/SystemMessageEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/SystemMessageEvent.kt index 6f62e5ec0dc1..82c53d0b16d2 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/SystemMessageEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/SystemMessageEvent.kt @@ -1,8 +1,10 @@ package at.hannibal2.skyhanni.data.hypixel.chat.event import at.hannibal2.skyhanni.events.LorenzEvent +import net.minecraft.util.IChatComponent class SystemMessageEvent( val message: String, + var chatComponent: IChatComponent, var blockedReason: String? = null, ) : LorenzEvent() From 590fa3c08c25628eecf438034ea8aac0ddb03abd Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:26:27 +0200 Subject: [PATCH 13/46] code cleanup --- .../data/hypixel/chat/PlayerChatManager.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 686fe4f5d188..e21df9cb61c1 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -82,17 +82,6 @@ class PlayerChatManager { @SubscribeEvent fun onChat(event: LorenzChatEvent) { val chatComponent = event.chatComponent - itemShowPattern.matchMatcher(event.message) { - val levelColor = groupOrNull("levelColor") - val level = groupOrNull("level")?.formatInt() - val author = group("author") - val action = group("action") - val itemName = group("itemName") - - // for consistency - val message = "§7$action §r$itemName" - PlayerShowItemChatEvent(levelColor, level, author, message, action, itemName, chatComponent).postChat(event) - } globalPattern.matchMatcher(event.message) { val author = group("author") val message = LorenzUtils.stripVanillaMessage(group("message")) @@ -124,6 +113,17 @@ class PlayerChatManager { PrivateMessageChatEvent(direction, author, message, chatComponent).postChat(event) return } + itemShowPattern.matchMatcher(event.message) { + val levelColor = groupOrNull("levelColor") + val level = groupOrNull("level")?.formatInt() + val author = group("author") + val action = group("action") + val itemName = group("itemName") + + // for consistency + val message = "§7$action §r$itemName" + PlayerShowItemChatEvent(levelColor, level, author, message, action, itemName, chatComponent).postChat(event) + } sendSystemMessage(event) } From 075933e95671255dd83bd5cd4f1257f09e1c22c2 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 11:24:01 +0200 Subject: [PATCH 14/46] make it work --- .../java/at/hannibal2/skyhanni/SkyHanniMod.kt | 4 + .../features/chat/PlayerMessagesConfig.java | 6 ++ .../data/hypixel/chat/PlayerChatManager.kt | 11 +-- .../data/hypixel/chat/PlayerNameFormatter.kt | 78 +++++++++++++++++++ .../hypixel/chat/event/PlayerAllChatEvent.kt | 1 + .../chat/playerchat/PlayerChatModifier.kt | 43 ++-------- .../hannibal2/skyhanni/utils/StringUtils.kt | 40 ++++++++++ 7 files changed, 141 insertions(+), 42 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 62ee61fb6974..08c651aafb4c 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -54,6 +54,8 @@ import at.hannibal2.skyhanni.data.TitleData import at.hannibal2.skyhanni.data.TitleManager import at.hannibal2.skyhanni.data.ToolTipData import at.hannibal2.skyhanni.data.TrackerManager +import at.hannibal2.skyhanni.data.hypixel.chat.PlayerChatManager +import at.hannibal2.skyhanni.data.hypixel.chat.PlayerNameFormatter import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson import at.hannibal2.skyhanni.data.jsonobjects.local.JacobContestsJson import at.hannibal2.skyhanni.data.jsonobjects.local.KnownFeaturesJson @@ -458,6 +460,8 @@ class SkyHanniMod { // data loadModule(this) loadModule(ChatManager) + loadModule(PlayerChatManager()) + loadModule(PlayerNameFormatter()) loadModule(HypixelData()) loadModule(LocationFixData) loadModule(DungeonAPI) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java index 5ebad3d0cea4..05d9bad89c9c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java @@ -13,6 +13,12 @@ public class PlayerMessagesConfig { @FeatureToggle public boolean playerRankHider = false; + @Expose + @ConfigOption(name = "Ignore YouTube", desc = "Do not remove the rank for YouTubers") + @ConfigEditorBoolean + @FeatureToggle + public boolean ignoreYouTube = false; + @Expose @ConfigOption(name = "Chat Filter", desc = "Scan messages sent by players for blacklisted words and gray out the message if any are found.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index e21df9cb61c1..e97acab08f66 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -32,7 +32,7 @@ class PlayerChatManager { */ private val globalPattern by patternGroup.pattern( "global", - "(?:§8\\[§r(?§.)(?\\d+)§r§8] §r)?(?§.+)(?:§f|§7§r§7): (?.*)" + "(?:§8\\[§r(?§.)(?\\d+)§r§8] §r)?(?§.+)(?§f|§7§r§7): (?.*)" ) /** @@ -51,7 +51,7 @@ class PlayerChatManager { * REGEX-TEST: §9Party §8> §b[MVP§3+§b] Eisengolem§f: §r!pt */ private val guildPattern by patternGroup.pattern( - "party", + "guild", "§2Guild > (?[^:]*): (?.*)" ) @@ -61,7 +61,7 @@ class PlayerChatManager { * REGEX-TEST: §dTo §r§b[MVP§r§5+§r§b] Alea1337§r§7: §r§d§lBoop! */ private val privateMessagePattern by patternGroup.pattern( - "party", + "privatemessage", "§d(?From|To) §r(?[^:]*)§7: §r(?.*)" ) @@ -75,7 +75,7 @@ class PlayerChatManager { * REGEX-TEST: §8[§5396§8] §7☢ §r§b[MVP§c+§b] hannibal2§f§7 is holding §r§8[§6Buzzing InfiniVacuum™ Hooverius§8] */ private val itemShowPattern by patternGroup.pattern( - "party", + "itemshow", "(?:§8\\[(?§.)(?\\d+)§8] )?(?.*)§f§7 (?is (?:holding|friends with a|wearing)|has) §r(?.*)" ) @@ -88,9 +88,10 @@ class PlayerChatManager { if (author.contains("[NPC]")) { NpcChatEvent(author, message.removePrefix("§f"), chatComponent).postChat(event) } else { + val chatColor = group("chatColor") val levelColor = groupOrNull("levelColor") val level = groupOrNull("level")?.formatInt() - PlayerAllChatEvent(levelColor, level, author, message, chatComponent).postChat(event) + PlayerAllChatEvent(levelColor, level, author, chatColor, message, chatComponent).postChat(event) } return } diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt new file mode 100644 index 000000000000..228b9c9dc7c8 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -0,0 +1,78 @@ +package at.hannibal2.skyhanni.data.hypixel.chat + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerAllChatEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils +import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class PlayerNameFormatter { + private val config get() = SkyHanniMod.feature.chat.playerMessage + + private val patternGroup = RepoPattern.group("data.chat.player.name") + + /** + * REGEX-TEST: §7☢ §r§b[MVP§d+§b] hannibal2 + * REGEX-TEST: §7☢ §r§b[MVP§d+§b] hannibal2 + * REGEX-TEST: §7☢ §r§bhannibal2 + * REGEX-TEST: §7☢ §rhannibal2 + */ + private val emblemPattern by patternGroup.pattern( + "emblem", + "(?§..) §r(?.*)" + ) + + @SubscribeEvent + fun onPlayerAllChat(event: PlayerAllChatEvent) { + val levelColor = event.levelColor + val level = event.level + val message = event.message + val author = event.author + val chatColor = event.chatColor + val name = format(levelColor, level, author) + val newMessage = "$name$chatColor: $message" + + println("newMessage: '$newMessage'") + event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return + } + + fun format(levelColor: String?, level: Int?, author: String): String { + var cleanAuthor = cleanAuthor(author) + var emblemFormat = "" + + emblemPattern.matchMatcher(author) { + val emblem = group("emblem") + // TODO add emblem hider + emblemFormat = "$emblem §r" + cleanAuthor = group("author") + } + + val authorFormat = formatAuthor(cleanAuthor) + val levelFormat = formatLevel(levelColor, level) + // TODO add chat format order options + return "$levelFormat$emblemFormat$authorFormat" + } + + private fun formatLevel(rawColor: String?, rawLevel: Int?): String { + val color = rawColor ?: return "" + val level = rawLevel ?: error("level is null, color is not null") + // TODO add level formatting options + return "§8[§r$color$level§r§8] §r" + } + + private fun cleanAuthor(author: String): String { + val text = LorenzUtils.stripVanillaMessage(author) + return text.removeSuffix("§f") + } + + private fun formatAuthor(author: String): String { + if (!config.playerRankHider) return author + if (author.contains("ADMIN")) return author + if (config.ignoreYouTube && author.contains("YOUTUBER")) return author + + return author.cleanPlayerName(displayName = true) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt index 69f0a407095b..ded937bc3c89 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt @@ -6,6 +6,7 @@ class PlayerAllChatEvent( val levelColor: String?, val level: Int?, author: String, + val chatColor: String?, message: String, chatComponent: IChatComponent, blockedReason: String? = null, diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt index 08776964584d..680e5168eafb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt @@ -2,12 +2,11 @@ package at.hannibal2.skyhanni.features.chat.playerchat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.data.hypixel.chat.event.SystemMessageEvent import at.hannibal2.skyhanni.features.dungeon.DungeonMilestonesDisplay import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager +import at.hannibal2.skyhanni.utils.StringUtils import at.hannibal2.skyhanni.utils.StringUtils.matches -import net.minecraft.util.ChatComponentText -import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class PlayerChatModifier { @@ -18,44 +17,14 @@ class PlayerChatModifier { init { patterns.add("§[ab6]\\[(?:VIP|MVP)(?:§.|\\+)*] {1,2}(?:§[7ab6])?(\\w{2,16})".toRegex()) // ranked player with prefix everywhere patterns.add("§[7ab6](\\w{2,16})§r(?!§7x)(?!\$)".toRegex()) // all players without rank prefix in notification messages - patterns.add("(?:§7 )?§7(\\w{2,16})§7§r".toRegex()) // nons user chat +// patterns.add("(?:§7 )?§7(\\w{2,16})§7§r".toRegex()) // nons user chat } @SubscribeEvent - fun onChat(event: LorenzChatEvent) { - val foundCommands = mutableListOf() - val message = event.chatComponent + fun onChat(event: SystemMessageEvent) { + val newMessage = cutMessage(event.chatComponent.formattedText) - addComponent(foundCommands, event.chatComponent) - for (sibling in message.siblings) { - addComponent(foundCommands, sibling) - } - - val size = foundCommands.size - if (size > 1) { - return - } - val original = event.chatComponent.formattedText - val newText = cutMessage(original) - if (original == newText) return - - val text = ChatComponentText(newText) - if (size == 1) { - val chatStyle = foundCommands[0].chatStyle - text.chatStyle.chatClickEvent = chatStyle.chatClickEvent - text.chatStyle.chatHoverEvent = chatStyle.chatHoverEvent - } - event.chatComponent = text - } - - private fun addComponent(foundCommands: MutableList, message: IChatComponent) { - val clickEvent = message.chatStyle.chatClickEvent - if (clickEvent != null) { - if (foundCommands.size == 1 && foundCommands[0].chatStyle.chatClickEvent.value == clickEvent.value) { - return - } - foundCommands.add(message) - } + event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return } private fun cutMessage(input: String): String { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 59b82cd8cafa..0ddefcf44aca 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -317,4 +317,44 @@ object StringUtils { fun isEmpty(message: String): Boolean = message.removeColor().trimWhiteSpaceAndResets().isEmpty() fun generateRandomId() = UUID.randomUUID().toString() + + fun replaceIfNeeded( + original: IChatComponent, + newText: String, + ): ChatComponentText? { + val foundCommands = mutableListOf() + + addComponent(foundCommands, original) + for (sibling in original.siblings) { + addComponent(foundCommands, sibling) + } + + val size = foundCommands.size + if (size > 1) { + return null + } + if (original.formattedText == newText) return null + println("replaceIfNeeded!") + println("original: ${original.formattedText}") + println("newText: $newText") + + val text = ChatComponentText(newText) + if (size == 1) { + val chatStyle = foundCommands[0].chatStyle + text.chatStyle.chatClickEvent = chatStyle.chatClickEvent + text.chatStyle.chatHoverEvent = chatStyle.chatHoverEvent + } + + return text + } + + private fun addComponent(foundCommands: MutableList, message: IChatComponent) { + val clickEvent = message.chatStyle.chatClickEvent + if (clickEvent != null) { + if (foundCommands.size == 1 && foundCommands[0].chatStyle.chatClickEvent.value == clickEvent.value) { + return + } + foundCommands.add(message) + } + } } From a92ebd2c8774d600c69f9f178adca5f5b5eb921c Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 11:28:47 +0200 Subject: [PATCH 15/46] not needed --- .../hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 228b9c9dc7c8..74ac9026f862 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -69,7 +69,6 @@ class PlayerNameFormatter { } private fun formatAuthor(author: String): String { - if (!config.playerRankHider) return author if (author.contains("ADMIN")) return author if (config.ignoreYouTube && author.contains("YOUTUBER")) return author From 6f2aca130b3312d697838139ba05e983d4937a72 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 11:43:55 +0200 Subject: [PATCH 16/46] add private message support --- .../data/hypixel/chat/PlayerNameFormatter.kt | 13 ++++++++++++- .../java/at/hannibal2/skyhanni/utils/StringUtils.kt | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 74ac9026f862..cc79c9fc4f6c 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.data.hypixel.chat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerAllChatEvent +import at.hannibal2.skyhanni.data.hypixel.chat.event.PrivateMessageChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName @@ -35,7 +36,17 @@ class PlayerNameFormatter { val name = format(levelColor, level, author) val newMessage = "$name$chatColor: $message" - println("newMessage: '$newMessage'") + event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return + } + + @SubscribeEvent + fun onPrivateMessageChat(event: PrivateMessageChatEvent) { + val direction = event.direction + val message = event.message + val author = event.author + val name = format(null, null, author) + val newMessage = "§d$direction §f$name§7: §f$message" + event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 0ddefcf44aca..d3d93ffdbf18 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -127,6 +127,7 @@ object StringUtils { fun String.cleanPlayerName(displayName: Boolean = false): String { return if (displayName) { if (SkyHanniMod.feature.chat.playerMessage.playerRankHider) { + // TODO custom color "§b" + internalCleanPlayerName() } else this } else { @@ -333,10 +334,12 @@ object StringUtils { if (size > 1) { return null } - if (original.formattedText == newText) return null + + if (LorenzUtils.stripVanillaMessage(original.formattedText) == newText) return null println("replaceIfNeeded!") println("original: ${original.formattedText}") println("newText: $newText") + println(" ") val text = ChatComponentText(newText) if (size == 1) { From fdb938d8862a54fb3f8b15b68175862d439cad08 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 11:47:01 +0200 Subject: [PATCH 17/46] add todo --- src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index d3d93ffdbf18..d0040cff4916 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -336,6 +336,7 @@ object StringUtils { } if (LorenzUtils.stripVanillaMessage(original.formattedText) == newText) return null + // TODO remove debug println("replaceIfNeeded!") println("original: ${original.formattedText}") println("newText: $newText") From 0ca857750d1e31ef74d09e0d43e5711345807535 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 12:41:27 +0200 Subject: [PATCH 18/46] moving player chat symbols into PlayerNameFormatter --- .../java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 - .../config/features/chat/ChatConfig.java | 5 - .../config/features/chat/ChatSymbols.java | 54 --------- .../data/hypixel/chat/PlayerNameFormatter.kt | 16 ++- .../skyhanni/features/bingo/BingoAPI.kt | 9 ++ .../features/misc/PlayerChatSymbols.kt | 107 ----------------- .../misc/compacttablist/AdvancedPlayerList.kt | 113 ++++++++++-------- .../misc/compacttablist/TabListReader.kt | 1 - 8 files changed, 85 insertions(+), 222 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSymbols.java delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 08c651aafb4c..652edeadeb30 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -314,7 +314,6 @@ import at.hannibal2.skyhanni.features.misc.PatcherSendCoordinates import at.hannibal2.skyhanni.features.misc.PetCandyUsedDisplay import at.hannibal2.skyhanni.features.misc.PetExpTooltip import at.hannibal2.skyhanni.features.misc.PetItemDisplay -import at.hannibal2.skyhanni.features.misc.PlayerChatSymbols import at.hannibal2.skyhanni.features.misc.PocketSackInASackDisplay import at.hannibal2.skyhanni.features.misc.PrivateIslandNoPickaxeAbility import at.hannibal2.skyhanni.features.misc.QuickModMenuSwitch @@ -811,7 +810,6 @@ class SkyHanniMod { loadModule(DungeonRankTabListColor()) loadModule(TerracottaPhase()) loadModule(VolcanoExplosivityDisplay()) - loadModule(PlayerChatSymbols()) loadModule(FixNEUHeavyPearls()) loadModule(QuickCraftFeatures()) loadModule(SkyBlockKickDuration()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java index 72b21411b6fd..d65bbe006c59 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java @@ -30,11 +30,6 @@ public class ChatConfig { @Accordion public PlayerMessagesConfig playerMessage = new PlayerMessagesConfig(); - @Expose - @ConfigOption(name = "Player Chat Symbols", desc = "") - @Accordion - public ChatSymbols chatSymbols = new ChatSymbols(); - @Expose @ConfigOption(name = "Dungeon Filter", desc = "Hide specific message types in Dungeons.") @ConfigEditorDraggableList diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSymbols.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSymbols.java deleted file mode 100644 index ccead7f7b190..000000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatSymbols.java +++ /dev/null @@ -1,54 +0,0 @@ -package at.hannibal2.skyhanni.config.features.chat; - -import at.hannibal2.skyhanni.config.FeatureToggle; -import at.hannibal2.skyhanni.config.HasLegacyId; -import com.google.gson.annotations.Expose; -import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; -import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown; -import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; - -public class ChatSymbols { - - @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. " + - "§cDoes not work with hide rank hider!") - @ConfigEditorBoolean - @FeatureToggle - public boolean enabled = true; - - @Expose - @ConfigOption(name = "Chat Symbol Location", desc = "Determines where the symbols should go in chat in relation to the " + - "player's name. Hidden will hide all emblems from the chat. §eRequires above setting to be on to hide the symbols.") - @ConfigEditorDropdown - public SymbolLocationEntry symbolLocation = SymbolLocationEntry.LEFT; - - public enum SymbolLocationEntry implements HasLegacyId { - LEFT("Left", 0), - RIGHT("Right", 1), - HIDDEN("Hidden", 2); - - private final String str; - private final int legacyId; - - SymbolLocationEntry(String str, int legacyId) { - this.str = str; - this.legacyId = legacyId; - } - - // Constructor if new enum elements are added post-migration - SymbolLocationEntry(String str) { - this(str, -1); - } - - @Override - public int getLegacyId() { - return legacyId; - } - - @Override - public String toString() { - return str; - } - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index cc79c9fc4f6c..6010faf14f1c 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -3,6 +3,8 @@ package at.hannibal2.skyhanni.data.hypixel.chat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerAllChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PrivateMessageChatEvent +import at.hannibal2.skyhanni.features.bingo.BingoAPI +import at.hannibal2.skyhanni.features.misc.compacttablist.AdvancedPlayerList import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName @@ -61,10 +63,20 @@ class PlayerNameFormatter { cleanAuthor = group("author") } - val authorFormat = formatAuthor(cleanAuthor) + val name = formatAuthor(cleanAuthor) val levelFormat = formatLevel(levelColor, level) + + val cleanName = cleanAuthor.cleanPlayerName() + val (faction, ironman, bingo) = AdvancedPlayerList.tabPlayerData[cleanName]?.let { + val faction = it.faction.icon + val ironman = if (it.ironman) "§7♲" else "" + val bingo = it.bingoLevel?.let { level -> BingoAPI.getBingoIcon(level) } ?: "" + listOf(faction, ironman, bingo) + } ?: listOf("", "", "") + // TODO add chat format order options - return "$levelFormat$emblemFormat$authorFormat" +// return "$levelFormat$emblemFormat$name" + return "$levelFormat$emblemFormat$name$faction$ironman$bingo" } private fun formatLevel(rawColor: String?, rawLevel: Int?): String { diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt index f5361e09aa87..ccfd85ef74da 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt @@ -106,4 +106,13 @@ object BingoAPI { else -> "§c" } + LorenzUtils.formatPercentage(percentage) + + fun getBingoIcon(rank: Int): String { + val rankIcon = getIcon(rank) ?: "" + return if (rank != -1) { + "$rankIcon $rank" + } else { + rankIcon + } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt deleted file mode 100644 index 56c6b8bfe97d..000000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt +++ /dev/null @@ -1,107 +0,0 @@ -package at.hannibal2.skyhanni.features.misc - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.config.features.chat.ChatSymbols.SymbolLocationEntry -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.ConfigUtils -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 at.hannibal2.skyhanni.utils.repopatterns.RepoPattern -import net.minecraft.util.ChatComponentText -import net.minecraft.util.IChatComponent -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.chat.chatSymbols - private val nameSymbols = mutableMapOf() - - private val patternGroup = RepoPattern.group("misc.chatsymbols") - private val symbolsPattern by patternGroup.pattern( - "symbols", - "^(?(?:(?:§\\w)+\\S)+) " - ) - private val symbolPattern by patternGroup.pattern( - "symbol", - "(?:§.)+(\\S)" - ) - - @SubscribeEvent - fun onChat(event: LorenzChatEvent) { - if (!LorenzUtils.inSkyBlock) return - if (!config.enabled) return - - val username = event.message.getPlayerNameFromChatMessage() ?: return - - var usernameWithSymbols = TabListData.getTabList() - .find { playerName -> TabStringType.usernameFromLine(playerName) == username } - - if (usernameWithSymbols != null) { - nameSymbols[username] = usernameWithSymbols - } - - usernameWithSymbols = nameSymbols[username] ?: return - - val split = usernameWithSymbols.split("$username ") - var emblemText = if (split.size > 1) split[1].removeResets() else "" - - var matcher = symbolsPattern.matcher("$emblemText ") - emblemText = if (matcher.find()) { - matcher.group("symbols") - } else "" - - if (emblemText == "") { - return - } - - val emblems = mutableListOf() - 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, emblemText: String, rankAndName: String): Boolean { - if (component !is ChatComponentText) return false - component as AccessorChatComponentText - if (!component.text_skyhanni().contains(rankAndName)) return false - val oldText = component.text_skyhanni() - - val newText = getNewText(emblemText, oldText, rankAndName) - component.setText_skyhanni(component.text_skyhanni().replace(oldText, newText)) - return true - } - - private fun getNewText(emblemText: String, oldText: String, rankAndName: String): String = - when (config.symbolLocation) { - SymbolLocationEntry.LEFT -> oldText.replace(rankAndName, "$emblemText $rankAndName") - SymbolLocationEntry.RIGHT -> oldText.replace(rankAndName, "$rankAndName $emblemText ") - SymbolLocationEntry.HIDDEN -> oldText - else -> oldText - } - - @SubscribeEvent - fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.transform(15, "chat.chatSymbols.symbolLocation") { element -> - ConfigUtils.migrateIntToEnum(element, SymbolLocationEntry::class.java) - } - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt index 4bdcd4a3b536..8cd6b16b2c7d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt @@ -23,11 +23,14 @@ import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeLimitedCache import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Matcher import kotlin.random.Random import kotlin.time.Duration.Companion.minutes object AdvancedPlayerList { + val tabPlayerData = mutableMapOf() + private val config get() = SkyHanniMod.feature.gui.compactTabList.advancedPlayerList private val levelPattern by RepoPattern.pattern( @@ -62,55 +65,28 @@ object AdvancedPlayerList { extraTitles++ continue } - levelPattern.matchMatcher(line) { + val playerData: PlayerData? = levelPattern.matchMatcher(line) { val levelText = group("level") val removeColor = levelText.removeColor() try { - val playerData = PlayerData(removeColor.toInt()) - currentData[line] = playerData - - var index = 0 - val fullName = group("name") - if (fullName.contains("[")) index++ - val name = fullName.split(" ") - val coloredName = name[index] - if (index == 1) { - playerData.coloredName = name[0] + " " + coloredName - } else { - playerData.coloredName = coloredName - } - playerData.name = coloredName.removeColor() - playerData.levelText = levelText - index++ - if (name.size > index) { - var nameSuffix = name.drop(index).joinToString(" ") - if (nameSuffix.contains("♲")) { - playerData.ironman = true - } else { - playerData.bingoLevel = BingoAPI.getRank(line) - } - if (IslandType.CRIMSON_ISLE.isInIsland()) { - playerData.faction = if (line.contains("§c⚒")) { - nameSuffix = nameSuffix.replace("§c⚒", "") - CrimsonIsleFaction.BARBARIAN - } else if (line.contains("§5ቾ")) { - nameSuffix = nameSuffix.replace("§5ቾ", "") - CrimsonIsleFaction.MAGE - } else { - CrimsonIsleFaction.NONE - } - } - playerData.nameSuffix = nameSuffix - } else { - playerData.nameSuffix = "" - } + val sbLevel = removeColor.toInt() + readPlayerData(sbLevel, levelText, line) } catch (e: NumberFormatException) { - ErrorManager.logErrorWithData(e, "Advanced Player List failed to parse user name", + ErrorManager.logErrorWithData( + e, "Advanced Player List failed to parse user name", "line" to line, "i" to i, "original" to original, - ) + ) + null + } + } + playerData?.let { + val name = it.name + if (name != "?") { + tabPlayerData[name] = it } + currentData[line] = it } } playerDatas = currentData @@ -155,6 +131,50 @@ object AdvancedPlayerList { return newList } + private fun Matcher.readPlayerData( + sbLevel: Int, + levelText: String, + line: String, + ): PlayerData { + val playerData = PlayerData(sbLevel) + var index = 0 + val fullName = group("name") + if (fullName.contains("[")) index++ + val name = fullName.split(" ") + val coloredName = name[index] + if (index == 1) { + playerData.coloredName = name[0] + " " + coloredName + } else { + playerData.coloredName = coloredName + } + playerData.name = coloredName.removeColor() + playerData.levelText = levelText + index++ + if (name.size > index) { + var nameSuffix = name.drop(index).joinToString(" ") + if (nameSuffix.contains("♲")) { + playerData.ironman = true + } else { + playerData.bingoLevel = BingoAPI.getRank(line) + } + if (IslandType.CRIMSON_ISLE.isInIsland()) { + playerData.faction = if (line.contains("§c⚒")) { + nameSuffix = nameSuffix.replace("§c⚒", "") + CrimsonIsleFaction.BARBARIAN + } else if (line.contains("§5ቾ")) { + nameSuffix = nameSuffix.replace("§5ቾ", "") + CrimsonIsleFaction.MAGE + } else { + CrimsonIsleFaction.NONE + } + } + playerData.nameSuffix = nameSuffix + } else { + playerData.nameSuffix = "" + } + return playerData + } + fun ignoreCustomTabList(): Boolean { val denyKeyPressed = SkyHanniMod.feature.dev.debug.bypassAdvancedPlayerTabList.isKeyHeld() return denyKeyPressed || !SkyHanniDebugsAndTests.globalRender @@ -178,7 +198,7 @@ object AdvancedPlayerList { } else "" var suffix = if (config.hideEmblem) { - if (data.ironman) "§7♲" else data.bingoLevel?.let { getBingoIcon(it) } ?: "" + if (data.ironman) "§7♲" else data.bingoLevel?.let { BingoAPI.getBingoIcon(it) } ?: "" } else data.nameSuffix if (config.markSpecialPersons) { @@ -229,15 +249,6 @@ object AdvancedPlayerList { else -> "" } - private fun getBingoIcon(rank: Int): String { - val rankIcon = BingoAPI.getIcon(rank) ?: "" - return if (config.showBingoRankNumber && rank != -1) { - "$rankIcon $rank" - } else { - rankIcon - } - } - class PlayerData(val sbLevel: Int) { var name: String = "?" diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt index 9d21c7421955..18bdede44f09 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabListReader.kt @@ -59,7 +59,6 @@ object TabListReader { private fun updateTablistData(tablist: List? = null) { if (!LorenzUtils.inSkyBlock) return - if (!config.enabled.get()) return var tabLines = tablist ?: TabListData.getTabList() From c12a262414dea5e22d715d8f31cd71cf66254be5 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 12:44:08 +0200 Subject: [PATCH 19/46] add enabled check --- .../skyhanni/config/features/chat/PlayerMessagesConfig.java | 1 - .../skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java index 05d9bad89c9c..3aee816baf30 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java @@ -16,7 +16,6 @@ public class PlayerMessagesConfig { @Expose @ConfigOption(name = "Ignore YouTube", desc = "Do not remove the rank for YouTubers") @ConfigEditorBoolean - @FeatureToggle public boolean ignoreYouTube = false; @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 6010faf14f1c..ecac5a9805b5 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -30,6 +30,7 @@ class PlayerNameFormatter { @SubscribeEvent fun onPlayerAllChat(event: PlayerAllChatEvent) { + if (!isEnabled()) return val levelColor = event.levelColor val level = event.level val message = event.message @@ -43,6 +44,7 @@ class PlayerNameFormatter { @SubscribeEvent fun onPrivateMessageChat(event: PrivateMessageChatEvent) { + if (!isEnabled()) return val direction = event.direction val message = event.message val author = event.author @@ -97,4 +99,6 @@ class PlayerNameFormatter { return author.cleanPlayerName(displayName = true) } + + fun isEnabled() = LorenzUtils.inSkyBlock && (config.playerRankHider || config.chatFilter) } From a79654c29687bee162b37b97a9a8142a5a0ec887 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:09:17 +0200 Subject: [PATCH 20/46] add Message Order --- .../features/chat/PlayerMessagesConfig.java | 39 +++++++++++++++++++ .../data/hypixel/chat/PlayerNameFormatter.kt | 19 +++++++-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java index 3aee816baf30..3b17be1a286f 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java @@ -3,10 +3,49 @@ import at.hannibal2.skyhanni.config.FeatureToggle; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + public class PlayerMessagesConfig { + @Expose + @ConfigOption( + name = "Message Order", + desc = "Drag text to change the the message order for chat messages." + ) + @ConfigEditorDraggableList + public List messageOrder = new ArrayList<>(Arrays.asList( + ChatPart.SKYBLOCK_LEVEL, + ChatPart.NAME, + ChatPart.EMBLEM + )); + + public enum ChatPart { + SKYBLOCK_LEVEL("SkyBlock Level"), + EMBLEM("Emblem"), + NAME("Name"), + CRIMSON_FACTION("Crimson Faction"), + MODE_IRONMAN("Ironman Mode"), + BINGO_LEVEL("Bingo Level"), + EMPTY_CHAR("§7"), + ; + + private final String str; + + ChatPart(String str) { + this.str = str; + } + + @Override + public String toString() { + return str; + } + } + @Expose @ConfigOption(name = "Player Rank Hider", desc = "Hide player ranks in all chat messages.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index ecac5a9805b5..f3759365e66c 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.data.hypixel.chat import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.features.chat.PlayerMessagesConfig import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerAllChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PrivateMessageChatEvent import at.hannibal2.skyhanni.features.bingo.BingoAPI @@ -76,9 +77,21 @@ class PlayerNameFormatter { listOf(faction, ironman, bingo) } ?: listOf("", "", "") - // TODO add chat format order options -// return "$levelFormat$emblemFormat$name" - return "$levelFormat$emblemFormat$name$faction$ironman$bingo" + val map = mutableMapOf() + map[PlayerMessagesConfig.ChatPart.SKYBLOCK_LEVEL] = levelFormat + map[PlayerMessagesConfig.ChatPart.EMBLEM] = emblemFormat + map[PlayerMessagesConfig.ChatPart.NAME] = name + map[PlayerMessagesConfig.ChatPart.CRIMSON_FACTION] = faction + map[PlayerMessagesConfig.ChatPart.MODE_IRONMAN] = ironman + map[PlayerMessagesConfig.ChatPart.BINGO_LEVEL] = bingo + map[PlayerMessagesConfig.ChatPart.EMPTY_CHAR] = " " + + val result = StringBuilder() + for (part in config.messageOrder) { + result.append(map[part]) + } + return result.toString() + } private fun formatLevel(rawColor: String?, rawLevel: Int?): String { From b511229f7752cd728f39ea06ba5e92061c36890b Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:13:59 +0200 Subject: [PATCH 21/46] all players same color in chat --- .../config/features/chat/PlayerMessagesConfig.java | 6 ++++++ .../skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 4 ++-- .../features/chat/playerchat/PlayerChatModifier.kt | 8 -------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java index 3b17be1a286f..18bcf81c01cf 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java @@ -62,4 +62,10 @@ public String toString() { @ConfigEditorBoolean @FeatureToggle public boolean chatFilter = false; + + @Expose + @ConfigOption(name = "Same Chat Color", desc = "All players, also those with ranks, have the same, white chat color.") + @ConfigEditorBoolean + @FeatureToggle + public boolean sameChatColor = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index f3759365e66c..fa6b1f01424e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -73,7 +73,7 @@ class PlayerNameFormatter { val (faction, ironman, bingo) = AdvancedPlayerList.tabPlayerData[cleanName]?.let { val faction = it.faction.icon val ironman = if (it.ironman) "§7♲" else "" - val bingo = it.bingoLevel?.let { level -> BingoAPI.getBingoIcon(level) } ?: "" + val bingo = it.bingoLevel?.let { level -> BingoAPI.getBingoIcon(level) } ?: "" listOf(faction, ironman, bingo) } ?: listOf("", "", "") @@ -113,5 +113,5 @@ class PlayerNameFormatter { return author.cleanPlayerName(displayName = true) } - fun isEnabled() = LorenzUtils.inSkyBlock && (config.playerRankHider || config.chatFilter) + fun isEnabled() = LorenzUtils.inSkyBlock && (config.playerRankHider || config.chatFilter || config.sameChatColor) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt index 680e5168eafb..d4c85942492d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt @@ -3,10 +3,8 @@ package at.hannibal2.skyhanni.features.chat.playerchat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.data.hypixel.chat.event.SystemMessageEvent -import at.hannibal2.skyhanni.features.dungeon.DungeonMilestonesDisplay import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager import at.hannibal2.skyhanni.utils.StringUtils -import at.hannibal2.skyhanni.utils.StringUtils.matches import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class PlayerChatModifier { @@ -36,12 +34,6 @@ class PlayerChatModifier { } string = string.replace("§[7ab6]((?:\\w+){2,16})'s", "§b$1's") string = string.replace("§[7ab6]((?:\\w+){2,16}) (§.)", "§b$1 $2") - - // TODO remove workaround - if (!DungeonMilestonesDisplay.milestonePattern.matches(input)) { - // all players same color in chat - string = string.replace("§r§7: ", "§r§f: ") - } } if (config.chatFilter && string.contains("§r§f: ") && PlayerChatFilter.shouldChatFilter(string)) { From 310609dcab25aadc4117c009406b59982c7fe124 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:14:33 +0200 Subject: [PATCH 22/46] all players same color in chat --- .../hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index fa6b1f01424e..1effc5e2e1c3 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -36,7 +36,7 @@ class PlayerNameFormatter { val level = event.level val message = event.message val author = event.author - val chatColor = event.chatColor + val chatColor = if (config.sameChatColor) "§f" else event.chatColor val name = format(levelColor, level, author) val newMessage = "$name$chatColor: $message" From c1dfae206223355c4f361489cbae8fff3d9b5d80 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:19:37 +0200 Subject: [PATCH 23/46] add mark player support --- .../skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 5 ++++- .../features/chat/playerchat/PlayerChatModifier.kt | 7 +------ .../skyhanni/features/misc/MarkedPlayerManager.kt | 11 +++++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 1effc5e2e1c3..f5cafc051d06 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.features.chat.PlayerMessagesConfig import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerAllChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PrivateMessageChatEvent import at.hannibal2.skyhanni.features.bingo.BingoAPI +import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager import at.hannibal2.skyhanni.features.misc.compacttablist.AdvancedPlayerList import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils @@ -110,7 +111,9 @@ class PlayerNameFormatter { if (author.contains("ADMIN")) return author if (config.ignoreYouTube && author.contains("YOUTUBER")) return author - return author.cleanPlayerName(displayName = true) + val result = author.cleanPlayerName(displayName = true) + + return MarkedPlayerManager.replaceInChat(result) } fun isEnabled() = LorenzUtils.inSkyBlock && (config.playerRankHider || config.chatFilter || config.sameChatColor) diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt index d4c85942492d..09158ceba175 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt @@ -40,12 +40,7 @@ class PlayerChatModifier { string = string.replace("§r§f: ", "§r§7: ") } - if (MarkedPlayerManager.config.highlightInChat) { - val color = MarkedPlayerManager.config.chatColor.getChatColor() - for (markedPlayer in MarkedPlayerManager.playerNamesToMark) { - string = string.replace(markedPlayer, "$color$markedPlayer§r") - } - } + string = MarkedPlayerManager.replaceInChat(string) return string } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/MarkedPlayerManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/MarkedPlayerManager.kt index 0adf1d5ec9e5..5edabcbb1944 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/MarkedPlayerManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/MarkedPlayerManager.kt @@ -80,6 +80,17 @@ class MarkedPlayerManager { private fun isEnabled() = (LorenzUtils.inSkyBlock || OutsideSbFeature.MARKED_PLAYERS.isSelected()) && config.highlightInWorld + + fun replaceInChat(string: String): String { + if (!config.highlightInChat) return string + + val color = config.chatColor.getChatColor() + var text = string + for (markedPlayer in playerNamesToMark) { + text = text.replace(markedPlayer, "$color$markedPlayer§r") + } + return text + } } @SubscribeEvent From da6850395e3596d696ed6a0abe7ea8d36599f91f Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:31:39 +0200 Subject: [PATCH 24/46] move chat filter to new system --- .../skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 6 +++++- .../skyhanni/features/chat/playerchat/PlayerChatModifier.kt | 5 ----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index f5cafc051d06..05c1221eb844 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.features.chat.PlayerMessagesConfig import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerAllChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PrivateMessageChatEvent import at.hannibal2.skyhanni.features.bingo.BingoAPI +import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatFilter import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager import at.hannibal2.skyhanni.features.misc.compacttablist.AdvancedPlayerList import at.hannibal2.skyhanni.utils.LorenzUtils @@ -37,7 +38,10 @@ class PlayerNameFormatter { val level = event.level val message = event.message val author = event.author - val chatColor = if (config.sameChatColor) "§f" else event.chatColor + + val shouldFilter = config.chatFilter && PlayerChatFilter.shouldChatFilter(message) + val chatColor = if (shouldFilter) "§7" else if (config.sameChatColor) "§f" else event.chatColor + val name = format(levelColor, level, author) val newMessage = "$name$chatColor: $message" diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt index 09158ceba175..4aabeaf6c433 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt @@ -15,7 +15,6 @@ class PlayerChatModifier { init { patterns.add("§[ab6]\\[(?:VIP|MVP)(?:§.|\\+)*] {1,2}(?:§[7ab6])?(\\w{2,16})".toRegex()) // ranked player with prefix everywhere patterns.add("§[7ab6](\\w{2,16})§r(?!§7x)(?!\$)".toRegex()) // all players without rank prefix in notification messages -// patterns.add("(?:§7 )?§7(\\w{2,16})§7§r".toRegex()) // nons user chat } @SubscribeEvent @@ -36,10 +35,6 @@ class PlayerChatModifier { string = string.replace("§[7ab6]((?:\\w+){2,16}) (§.)", "§b$1 $2") } - if (config.chatFilter && string.contains("§r§f: ") && PlayerChatFilter.shouldChatFilter(string)) { - string = string.replace("§r§f: ", "§r§7: ") - } - string = MarkedPlayerManager.replaceInChat(string) return string From 33f7bec53d1abbaa8bb9761626c054ded06b80c7 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:03:45 +0200 Subject: [PATCH 25/46] fix bigger emblems --- .../hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 05c1221eb844..80e2b35626ef 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -28,7 +28,7 @@ class PlayerNameFormatter { */ private val emblemPattern by patternGroup.pattern( "emblem", - "(?§..) §r(?.*)" + "(?(§.)*.) §r(?.*)" ) @SubscribeEvent From eb036b9b5db48aad32251b52ba4ca8bacd4c0f78 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:14:39 +0200 Subject: [PATCH 26/46] add todos --- src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt | 1 + .../skyhanni/features/garden/visitor/GardenVisitorFeatures.kt | 1 + 2 files changed, 2 insertions(+) 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 4e02f89f3230..8e61f4b6cbd0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt @@ -31,6 +31,7 @@ class Translator { if (!isEnabled()) return val message = event.message + // TODO use PlayerAllChatEvent and other player chat events if (message.getPlayerNameFromChatMessage() == null) return val editedComponent = event.chatComponent.transformIf({ siblings.isNotEmpty() }) { siblings.last() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index 50779ac60edc..9ace68233674 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -462,6 +462,7 @@ object GardenVisitorFeatures { event.blockedReason = "new_visitor_arrived" } + // TODO use NpcChatEvent if (GardenAPI.inGarden() && config.hideChat && hideVisitorMessage(event.message)) { event.blockedReason = "garden_visitor_message" } From d1036413be6c9996e41d1fbc06e20e830546b1d1 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:28:09 +0200 Subject: [PATCH 27/46] small fixes --- .../skyhanni/data/hypixel/chat/PlayerChatManager.kt | 6 +++--- .../skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index e97acab08f66..e1228b3de812 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -46,9 +46,9 @@ class PlayerChatManager { ) /** - * REGEX-TEST: §9Party §8> §b§l⚛ §b[MVP§f+§b] Dankbarkeit§f: §rx: -190, y: 5, z: -163 - * REGEX-TEST: §9Party §8> §6⚔ §6[MVP§3++§6] RealBacklight§f: §r!warp - * REGEX-TEST: §9Party §8> §b[MVP§3+§b] Eisengolem§f: §r!pt + * REGEX-TEST: §2Guild > §b§l⚛ §b[MVP§f+§b] Dankbarkeit§f: §rx: -190, y: 5, z: -163 + * REGEX-TEST: §2Guild > §6⚔ §6[MVP§3++§6] RealBacklight§f: §r!warp + * REGEX-TEST: §2Guild > §b[MVP§3+§b] Eisengolem§f: §r!pt */ private val guildPattern by patternGroup.pattern( "guild", diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 80e2b35626ef..76350e1fef49 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -113,7 +113,7 @@ class PlayerNameFormatter { private fun formatAuthor(author: String): String { if (author.contains("ADMIN")) return author - if (config.ignoreYouTube && author.contains("YOUTUBER")) return author + if (config.ignoreYouTube && author.contains("YOUTUBE")) return author val result = author.cleanPlayerName(displayName = true) From 2051d60b917fe50366b4961dbf807066b375ed78 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:01:36 +0200 Subject: [PATCH 28/46] fix guild rank --- .../data/hypixel/chat/PlayerChatManager.kt | 29 ++++++++++++------- .../data/hypixel/chat/PlayerNameFormatter.kt | 13 +++++++++ .../data/hypixel/chat/event/GuildChatEvent.kt | 1 + 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index e1228b3de812..52f4c11af864 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -49,10 +49,11 @@ class PlayerChatManager { * REGEX-TEST: §2Guild > §b§l⚛ §b[MVP§f+§b] Dankbarkeit§f: §rx: -190, y: 5, z: -163 * REGEX-TEST: §2Guild > §6⚔ §6[MVP§3++§6] RealBacklight§f: §r!warp * REGEX-TEST: §2Guild > §b[MVP§3+§b] Eisengolem§f: §r!pt + * REGEX-TEST: §2Guild > §b[MVP§d+§b] zunoff §e[VET]§f: §rwas löuft */ private val guildPattern by patternGroup.pattern( "guild", - "§2Guild > (?[^:]*): (?.*)" + "§2Guild > (?§.+?)(? §e\\[\\w*])?§f: §r(?.*)" ) /** @@ -84,16 +85,21 @@ class PlayerChatManager { val chatComponent = event.chatComponent globalPattern.matchMatcher(event.message) { val author = group("author") - val message = LorenzUtils.stripVanillaMessage(group("message")) - if (author.contains("[NPC]")) { - NpcChatEvent(author, message.removePrefix("§f"), chatComponent).postChat(event) - } else { - val chatColor = group("chatColor") - val levelColor = groupOrNull("levelColor") - val level = groupOrNull("level")?.formatInt() - PlayerAllChatEvent(levelColor, level, author, chatColor, message, chatComponent).postChat(event) + // TODO move into regex + val isGuild = author.startsWith("§2Guild >") + val isParty = author.startsWith("§9Party") + if (!isGuild && !isParty) { + val message = LorenzUtils.stripVanillaMessage(group("message")) + if (author.contains("[NPC]")) { + NpcChatEvent(author, message.removePrefix("§f"), chatComponent).postChat(event) + } else { + val chatColor = group("chatColor") + val levelColor = groupOrNull("levelColor") + val level = groupOrNull("level")?.formatInt() + PlayerAllChatEvent(levelColor, level, author, chatColor, message, chatComponent).postChat(event) + } + return } - return } partyPattern.matchMatcher(event.message) { val author = group("author") @@ -104,7 +110,8 @@ class PlayerChatManager { guildPattern.matchMatcher(event.message) { val author = group("author") val message = group("message") - GuildChatEvent(author, message, chatComponent).postChat(event) + val guildRank = groupOrNull("guildRank") + GuildChatEvent(author, message, guildRank, chatComponent).postChat(event) return } privateMessagePattern.matchMatcher(event.message) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 76350e1fef49..a41f1f4e6a0e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.data.hypixel.chat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.features.chat.PlayerMessagesConfig +import at.hannibal2.skyhanni.data.hypixel.chat.event.GuildChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerAllChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PrivateMessageChatEvent import at.hannibal2.skyhanni.features.bingo.BingoAPI @@ -60,6 +61,18 @@ class PlayerNameFormatter { event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return } + @SubscribeEvent + fun onGuildChat(event: GuildChatEvent) { + if (!isEnabled()) return + val message = event.message + val author = event.author + val guildRank = event.guildRank ?: "" + val name = format(null, null, author) + val newMessage = "§2Guild > $name$guildRank§f: $message" + + event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return + } + fun format(levelColor: String?, level: Int?, author: String): String { var cleanAuthor = cleanAuthor(author) var emblemFormat = "" diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt index 9e453cdc5ca1..dd38671068a5 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/GuildChatEvent.kt @@ -5,6 +5,7 @@ import net.minecraft.util.IChatComponent class GuildChatEvent( author: String, message: String, + val guildRank: String? = null, chatComponent: IChatComponent, blockedReason: String? = null, ) : AbstractChatEvent(author, message, chatComponent, blockedReason) From d6d633d36f1aa4dec80389bfc778b08e7d05d712 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:11:22 +0200 Subject: [PATCH 29/46] dynamic guild rank position --- .../features/chat/PlayerMessagesConfig.java | 2 ++ .../data/hypixel/chat/PlayerNameFormatter.kt | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java index 18bcf81c01cf..9f2528575730 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java @@ -21,6 +21,7 @@ public class PlayerMessagesConfig { public List messageOrder = new ArrayList<>(Arrays.asList( ChatPart.SKYBLOCK_LEVEL, ChatPart.NAME, + ChatPart.GUILD_RANK, ChatPart.EMBLEM )); @@ -28,6 +29,7 @@ public enum ChatPart { SKYBLOCK_LEVEL("SkyBlock Level"), EMBLEM("Emblem"), NAME("Name"), + GUILD_RANK("Guild Rank"), CRIMSON_FACTION("Crimson Faction"), MODE_IRONMAN("Ironman Mode"), BINGO_LEVEL("Bingo Level"), diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index a41f1f4e6a0e..09888c8c162d 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -43,7 +43,7 @@ class PlayerNameFormatter { val shouldFilter = config.chatFilter && PlayerChatFilter.shouldChatFilter(message) val chatColor = if (shouldFilter) "§7" else if (config.sameChatColor) "§f" else event.chatColor - val name = format(levelColor, level, author) + val name = nameFormat(author, levelColor, level) val newMessage = "$name$chatColor: $message" event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return @@ -55,7 +55,7 @@ class PlayerNameFormatter { val direction = event.direction val message = event.message val author = event.author - val name = format(null, null, author) + val name = nameFormat(author) val newMessage = "§d$direction §f$name§7: §f$message" event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return @@ -66,14 +66,14 @@ class PlayerNameFormatter { if (!isEnabled()) return val message = event.message val author = event.author - val guildRank = event.guildRank ?: "" - val name = format(null, null, author) - val newMessage = "§2Guild > $name$guildRank§f: $message" + val guildRank = event.guildRank + val name = nameFormat(author, guildRank = guildRank) + val newMessage = "§2Guild > $name§f: $message" event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return } - fun format(levelColor: String?, level: Int?, author: String): String { + private fun nameFormat(author: String, levelColor: String? = null, level: Int? = null, guildRank: String? = null): String { var cleanAuthor = cleanAuthor(author) var emblemFormat = "" @@ -86,6 +86,7 @@ class PlayerNameFormatter { val name = formatAuthor(cleanAuthor) val levelFormat = formatLevel(levelColor, level) + val guildRankFormat = guildRank ?: "" val cleanName = cleanAuthor.cleanPlayerName() val (faction, ironman, bingo) = AdvancedPlayerList.tabPlayerData[cleanName]?.let { @@ -95,6 +96,7 @@ class PlayerNameFormatter { listOf(faction, ironman, bingo) } ?: listOf("", "", "") + val map = mutableMapOf() map[PlayerMessagesConfig.ChatPart.SKYBLOCK_LEVEL] = levelFormat map[PlayerMessagesConfig.ChatPart.EMBLEM] = emblemFormat @@ -103,6 +105,7 @@ class PlayerNameFormatter { map[PlayerMessagesConfig.ChatPart.MODE_IRONMAN] = ironman map[PlayerMessagesConfig.ChatPart.BINGO_LEVEL] = bingo map[PlayerMessagesConfig.ChatPart.EMPTY_CHAR] = " " + map[PlayerMessagesConfig.ChatPart.GUILD_RANK] = guildRankFormat val result = StringBuilder() for (part in config.messageOrder) { From 45e72a4dad9b0e17e6c5a13d905992c89001ea42 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:06:51 +0200 Subject: [PATCH 30/46] fix private island rank --- .../features/chat/PlayerMessagesConfig.java | 2 ++ .../data/hypixel/chat/PlayerChatManager.kt | 32 +++++++++++++++++-- .../data/hypixel/chat/PlayerNameFormatter.kt | 16 +++++++--- .../hypixel/chat/event/PlayerAllChatEvent.kt | 1 + 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java index 9f2528575730..cbd8f8195679 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java @@ -20,6 +20,7 @@ public class PlayerMessagesConfig { @ConfigEditorDraggableList public List messageOrder = new ArrayList<>(Arrays.asList( ChatPart.SKYBLOCK_LEVEL, + ChatPart.PRIVATE_ISLAND_RANK, ChatPart.NAME, ChatPart.GUILD_RANK, ChatPart.EMBLEM @@ -30,6 +31,7 @@ public enum ChatPart { EMBLEM("Emblem"), NAME("Name"), GUILD_RANK("Guild Rank"), + PRIVATE_ISLAND_RANK("Private Island Rank"), CRIMSON_FACTION("Crimson Faction"), MODE_IRONMAN("Ironman Mode"), BINGO_LEVEL("Bingo Level"), diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 52f4c11af864..004f93dcb176 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.data.hypixel.chat +import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.hypixel.chat.event.AbstractChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.GuildChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.NpcChatEvent @@ -11,6 +12,7 @@ import at.hannibal2.skyhanni.data.hypixel.chat.event.SystemMessageEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.groupOrNull +import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -80,11 +82,20 @@ class PlayerChatManager { "(?:§8\\[(?§.)(?\\d+)§8] )?(?.*)§f§7 (?is (?:holding|friends with a|wearing)|has) §r(?.*)" ) + /** + * REGEX-TEST: §c[Tiffany] §b[MVP§c+§b] hannibal2 + * REGEX-TEST: §b[MVP§c+§b] hannibal2 + */ + private val privateIslandRankPattern by patternGroup.pattern( + "privateislandgroup", + "(?§.\\[\\w+]) (?.*)" + ) + @SubscribeEvent fun onChat(event: LorenzChatEvent) { val chatComponent = event.chatComponent globalPattern.matchMatcher(event.message) { - val author = group("author") + var author = group("author") // TODO move into regex val isGuild = author.startsWith("§2Guild >") val isParty = author.startsWith("§9Party") @@ -93,10 +104,27 @@ class PlayerChatManager { if (author.contains("[NPC]")) { NpcChatEvent(author, message.removePrefix("§f"), chatComponent).postChat(event) } else { + + var privateIslandRank: String? = null + if (IslandType.PRIVATE_ISLAND.isInIsland() || IslandType.PRIVATE_ISLAND_GUEST.isInIsland()) { + privateIslandRankPattern.matchMatcher(author) { + privateIslandRank = group("privateIslandGroup") + author = group("author") + } + } + val chatColor = group("chatColor") val levelColor = groupOrNull("levelColor") val level = groupOrNull("level")?.formatInt() - PlayerAllChatEvent(levelColor, level, author, chatColor, message, chatComponent).postChat(event) + PlayerAllChatEvent( + levelColor = levelColor, + level = level, + privateIslandRank = privateIslandRank, + author = author, + chatColor = chatColor, + message = message, + chatComponent = chatComponent, + ).postChat(event) } return } diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 09888c8c162d..401768ee662b 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -39,11 +39,12 @@ class PlayerNameFormatter { val level = event.level val message = event.message val author = event.author + val privateIslandRank = event.privateIslandRank val shouldFilter = config.chatFilter && PlayerChatFilter.shouldChatFilter(message) val chatColor = if (shouldFilter) "§7" else if (config.sameChatColor) "§f" else event.chatColor - val name = nameFormat(author, levelColor, level) + val name = nameFormat(author, levelColor, level, privateIslandRank = privateIslandRank) val newMessage = "$name$chatColor: $message" event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return @@ -73,10 +74,16 @@ class PlayerNameFormatter { event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return } - private fun nameFormat(author: String, levelColor: String? = null, level: Int? = null, guildRank: String? = null): String { + private fun nameFormat( + author: String, + levelColor: String? = null, + level: Int? = null, + guildRank: String? = null, + privateIslandRank: String? = null, + ): String { var cleanAuthor = cleanAuthor(author) - var emblemFormat = "" + var emblemFormat = "" emblemPattern.matchMatcher(author) { val emblem = group("emblem") // TODO add emblem hider @@ -87,6 +94,7 @@ class PlayerNameFormatter { val name = formatAuthor(cleanAuthor) val levelFormat = formatLevel(levelColor, level) val guildRankFormat = guildRank ?: "" + val privateIslandRankFormat = privateIslandRank ?: "" val cleanName = cleanAuthor.cleanPlayerName() val (faction, ironman, bingo) = AdvancedPlayerList.tabPlayerData[cleanName]?.let { @@ -96,7 +104,6 @@ class PlayerNameFormatter { listOf(faction, ironman, bingo) } ?: listOf("", "", "") - val map = mutableMapOf() map[PlayerMessagesConfig.ChatPart.SKYBLOCK_LEVEL] = levelFormat map[PlayerMessagesConfig.ChatPart.EMBLEM] = emblemFormat @@ -106,6 +113,7 @@ class PlayerNameFormatter { map[PlayerMessagesConfig.ChatPart.BINGO_LEVEL] = bingo map[PlayerMessagesConfig.ChatPart.EMPTY_CHAR] = " " map[PlayerMessagesConfig.ChatPart.GUILD_RANK] = guildRankFormat + map[PlayerMessagesConfig.ChatPart.PRIVATE_ISLAND_RANK] = privateIslandRankFormat val result = StringBuilder() for (part in config.messageOrder) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt index ded937bc3c89..62ae7d1cacb5 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt @@ -5,6 +5,7 @@ import net.minecraft.util.IChatComponent class PlayerAllChatEvent( val levelColor: String?, val level: Int?, + val privateIslandRank: String? = null, author: String, val chatColor: String?, message: String, From c76477ec7b8e2d99e97050cf67033704b33a5576 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:10:51 +0200 Subject: [PATCH 31/46] party chat support --- .../data/hypixel/chat/PlayerChatManager.kt | 1 + .../data/hypixel/chat/PlayerNameFormatter.kt | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 004f93dcb176..7043ed895373 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -158,6 +158,7 @@ class PlayerChatManager { // for consistency val message = "§7$action §r$itemName" + // TODO PlayerShowItemChatEvent(levelColor, level, author, message, action, itemName, chatComponent).postChat(event) } diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 401768ee662b..67ff18c703d5 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.data.hypixel.chat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.features.chat.PlayerMessagesConfig import at.hannibal2.skyhanni.data.hypixel.chat.event.GuildChatEvent +import at.hannibal2.skyhanni.data.hypixel.chat.event.PartyChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerAllChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PrivateMessageChatEvent import at.hannibal2.skyhanni.features.bingo.BingoAPI @@ -74,6 +75,17 @@ class PlayerNameFormatter { event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return } + @SubscribeEvent + fun onPartyChat(event: PartyChatEvent) { + if (!isEnabled()) return + val message = event.message + val author = event.author + val name = nameFormat(author) + val newMessage = "§9Party §8> $name§f: $message" + + event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return + } + private fun nameFormat( author: String, levelColor: String? = null, @@ -115,12 +127,7 @@ class PlayerNameFormatter { map[PlayerMessagesConfig.ChatPart.GUILD_RANK] = guildRankFormat map[PlayerMessagesConfig.ChatPart.PRIVATE_ISLAND_RANK] = privateIslandRankFormat - val result = StringBuilder() - for (part in config.messageOrder) { - result.append(map[part]) - } - return result.toString() - + return config.messageOrder.map { map[it] }.joinToString(" ") } private fun formatLevel(rawColor: String?, rawLevel: Int?): String { From 2e3231aa60646dc3c0dbacbf28e248ec56777ebd Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:13:12 +0200 Subject: [PATCH 32/46] private message support --- .../skyhanni/data/hypixel/chat/PlayerChatManager.kt | 1 - .../data/hypixel/chat/PlayerNameFormatter.kt | 13 +++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 7043ed895373..004f93dcb176 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -158,7 +158,6 @@ class PlayerChatManager { // for consistency val message = "§7$action §r$itemName" - // TODO PlayerShowItemChatEvent(levelColor, level, author, message, action, itemName, chatComponent).postChat(event) } diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 67ff18c703d5..f40d408675ea 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.features.chat.PlayerMessagesConfig import at.hannibal2.skyhanni.data.hypixel.chat.event.GuildChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PartyChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerAllChatEvent +import at.hannibal2.skyhanni.data.hypixel.chat.event.PlayerShowItemChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PrivateMessageChatEvent import at.hannibal2.skyhanni.features.bingo.BingoAPI import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatFilter @@ -86,6 +87,18 @@ class PlayerNameFormatter { event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return } + @SubscribeEvent + fun onPlayerShowItemChat(event: PlayerShowItemChatEvent) { + if (!isEnabled()) return + val author = event.author + val action = event.action + val itemName = event.itemName + val name = nameFormat(author) + val newMessage = "$name §7$action §r$itemName" + + event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return + } + private fun nameFormat( author: String, levelColor: String? = null, From 3aed4950014565736af600c86986a99dab403e5e Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:16:09 +0200 Subject: [PATCH 33/46] move global chat check into own function --- .../data/hypixel/chat/PlayerChatManager.kt | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 004f93dcb176..934810a0ae83 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -18,6 +18,7 @@ import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Matcher class PlayerChatManager { @@ -95,39 +96,7 @@ class PlayerChatManager { fun onChat(event: LorenzChatEvent) { val chatComponent = event.chatComponent globalPattern.matchMatcher(event.message) { - var author = group("author") - // TODO move into regex - val isGuild = author.startsWith("§2Guild >") - val isParty = author.startsWith("§9Party") - if (!isGuild && !isParty) { - val message = LorenzUtils.stripVanillaMessage(group("message")) - if (author.contains("[NPC]")) { - NpcChatEvent(author, message.removePrefix("§f"), chatComponent).postChat(event) - } else { - - var privateIslandRank: String? = null - if (IslandType.PRIVATE_ISLAND.isInIsland() || IslandType.PRIVATE_ISLAND_GUEST.isInIsland()) { - privateIslandRankPattern.matchMatcher(author) { - privateIslandRank = group("privateIslandGroup") - author = group("author") - } - } - - val chatColor = group("chatColor") - val levelColor = groupOrNull("levelColor") - val level = groupOrNull("level")?.formatInt() - PlayerAllChatEvent( - levelColor = levelColor, - level = level, - privateIslandRank = privateIslandRank, - author = author, - chatColor = chatColor, - message = message, - chatComponent = chatComponent, - ).postChat(event) - } - return - } + if (isGlobalChat(event)) return } partyPattern.matchMatcher(event.message) { val author = group("author") @@ -164,6 +133,42 @@ class PlayerChatManager { sendSystemMessage(event) } + private fun Matcher.isGlobalChat(event: LorenzChatEvent): Boolean { + var author = group("author") + // TODO move into regex + val isGuild = author.startsWith("§2Guild >") + val isParty = author.startsWith("§9Party") + if (isGuild || isParty) return false + + val message = LorenzUtils.stripVanillaMessage(group("message")) + if (author.contains("[NPC]")) { + NpcChatEvent(author, message.removePrefix("§f"), event.chatComponent).postChat(event) + return true + } + + var privateIslandRank: String? = null + if (IslandType.PRIVATE_ISLAND.isInIsland() || IslandType.PRIVATE_ISLAND_GUEST.isInIsland()) { + privateIslandRankPattern.matchMatcher(author) { + privateIslandRank = group("privateIslandGroup") + author = group("author") + } + } + + val chatColor = group("chatColor") + val levelColor = groupOrNull("levelColor") + val level = groupOrNull("level")?.formatInt() + PlayerAllChatEvent( + levelColor = levelColor, + level = level, + privateIslandRank = privateIslandRank, + author = author, + chatColor = chatColor, + message = message, + chatComponent = event.chatComponent, + ).postChat(event) + return true + } + private fun sendSystemMessage(event: LorenzChatEvent) { with(SystemMessageEvent(event.message, event.chatComponent)) { val cancelled = postAndCatch() From 186fd0aa2dfd152fa06a722a8fce49c82dea23e4 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:17:18 +0200 Subject: [PATCH 34/46] same order everywhere --- .../skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index f40d408675ea..15f28bd853d8 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -53,13 +53,12 @@ class PlayerNameFormatter { } @SubscribeEvent - fun onPrivateMessageChat(event: PrivateMessageChatEvent) { + fun onPartyChat(event: PartyChatEvent) { if (!isEnabled()) return - val direction = event.direction val message = event.message val author = event.author val name = nameFormat(author) - val newMessage = "§d$direction §f$name§7: §f$message" + val newMessage = "§9Party §8> $name§f: $message" event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return } @@ -77,12 +76,13 @@ class PlayerNameFormatter { } @SubscribeEvent - fun onPartyChat(event: PartyChatEvent) { + fun onPrivateMessageChat(event: PrivateMessageChatEvent) { if (!isEnabled()) return + val direction = event.direction val message = event.message val author = event.author val name = nameFormat(author) - val newMessage = "§9Party §8> $name§f: $message" + val newMessage = "§d$direction §f$name§7: §f$message" event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return } From f3bb85a8eb9200292728cf50e7c1aa48f96aa576 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:19:05 +0200 Subject: [PATCH 35/46] add docs --- .../hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt | 3 +++ .../skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 934810a0ae83..903fef13d74d 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -20,6 +20,9 @@ import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Matcher +/** + * Reading normal chat events, and splitting them up into many different player chat events, with all avaliable extra information + */ class PlayerChatManager { private val patternGroup = RepoPattern.group("data.chat.player") diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 15f28bd853d8..d855fa762197 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -18,6 +18,10 @@ import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +/** + * Listening to the player chat events, and applying custom chat options to them. + * E.g. part order, rank hider, etc + */ class PlayerNameFormatter { private val config get() = SkyHanniMod.feature.chat.playerMessage From c6bf6cf3db74602e7960cbe311a854fc23b8011f Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:33:10 +0200 Subject: [PATCH 36/46] add options Hide Level Brackets and Level Color As Name --- .../features/chat/PlayerMessagesConfig.java | 30 ++++++++++----- .../AdvancedPlayerListConfig.java | 1 + .../data/hypixel/chat/PlayerNameFormatter.kt | 37 ++++++++++--------- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java index cbd8f8195679..0c5b67854663 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java @@ -14,19 +14,19 @@ public class PlayerMessagesConfig { @Expose @ConfigOption( - name = "Message Order", - desc = "Drag text to change the the message order for chat messages." + name = "Part Order", + desc = "Drag text to change the chat message format order for chat messages." ) @ConfigEditorDraggableList - public List messageOrder = new ArrayList<>(Arrays.asList( - ChatPart.SKYBLOCK_LEVEL, - ChatPart.PRIVATE_ISLAND_RANK, - ChatPart.NAME, - ChatPart.GUILD_RANK, - ChatPart.EMBLEM + public List partsOrder = new ArrayList<>(Arrays.asList( + MessagePart.SKYBLOCK_LEVEL, + MessagePart.PRIVATE_ISLAND_RANK, + MessagePart.NAME, + MessagePart.GUILD_RANK, + MessagePart.EMBLEM )); - public enum ChatPart { + public enum MessagePart { SKYBLOCK_LEVEL("SkyBlock Level"), EMBLEM("Emblem"), NAME("Name"), @@ -40,7 +40,7 @@ public enum ChatPart { private final String str; - ChatPart(String str) { + MessagePart(String str) { this.str = str; } @@ -50,6 +50,16 @@ public String toString() { } } + @Expose + @ConfigOption(name = "Hide Level Brackets", desc = "Hide the gray brackets in front of and behind the level numbers.") + @ConfigEditorBoolean + public boolean hideLevelBrackets = false; + + @Expose + @ConfigOption(name = "Level Color As Name", desc = "Use the color of the SkyBlock level for the player color.") + @ConfigEditorBoolean + public boolean useLevelColorForName = false; + @Expose @ConfigOption(name = "Player Rank Hider", desc = "Hide player ranks in all chat messages.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/AdvancedPlayerListConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/AdvancedPlayerListConfig.java index be8cfe3400e8..7f1be65ae9f0 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/AdvancedPlayerListConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/AdvancedPlayerListConfig.java @@ -95,6 +95,7 @@ public String toString() { @ConfigEditorBoolean public boolean markSpecialPersons = false; + @Expose @ConfigOption( name = "Mark SkyHanni Devs", diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index d855fa762197..5315d12cf213 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -115,12 +115,11 @@ class PlayerNameFormatter { var emblemFormat = "" emblemPattern.matchMatcher(author) { val emblem = group("emblem") - // TODO add emblem hider emblemFormat = "$emblem §r" cleanAuthor = group("author") } - val name = formatAuthor(cleanAuthor) + val name = formatAuthor(cleanAuthor, levelColor) val levelFormat = formatLevel(levelColor, level) val guildRankFormat = guildRank ?: "" val privateIslandRankFormat = privateIslandRank ?: "" @@ -133,25 +132,25 @@ class PlayerNameFormatter { listOf(faction, ironman, bingo) } ?: listOf("", "", "") - val map = mutableMapOf() - map[PlayerMessagesConfig.ChatPart.SKYBLOCK_LEVEL] = levelFormat - map[PlayerMessagesConfig.ChatPart.EMBLEM] = emblemFormat - map[PlayerMessagesConfig.ChatPart.NAME] = name - map[PlayerMessagesConfig.ChatPart.CRIMSON_FACTION] = faction - map[PlayerMessagesConfig.ChatPart.MODE_IRONMAN] = ironman - map[PlayerMessagesConfig.ChatPart.BINGO_LEVEL] = bingo - map[PlayerMessagesConfig.ChatPart.EMPTY_CHAR] = " " - map[PlayerMessagesConfig.ChatPart.GUILD_RANK] = guildRankFormat - map[PlayerMessagesConfig.ChatPart.PRIVATE_ISLAND_RANK] = privateIslandRankFormat - - return config.messageOrder.map { map[it] }.joinToString(" ") + val map = mutableMapOf() + map[PlayerMessagesConfig.MessagePart.SKYBLOCK_LEVEL] = levelFormat + map[PlayerMessagesConfig.MessagePart.EMBLEM] = emblemFormat + map[PlayerMessagesConfig.MessagePart.NAME] = name + map[PlayerMessagesConfig.MessagePart.CRIMSON_FACTION] = faction + map[PlayerMessagesConfig.MessagePart.MODE_IRONMAN] = ironman + map[PlayerMessagesConfig.MessagePart.BINGO_LEVEL] = bingo + map[PlayerMessagesConfig.MessagePart.EMPTY_CHAR] = " " + map[PlayerMessagesConfig.MessagePart.GUILD_RANK] = guildRankFormat + map[PlayerMessagesConfig.MessagePart.PRIVATE_ISLAND_RANK] = privateIslandRankFormat + + return config.partsOrder.map { map[it] }.joinToString(" ").replace(" ", " ").trim() } private fun formatLevel(rawColor: String?, rawLevel: Int?): String { val color = rawColor ?: return "" val level = rawLevel ?: error("level is null, color is not null") - // TODO add level formatting options - return "§8[§r$color$level§r§8] §r" + val levelData = "$color$level" + return if (config.hideLevelBrackets) levelData else "§8[${levelData}§8]" } private fun cleanAuthor(author: String): String { @@ -159,11 +158,13 @@ class PlayerNameFormatter { return text.removeSuffix("§f") } - private fun formatAuthor(author: String): String { + private fun formatAuthor(author: String, levelColor: String?): String { if (author.contains("ADMIN")) return author if (config.ignoreYouTube && author.contains("YOUTUBE")) return author - val result = author.cleanPlayerName(displayName = true) + val result = if (config.useLevelColorForName) { + levelColor + author.cleanPlayerName() + } else author.cleanPlayerName(displayName = true) return MarkedPlayerManager.replaceInChat(result) } From e14d67ae694f49df4970afa9fca9012723f33a92 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:51:52 +0200 Subject: [PATCH 37/46] code cleanup --- .../config/features/chat/PlayerMessagesConfig.java | 8 ++++---- .../misc/compacttablist/AdvancedPlayerListConfig.java | 1 - .../skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 2 +- .../features/misc/compacttablist/AdvancedPlayerList.kt | 1 + 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java index 0c5b67854663..e60cae5c5032 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java @@ -21,7 +21,7 @@ public class PlayerMessagesConfig { public List partsOrder = new ArrayList<>(Arrays.asList( MessagePart.SKYBLOCK_LEVEL, MessagePart.PRIVATE_ISLAND_RANK, - MessagePart.NAME, + MessagePart.PLAYER_NAME, MessagePart.GUILD_RANK, MessagePart.EMBLEM )); @@ -29,7 +29,7 @@ public class PlayerMessagesConfig { public enum MessagePart { SKYBLOCK_LEVEL("SkyBlock Level"), EMBLEM("Emblem"), - NAME("Name"), + PLAYER_NAME("Player Name"), GUILD_RANK("Guild Rank"), PRIVATE_ISLAND_RANK("Private Island Rank"), CRIMSON_FACTION("Crimson Faction"), @@ -67,7 +67,7 @@ public String toString() { public boolean playerRankHider = false; @Expose - @ConfigOption(name = "Ignore YouTube", desc = "Do not remove the rank for YouTubers") + @ConfigOption(name = "Ignore YouTube", desc = "Do not remove the rank for YouTubers in chat.") @ConfigEditorBoolean public boolean ignoreYouTube = false; @@ -78,7 +78,7 @@ public String toString() { public boolean chatFilter = false; @Expose - @ConfigOption(name = "Same Chat Color", desc = "All players, also those with ranks, have the same, white chat color.") + @ConfigOption(name = "Same Chat Color", desc = "All players, also those with ranks, write with the same, white chat color.") @ConfigEditorBoolean @FeatureToggle public boolean sameChatColor = true; diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/AdvancedPlayerListConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/AdvancedPlayerListConfig.java index 7f1be65ae9f0..be8cfe3400e8 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/AdvancedPlayerListConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/compacttablist/AdvancedPlayerListConfig.java @@ -95,7 +95,6 @@ public String toString() { @ConfigEditorBoolean public boolean markSpecialPersons = false; - @Expose @ConfigOption( name = "Mark SkyHanni Devs", diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 5315d12cf213..3766bb692a10 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -135,7 +135,7 @@ class PlayerNameFormatter { val map = mutableMapOf() map[PlayerMessagesConfig.MessagePart.SKYBLOCK_LEVEL] = levelFormat map[PlayerMessagesConfig.MessagePart.EMBLEM] = emblemFormat - map[PlayerMessagesConfig.MessagePart.NAME] = name + map[PlayerMessagesConfig.MessagePart.PLAYER_NAME] = name map[PlayerMessagesConfig.MessagePart.CRIMSON_FACTION] = faction map[PlayerMessagesConfig.MessagePart.MODE_IRONMAN] = ironman map[PlayerMessagesConfig.MessagePart.BINGO_LEVEL] = bingo diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt index 8cd6b16b2c7d..273942287625 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt @@ -188,6 +188,7 @@ object AdvancedPlayerList { } private fun createCustomName(data: PlayerData): String { + val playerName = if (config.useLevelColorForName) { val c = data.levelText[3] "§$c" + data.name From e54c8f48c69d4a8932ed23113e00f75ecbdda3a3 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 20:26:47 +0200 Subject: [PATCH 38/46] commented out debug code --- src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index d0040cff4916..89f6d4a6f405 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -337,10 +337,10 @@ object StringUtils { if (LorenzUtils.stripVanillaMessage(original.formattedText) == newText) return null // TODO remove debug - println("replaceIfNeeded!") - println("original: ${original.formattedText}") - println("newText: $newText") - println(" ") +// println("replaceIfNeeded!") +// println("original: ${original.formattedText}") +// println("newText: $newText") +// println(" ") val text = ChatComponentText(newText) if (size == 1) { From defdc57d7d5a26c7e1c8ef8a86fc4281c34d47d8 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 20:31:07 +0200 Subject: [PATCH 39/46] add todos --- .../at/hannibal2/skyhanni/config/features/chat/ChatConfig.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java index d65bbe006c59..f2d187687129 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java @@ -22,12 +22,14 @@ public class ChatConfig { @Expose @ConfigOption(name = "Chat Filter Types", desc = "") @Accordion + // TODO move into own sub category public FilterTypesConfig filterType = new FilterTypesConfig(); @Expose @ConfigOption(name = "Player Messages", desc = "") @Accordion + // TODO move into own sub category public PlayerMessagesConfig playerMessage = new PlayerMessagesConfig(); @Expose From 8c8a3720ec9762014bf795dc6ecd90f6073ff18a Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 22:51:53 +0200 Subject: [PATCH 40/46] fix private island rank with emblem problem --- .../skyhanni/data/hypixel/chat/PlayerChatManager.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 903fef13d74d..238690fbfa9e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -89,10 +89,11 @@ class PlayerChatManager { /** * REGEX-TEST: §c[Tiffany] §b[MVP§c+§b] hannibal2 * REGEX-TEST: §b[MVP§c+§b] hannibal2 + * REGEX-TEST: §6§l℻ §r§f[Gamer] §b[MVP§f+§b] SchrankLP§f§r */ private val privateIslandRankPattern by patternGroup.pattern( - "privateislandgroup", - "(?§.\\[\\w+]) (?.*)" + "privateislandrank", + ".*(?§.\\[\\w+]).*" ) @SubscribeEvent @@ -152,8 +153,9 @@ class PlayerChatManager { var privateIslandRank: String? = null if (IslandType.PRIVATE_ISLAND.isInIsland() || IslandType.PRIVATE_ISLAND_GUEST.isInIsland()) { privateIslandRankPattern.matchMatcher(author) { - privateIslandRank = group("privateIslandGroup") - author = group("author") + val rank = group("privateIslandRank") + privateIslandRank = rank + author = author.replace(rank, "") } } From 79fb364adcfcb1ebd9ef90e6d03a9fa040afa2ca Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 23:11:06 +0200 Subject: [PATCH 41/46] fix show item chat formatting --- .../skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 3766bb692a10..67f7876cde89 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -97,7 +97,9 @@ class PlayerNameFormatter { val author = event.author val action = event.action val itemName = event.itemName - val name = nameFormat(author) + val levelColor = event.levelColor + val level = event.level + val name = nameFormat(author, levelColor = levelColor, level = level) val newMessage = "$name §7$action §r$itemName" event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return @@ -114,8 +116,7 @@ class PlayerNameFormatter { var emblemFormat = "" emblemPattern.matchMatcher(author) { - val emblem = group("emblem") - emblemFormat = "$emblem §r" + emblemFormat = group("emblem") cleanAuthor = group("author") } @@ -162,7 +163,7 @@ class PlayerNameFormatter { if (author.contains("ADMIN")) return author if (config.ignoreYouTube && author.contains("YOUTUBE")) return author - val result = if (config.useLevelColorForName) { + val result = if (config.useLevelColorForName && levelColor != null) { levelColor + author.cleanPlayerName() } else author.cleanPlayerName(displayName = true) From 7d70dfa64f436283328ec632a72f4b288dfc47c5 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 Apr 2024 23:53:07 +0200 Subject: [PATCH 42/46] added Private Island Guest --- .../features/chat/PlayerMessagesConfig.java | 4 +++- .../data/hypixel/chat/PlayerChatManager.kt | 18 ++++++++++++++++++ .../data/hypixel/chat/PlayerNameFormatter.kt | 11 ++++++++--- .../hypixel/chat/event/PlayerAllChatEvent.kt | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java index e60cae5c5032..aa43d64fb02a 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java @@ -21,6 +21,7 @@ public class PlayerMessagesConfig { public List partsOrder = new ArrayList<>(Arrays.asList( MessagePart.SKYBLOCK_LEVEL, MessagePart.PRIVATE_ISLAND_RANK, + MessagePart.PRIVATE_ISLAND_GUEST, MessagePart.PLAYER_NAME, MessagePart.GUILD_RANK, MessagePart.EMBLEM @@ -29,9 +30,10 @@ public class PlayerMessagesConfig { public enum MessagePart { SKYBLOCK_LEVEL("SkyBlock Level"), EMBLEM("Emblem"), - PLAYER_NAME("Player Name"), + PLAYER_NAME("§bPlayer Name"), GUILD_RANK("Guild Rank"), PRIVATE_ISLAND_RANK("Private Island Rank"), + PRIVATE_ISLAND_GUEST("Private Island Guest"), CRIMSON_FACTION("Crimson Faction"), MODE_IRONMAN("Ironman Mode"), BINGO_LEVEL("Bingo Level"), diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt index 238690fbfa9e..2b3efb6aabe2 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -96,6 +96,17 @@ class PlayerChatManager { ".*(?§.\\[\\w+]).*" ) + /** + * REGEX-TEST: §8[§r§5396§r§8] §r§7☢ §r§a[✌] §b[MVP§c+§b] hannibal2§f: hey + * REGEX-TEST: §b[MVP§c+§b] hannibal2 + * REGEX-TEST: §6§l℻ §r§f[Gamer] §b[MVP§f+§b] SchrankLP§f§r + * REGEX-TEST: §7☢ §r§a[✌] §b[MVP§c+§b] hannibal2 + */ + private val prrivateIslandGuestPattern by patternGroup.pattern( + "privateislandguest", + ".*(?§r§a\\[✌]).*" + ) + @SubscribeEvent fun onChat(event: LorenzChatEvent) { val chatComponent = event.chatComponent @@ -151,12 +162,18 @@ class PlayerChatManager { } var privateIslandRank: String? = null + var isAGuest = false if (IslandType.PRIVATE_ISLAND.isInIsland() || IslandType.PRIVATE_ISLAND_GUEST.isInIsland()) { privateIslandRankPattern.matchMatcher(author) { val rank = group("privateIslandRank") privateIslandRank = rank author = author.replace(rank, "") } + prrivateIslandGuestPattern.matchMatcher(author) { + val guest = group("guest") + isAGuest = true + author = author.replace(guest, "") + } } val chatColor = group("chatColor") @@ -166,6 +183,7 @@ class PlayerChatManager { levelColor = levelColor, level = level, privateIslandRank = privateIslandRank, + isAGuest = isAGuest, author = author, chatColor = chatColor, message = message, diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 67f7876cde89..33358ce3fe89 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -32,10 +32,11 @@ class PlayerNameFormatter { * REGEX-TEST: §7☢ §r§b[MVP§d+§b] hannibal2 * REGEX-TEST: §7☢ §r§bhannibal2 * REGEX-TEST: §7☢ §rhannibal2 + * REGEX-TEST: §7☢ §b[MVP§c+§b] hannibal2 */ private val emblemPattern by patternGroup.pattern( "emblem", - "(?(§.)*.) §r(?.*)" + "(?(?:§.){1,2}.) (?.*)" ) @SubscribeEvent @@ -46,11 +47,12 @@ class PlayerNameFormatter { val message = event.message val author = event.author val privateIslandRank = event.privateIslandRank + val isAGuest = event.isAGuest val shouldFilter = config.chatFilter && PlayerChatFilter.shouldChatFilter(message) val chatColor = if (shouldFilter) "§7" else if (config.sameChatColor) "§f" else event.chatColor - val name = nameFormat(author, levelColor, level, privateIslandRank = privateIslandRank) + val name = nameFormat(author, levelColor, level, privateIslandRank = privateIslandRank, isAGuest = isAGuest) val newMessage = "$name$chatColor: $message" event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return @@ -111,19 +113,21 @@ class PlayerNameFormatter { level: Int? = null, guildRank: String? = null, privateIslandRank: String? = null, + isAGuest: Boolean = false ): String { var cleanAuthor = cleanAuthor(author) var emblemFormat = "" emblemPattern.matchMatcher(author) { emblemFormat = group("emblem") - cleanAuthor = group("author") + cleanAuthor = LorenzUtils.stripVanillaMessage(group("author")) } val name = formatAuthor(cleanAuthor, levelColor) val levelFormat = formatLevel(levelColor, level) val guildRankFormat = guildRank ?: "" val privateIslandRankFormat = privateIslandRank ?: "" + val privateIslandGuestFormat = if (isAGuest) "§a[✌]" else "" val cleanName = cleanAuthor.cleanPlayerName() val (faction, ironman, bingo) = AdvancedPlayerList.tabPlayerData[cleanName]?.let { @@ -143,6 +147,7 @@ class PlayerNameFormatter { map[PlayerMessagesConfig.MessagePart.EMPTY_CHAR] = " " map[PlayerMessagesConfig.MessagePart.GUILD_RANK] = guildRankFormat map[PlayerMessagesConfig.MessagePart.PRIVATE_ISLAND_RANK] = privateIslandRankFormat + map[PlayerMessagesConfig.MessagePart.PRIVATE_ISLAND_GUEST] = privateIslandGuestFormat return config.partsOrder.map { map[it] }.joinToString(" ").replace(" ", " ").trim() } diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt index 62ae7d1cacb5..56ea15a641d0 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt @@ -6,6 +6,7 @@ class PlayerAllChatEvent( val levelColor: String?, val level: Int?, val privateIslandRank: String? = null, + val isAGuest: Boolean, author: String, val chatColor: String?, message: String, From e5fd906bff87b44790c380e1b475b8e46fadc060 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 19 Apr 2024 09:54:46 +0200 Subject: [PATCH 43/46] fixed empty line error --- .../config/features/chat/PlayerMessagesConfig.java | 1 - .../skyhanni/data/hypixel/chat/PlayerNameFormatter.kt | 4 ++-- .../java/at/hannibal2/skyhanni/utils/StringUtils.kt | 11 +++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java index aa43d64fb02a..a8903f4f18f6 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java @@ -37,7 +37,6 @@ public enum MessagePart { CRIMSON_FACTION("Crimson Faction"), MODE_IRONMAN("Ironman Mode"), BINGO_LEVEL("Bingo Level"), - EMPTY_CHAR("§7"), ; private final String str; diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 33358ce3fe89..2032e4ae3861 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -15,6 +15,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.replaceAll import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -144,12 +145,11 @@ class PlayerNameFormatter { map[PlayerMessagesConfig.MessagePart.CRIMSON_FACTION] = faction map[PlayerMessagesConfig.MessagePart.MODE_IRONMAN] = ironman map[PlayerMessagesConfig.MessagePart.BINGO_LEVEL] = bingo - map[PlayerMessagesConfig.MessagePart.EMPTY_CHAR] = " " map[PlayerMessagesConfig.MessagePart.GUILD_RANK] = guildRankFormat map[PlayerMessagesConfig.MessagePart.PRIVATE_ISLAND_RANK] = privateIslandRankFormat map[PlayerMessagesConfig.MessagePart.PRIVATE_ISLAND_GUEST] = privateIslandGuestFormat - return config.partsOrder.map { map[it] }.joinToString(" ").replace(" ", " ").trim() + return config.partsOrder.map { map[it] }.joinToString(" ").replaceAll(" ", " ").trim() } private fun formatLevel(rawColor: String?, rawLevel: Int?): String { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 89f6d4a6f405..c246ea68043f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -361,4 +361,15 @@ object StringUtils { foundCommands.add(message) } } + + fun String.replaceAll(oldValue: String, newValue: String): String { + var text = this + while (true) { + val newText = text.replace(oldValue, newValue) + if (newText == text) { + return text + } + text = newText + } + } } From 77888368d44733dd62f40b0c95f86987b82046cf Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 19 Apr 2024 10:04:54 +0200 Subject: [PATCH 44/46] fix crash --- .../skyhanni/config/ConfigUpdaterMigrator.kt | 2 +- .../data/hypixel/chat/PlayerNameFormatter.kt | 18 ++++++++++++++++++ .../at/hannibal2/skyhanni/utils/StringUtils.kt | 4 ++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index 9f0b281ffc9d..1e8a576e2d63 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = LorenzLogger("ConfigMigration") - const val CONFIG_VERSION = 40 + const val CONFIG_VERSION = 41 fun JsonElement.at(chain: List, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index 2032e4ae3861..f7d660dd3de0 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.data.hypixel.chat import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.config.features.chat.PlayerMessagesConfig import at.hannibal2.skyhanni.data.hypixel.chat.event.GuildChatEvent import at.hannibal2.skyhanni.data.hypixel.chat.event.PartyChatEvent @@ -17,6 +18,8 @@ import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.replaceAll import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import com.google.gson.JsonArray +import com.google.gson.JsonNull import net.minecraftforge.fml.common.eventhandler.SubscribeEvent /** @@ -176,4 +179,19 @@ class PlayerNameFormatter { } fun isEnabled() = LorenzUtils.inSkyBlock && (config.playerRankHider || config.chatFilter || config.sameChatColor) + + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.transform(41, "chat.PlayerMessagesConfig.partsOrder") { element -> + val newList = JsonArray() + for (entry in element.asJsonArray) { + if (entry is JsonNull) continue + if (entry.asString != "EMPTY_CHAR") { + newList.add(entry) + } + } + newList + } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index c246ea68043f..68c92f7a7e23 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -362,10 +362,10 @@ object StringUtils { } } - fun String.replaceAll(oldValue: String, newValue: String): String { + fun String.replaceAll(oldValue: String, newValue: String, ignoreCase: Boolean = false): String { var text = this while (true) { - val newText = text.replace(oldValue, newValue) + val newText = text.replace(oldValue, newValue, ignoreCase = ignoreCase) if (newText == text) { return text } From 49420a50355300625b5356c160bcf98c1d8ba052 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 19 Apr 2024 10:25:00 +0200 Subject: [PATCH 45/46] do not remove rank if only selecting use level color for name --- .../data/hypixel/chat/PlayerNameFormatter.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt index f7d660dd3de0..4463270b38c7 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -117,7 +117,7 @@ class PlayerNameFormatter { level: Int? = null, guildRank: String? = null, privateIslandRank: String? = null, - isAGuest: Boolean = false + isAGuest: Boolean = false, ): String { var cleanAuthor = cleanAuthor(author) @@ -171,16 +171,19 @@ class PlayerNameFormatter { if (author.contains("ADMIN")) return author if (config.ignoreYouTube && author.contains("YOUTUBE")) return author - val result = if (config.useLevelColorForName && levelColor != null) { - levelColor + author.cleanPlayerName() - } else author.cleanPlayerName(displayName = true) + var result = author.cleanPlayerName(displayName = true) + levelColor?.let { + if (config.useLevelColorForName) { + val cleanPlayerName = author.cleanPlayerName() + result = result.replace(cleanPlayerName, it + cleanPlayerName) + } + } return MarkedPlayerManager.replaceInChat(result) } fun isEnabled() = LorenzUtils.inSkyBlock && (config.playerRankHider || config.chatFilter || config.sameChatColor) - @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.transform(41, "chat.PlayerMessagesConfig.partsOrder") { element -> From 42074ca56715ff675c76d7b8c10cbb6504b4f6d0 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Fri, 19 Apr 2024 11:00:25 +0200 Subject: [PATCH 46/46] Update src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt index 239305caf466..3bd3967be528 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt @@ -104,7 +104,7 @@ object PartyAPI { } @SubscribeEvent - fun onPartyCommand(event: PartyChatEvent) { + fun onPartyChat(event: PartyChatEvent) { val name = event.author.cleanPlayerName() addPlayer(name) }