diff options
| author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-04-19 11:24:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-19 11:24:36 +0200 |
| commit | f8efe9effd27bee18bced64385fc1ad9b05b68bd (patch) | |
| tree | 1429920226fc79af8bae814bb7596b9e65e0cf7e /src | |
| parent | 7feb5c67fbc1c9f63118952f1bea649ada1dccd6 (diff) | |
| download | skyhanni-f8efe9effd27bee18bced64385fc1ad9b05b68bd.tar.gz skyhanni-f8efe9effd27bee18bced64385fc1ad9b05b68bd.tar.bz2 skyhanni-f8efe9effd27bee18bced64385fc1ad9b05b68bd.zip | |
Feature + Fix: Player Chat Rework (#1483)
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src')
27 files changed, 737 insertions, 302 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index c23149967..a91d6bcad 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 @@ -319,7 +321,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 @@ -465,6 +466,8 @@ class SkyHanniMod { // data loadModule(this) loadModule(ChatManager) + loadModule(PlayerChatManager()) + loadModule(PlayerNameFormatter()) loadModule(HypixelData()) loadModule(LocationFixData) loadModule(DungeonAPI) @@ -821,7 +824,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/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index 9f0b281ff..1e8a576e2 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<String>, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null 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 72b21411b..f2d187687 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,20 +22,17 @@ 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 - @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 public List<DungeonMessageTypes> dungeonFilteredMessageTypes = new ArrayList<>(); 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 ccead7f7b..000000000 --- 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/config/features/chat/PlayerMessagesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/PlayerMessagesConfig.java index 5ebad3d0c..a8903f4f1 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,19 +3,84 @@ package at.hannibal2.skyhanni.config.features.chat; 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 = "Part Order", + desc = "Drag text to change the chat message format order for chat messages." + ) + @ConfigEditorDraggableList + public List<MessagePart> partsOrder = new ArrayList<>(Arrays.asList( + MessagePart.SKYBLOCK_LEVEL, + MessagePart.PRIVATE_ISLAND_RANK, + MessagePart.PRIVATE_ISLAND_GUEST, + MessagePart.PLAYER_NAME, + MessagePart.GUILD_RANK, + MessagePart.EMBLEM + )); + + public enum MessagePart { + SKYBLOCK_LEVEL("SkyBlock Level"), + EMBLEM("Emblem"), + 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"), + ; + + private final String str; + + MessagePart(String str) { + this.str = str; + } + + @Override + public String toString() { + return str; + } + } + + @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 @FeatureToggle public boolean playerRankHider = false; @Expose + @ConfigOption(name = "Ignore YouTube", desc = "Do not remove the rank for YouTubers in chat.") + @ConfigEditorBoolean + 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 @FeatureToggle public boolean chatFilter = false; + + @Expose + @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/data/PartyAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt index 44a778292..3bd3967be 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.event.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> (?<name>.*?) §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> (?<name>[^:]*): §r(?<message>.*)" - ) - val partyMembers = mutableListOf<String>() var partyLeader: String? = null @@ -114,16 +104,15 @@ object PartyAPI { } @SubscribeEvent + fun onPartyChat(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/PlayerChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt new file mode 100644 index 000000000..2b3efb6aa --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerChatManager.kt @@ -0,0 +1,220 @@ +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 +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 +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 +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") + + /** + * 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(?<levelColor>§.)(?<level>\\d+)§r§8] §r)?(?<author>§.+)(?<chatColor>§f|§7§r§7): (?<message>.*)" + ) + + /** + * 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> (?<author>[^:]*): §r(?<message>.*)" + ) + + /** + * 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 > (?<author>§.+?)(?<guildRank> §e\\[\\w*])?§f: §r(?<message>.*)" + ) + + /** + * 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( + "privatemessage", + "§d(?<direction>From|To) §r(?<author>[^:]*)§7: §r(?<message>.*)" + ) + + /** + * 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( + "itemshow", + "(?:§8\\[(?<levelColor>§.)(?<level>\\d+)§8] )?(?<author>.*)§f§7 (?<action>is (?:holding|friends with a|wearing)|has) §r(?<itemName>.*)" + ) + + /** + * 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( + "privateislandrank", + ".*(?<privateIslandRank>§.\\[\\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", + ".*(?<guest>§r§a\\[✌]).*" + ) + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + val chatComponent = event.chatComponent + globalPattern.matchMatcher(event.message) { + if (isGlobalChat(event)) return + } + partyPattern.matchMatcher(event.message) { + val author = group("author") + val message = group("message") + PartyChatEvent(author, message, chatComponent).postChat(event) + return + } + guildPattern.matchMatcher(event.message) { + val author = group("author") + val message = group("message") + val guildRank = groupOrNull("guildRank") + GuildChatEvent(author, message, guildRank, chatComponent).postChat(event) + return + } + privateMessagePattern.matchMatcher(event.message) { + val direction = group("direction") + val author = group("author") + val message = group("message") + 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) + } + + 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 + 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") + val levelColor = groupOrNull("levelColor") + val level = groupOrNull("level")?.formatInt() + PlayerAllChatEvent( + levelColor = levelColor, + level = level, + privateIslandRank = privateIslandRank, + isAGuest = isAGuest, + 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() + event.handleChat(cancelled, blockedReason, chatComponent) + } + } + + private fun AbstractChatEvent.postChat(event: LorenzChatEvent) { + val cancelled = postAndCatch() + event.handleChat(cancelled, blockedReason, chatComponent) + } + + private fun LorenzChatEvent.handleChat( + cancelled: Boolean, + blockedReason: String?, + chatComponent: IChatComponent, + ) { + if (cancelled) { + this.cancel() + } + blockedReason?.let { + this.blockedReason = it + } + this.chatComponent = chatComponent + } +} 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 000000000..4463270b3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/PlayerNameFormatter.kt @@ -0,0 +1,200 @@ +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 +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 +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 +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 + +/** + * 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 + + 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 + * REGEX-TEST: §7☢ §b[MVP§c+§b] hannibal2 + */ + private val emblemPattern by patternGroup.pattern( + "emblem", + "(?<emblem>(?:§.){1,2}.) (?<author>.*)" + ) + + @SubscribeEvent + fun onPlayerAllChat(event: PlayerAllChatEvent) { + if (!isEnabled()) return + val levelColor = event.levelColor + val level = event.level + 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, isAGuest = isAGuest) + val newMessage = "$name$chatColor: $message" + + 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 + } + + @SubscribeEvent + fun onGuildChat(event: GuildChatEvent) { + if (!isEnabled()) return + val message = event.message + val author = event.author + val guildRank = event.guildRank + val name = nameFormat(author, guildRank = guildRank) + val newMessage = "§2Guild > $name§f: $message" + + event.chatComponent = StringUtils.replaceIfNeeded(event.chatComponent, newMessage) ?: return + } + + @SubscribeEvent + 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 = "§d$direction §f$name§7: §f$message" + + 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 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 + } + + private fun nameFormat( + author: String, + levelColor: String? = null, + 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 = LorenzUtils.stripVanillaMessage(group("author")) + } + + val name = formatAuthor(cleanAuthor, levelColor) + val levelFormat = formatLevel(levelColor, level) + val guildRankFormat = guildRank ?: "" + val privateIslandRankFormat = privateIslandRank ?: "" |
