diff options
Diffstat (limited to 'src')
12 files changed, 147 insertions, 511 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index de9d1c2e0..a20ce7bc0 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -13,7 +13,7 @@ import at.hannibal2.skyhanni.features.bazaar.BazaarOrderHelper; import at.hannibal2.skyhanni.features.chat.ChatFilter; import at.hannibal2.skyhanni.features.chat.PlayerDeathMessages; import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatFilter; -import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatFormatter; +import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatModifier; import at.hannibal2.skyhanni.features.commands.WikiCommand; import at.hannibal2.skyhanni.features.damageindicator.DamageIndicatorManager; import at.hannibal2.skyhanni.features.dungeon.*; @@ -61,7 +61,7 @@ import java.util.List; public class SkyHanniMod { public static final String MODID = "skyhanni"; - public static final String VERSION = "0.12.2"; + public static final String VERSION = "0.13"; public static Features feature; @@ -101,7 +101,7 @@ public class SkyHanniMod { //features registerEvent(new BazaarOrderHelper()); registerEvent(new ChatFilter()); - registerEvent(new PlayerChatFormatter()); + registerEvent(new PlayerChatModifier()); registerEvent(new DungeonChatFilter()); registerEvent(new HideNotClickableItems()); registerEvent(new ItemDisplayOverlayFeatures()); diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index 4674e6cf1..0f7f0fd6c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -10,7 +10,6 @@ import at.hannibal2.skyhanni.config.core.config.gui.GuiPositionEditor; import at.hannibal2.skyhanni.config.features.*; import at.hannibal2.skyhanni.features.HideArmor; import at.hannibal2.skyhanni.features.MarkedPlayerManager; -import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatFormatter; import com.google.gson.annotations.Expose; import net.minecraft.client.Minecraft; @@ -88,16 +87,6 @@ public class Features extends Config { return; } - if (runnableId.equals("testAllChat")) { - PlayerChatFormatter.Companion.testAllChat(); - return; - } - - if (runnableId.equals("testGuildChat")) { - PlayerChatFormatter.Companion.testGuildChat(); - return; - } - if (runnableId.equals("markOwnPlayer")) { MarkedPlayerManager.Companion.toggleOwn(); return; diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java b/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java index e12d96f57..c7af12866 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java @@ -53,92 +53,13 @@ public class Chat { public boolean playerMessages = false; @Expose - @ConfigOption(name = "Message Format", desc = "") - @ConfigAccordionId(id = 1) - @ConfigEditorAccordion(id = 2) - public boolean messageFormat = false; - - @Expose - @ConfigOption(name = "All Channel Prefix", desc = "Show the prefix for the all channel chat.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 2) - public boolean allChannelPrefix = false; - - @Expose - @ConfigOption(name = "Player Rank Hider", desc = "Hide player ranks in the chat.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 2) - public boolean playerRankHider = false; - - @Expose - @ConfigOption(name = "Player Colon Hider", desc = "Hide the colon after the player name in the chat.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 2) - public boolean playerColonHider = false; - - @Expose - @ConfigOption( - name = "SkyBlock Level Design", - desc = "Change the design of the Skyblock Level in the chat.\n" + - "§cRequires 'SkyBlock Level in Chat' enabled in the SkyBlock Menu." - ) - @ConfigEditorDropdown( - values = {"§8[§6123§8] §bname§f: msg", - "§6§l123 §bname§f: §fmsg", - "§bname §8[§6123§8]§f: msg", - "§cHide SkyBlock Level"} - ) - @ConfigAccordionId(id = 2) - public int skyblockLevelDesign = 0; - - @Expose - @ConfigOption( - name = "Elite Design", - desc = "Change the design of the Elite position in the chat." - ) - @ConfigEditorDropdown( - values = {"§6[⌬499]", - "§6§l⌬499", - "§cHide Elite Position"} - ) - @ConfigAccordionId(id = 2) - public int eliteFormat = 0; - - @Expose - @ConfigOption( - name = "Channel Design", - desc = "Change the design of the Channel Prefix in the chat." - ) - @ConfigEditorDropdown( - values = {"§2Guild >", - "§2G>", - "§8<§2G§8>", - "§8[§2G§8]", - "§8(§2G§8)"} - ) - @ConfigAccordionId(id = 2) - public int channelDesign = 0; - - @Expose - @ConfigOption(name = "Test All Chat", desc = "Test the All Chat message format locally (no message gets sent to hypixel)") - @ConfigEditorButton(runnableId = "testAllChat") - @ConfigAccordionId(id = 2) - public boolean testAllChat = false; - - @Expose - @ConfigOption(name = "Test Guild Chat", desc = "Test the Guild Chat message format locally (no message gets sent to hypixel)") - @ConfigEditorButton(runnableId = "testGuildChat") - @ConfigAccordionId(id = 2) - public boolean testGuildChat = false; - - @Expose - @ConfigOption(name = "NEU Profile Viewer", desc = "Click on a player name to open the Profile Viewer from NotEnoughUpdates") + @ConfigOption(name = "Player Rank Hider", desc = "Hide player ranks in all chat messages.") @ConfigEditorBoolean @ConfigAccordionId(id = 1) - public boolean neuProfileViewer = false; + public boolean playerRankHider = true; @Expose - @ConfigOption(name = "Chat Filter", desc = "Scan messages sent by players in all-chat for blacklisted words and greys out the message") + @ConfigOption(name = "Chat Filter", desc = "Scan messages sent by players for blacklisted words and grey out the message if any are found.") @ConfigEditorBoolean @ConfigAccordionId(id = 1) public boolean chatFilter = false; diff --git a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt index 39459fe83..de0cafead 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt @@ -12,9 +12,10 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class ChatManager { - private val loggerAll = LorenzLogger("chat/filter_all") - private val loggerFiltered = LorenzLogger("chat/filter_blocked") - private val loggerAllowed = LorenzLogger("chat/filter_allowed") + private val loggerAll = LorenzLogger("chat/all") + private val loggerFiltered = LorenzLogger("chat/blocked") + private val loggerAllowed = LorenzLogger("chat/allowed") + private val loggerModified = LorenzLogger("chat/modified") private val loggerFilteredTypes = mutableMapOf<String, LorenzLogger>() @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) @@ -34,10 +35,12 @@ class ChatManager { fun onChatReceive(event: ClientChatReceivedEvent) { if (event.type.toInt() == 2) return - val messageComponent = event.message - val message = LorenzUtils.stripVanillaMessage(messageComponent.formattedText) + val original = event.message + val message = LorenzUtils.stripVanillaMessage(original.formattedText) + + if (message.startsWith("§f{\"server\":\"")) return - val chatEvent = LorenzChatEvent(message, messageComponent) + val chatEvent = LorenzChatEvent(message, original) chatEvent.postAndCatch() val blockReason = chatEvent.blockedReason.uppercase() @@ -50,9 +53,16 @@ class ChatManager { return } - if (!message.startsWith("§f{\"server\":\"")) { + val modified = chatEvent.chatComponent + if (modified.formattedText == original.formattedText) { loggerAllowed.log(message) loggerAll.log("[allowed] $message") + } else { + event.message = chatEvent.chatComponent + loggerModified.log(" ") + loggerModified.log("[original] " + original.formattedText) + loggerModified.log("[modified] " + modified.formattedText) + loggerAll.log("[modified] " + modified.formattedText) } } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzChatEvent.kt index 2c7db6bd7..891ab340c 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/LorenzChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzChatEvent.kt @@ -2,4 +2,4 @@ package at.hannibal2.skyhanni.events import net.minecraft.util.IChatComponent -class LorenzChatEvent(val message: String, val chatComponent: IChatComponent, var blockedReason: String = "") : LorenzEvent()
\ No newline at end of file +class LorenzChatEvent(val message: String, var chatComponent: IChatComponent, var blockedReason: String = "") : LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/PlayerSendChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/PlayerSendChatEvent.kt deleted file mode 100644 index 12b9300e4..000000000 --- a/src/main/java/at/hannibal2/skyhanni/events/PlayerSendChatEvent.kt +++ /dev/null @@ -1,12 +0,0 @@ -package at.hannibal2.skyhanni.events - -import at.hannibal2.skyhanni.features.chat.playerchat.PlayerMessageChannel -import net.minecraft.util.ChatComponentText - -class PlayerSendChatEvent( - val channel: PlayerMessageChannel, - val name: String, - val message: String, - val chatComponents: MutableList<ChatComponentText>, - var cancelledReason: String = "", -) : LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/MarkedPlayerManager.kt b/src/main/java/at/hannibal2/skyhanni/features/MarkedPlayerManager.kt index b1c1ac4e8..17ebec137 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/MarkedPlayerManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/MarkedPlayerManager.kt @@ -1,7 +1,6 @@ package at.hannibal2.skyhanni.features import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.PlayerSendChatEvent import at.hannibal2.skyhanni.events.RenderMobColoredEvent import at.hannibal2.skyhanni.events.ResetEntityHurtEvent import at.hannibal2.skyhanni.events.withAlpha @@ -9,7 +8,6 @@ import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraft.client.Minecraft import net.minecraft.client.entity.EntityOtherPlayerMP -import net.minecraft.util.EnumChatFormatting import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent @@ -17,7 +15,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent class MarkedPlayerManager { companion object { - private val playerNamesToMark = mutableListOf<String>() + val playerNamesToMark = mutableListOf<String>() private val markedPlayers = mutableMapOf<String, EntityOtherPlayerMP>() fun command(args: Array<String>) { @@ -119,16 +117,4 @@ class MarkedPlayerManager { } } } - - @SubscribeEvent - fun onMarkedChatMessage(event: PlayerSendChatEvent) { - if (!LorenzUtils.inSkyblock) return - - for (chatComponent in event.chatComponents) { - val text = chatComponent.unformattedText - if (isMarkedPlayer(text) && SkyHanniMod.feature.markedPlayers.highlightInChat) { - chatComponent.chatStyle.color = EnumChatFormatting.YELLOW - } - } - } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt index cd1581d5c..742625fb7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt @@ -258,6 +258,7 @@ class ChatFilter { private fun lobby(message: String): Boolean = when { //player join message.matchRegex("(.*) §6joined the lobby!") -> true + message.matchRegex("(.*) §6slid into the lobby!") -> true message.matchRegex(" §b>§c>§a>§r (.*) §6joined the lobby!§r §a<§c<§b<") -> true //mystery box diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatFilter.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatFilter.kt index f0576fa62..2510aa0b0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatFilter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatFilter.kt @@ -1,19 +1,27 @@ package at.hannibal2.skyhanni.features.chat.playerchat -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.PlayerSendChatEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.MultiFilter -import net.minecraft.util.ChatComponentText -import net.minecraft.util.EnumChatFormatting -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.regex.Pattern class PlayerChatFilter { - private val filters = mutableMapOf<String, MultiFilter>() + companion object { + + private val filters = mutableMapOf<String, MultiFilter>() + + fun shouldChatFilter(original: String): Boolean { + val message = original.lowercase() + for (filter in filters) { + filter.value.matchResult(message)?.let { + return true + } + } + + return false + } + } @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { @@ -42,48 +50,4 @@ class PlayerChatFilter { LorenzUtils.error("error in RepositoryReloadEvent") } } - - @SubscribeEvent(priority = EventPriority.HIGH) - fun onPlayerChat(event: PlayerSendChatEvent) { - if (!SkyHanniMod.feature.chat.chatFilter) return - if (event.channel != PlayerMessageChannel.ALL) return - - val message = event.message.lowercase() - for (filter in filters) { - filter.value.matchResult(message)?.let { - filter(event, it) - return - } - } - } - - private fun filter(event: PlayerSendChatEvent, filter: String) { - val pattern = Pattern.compile("(.*)?$filter(.*)?", Pattern.CASE_INSENSITIVE) - val matcher = pattern.matcher(event.message) - matcher.matches() - val beginning = matcher.group(1) - val end = matcher.group(2) - - event.chatComponents.clear() - - val endSplit = end.split(" ") - - for (word in beginning.split(" ")) { - if (word.isEmpty()) continue - event.chatComponents.add(coloredChat(word, EnumChatFormatting.GRAY)) - } - - event.chatComponents.add(coloredChat(filter.trim(), EnumChatFormatting.WHITE)) - - for (word in endSplit) { - if (word.isEmpty()) continue - event.chatComponents.add(coloredChat(word, EnumChatFormatting.GRAY)) - } - } - - private fun coloredChat(string: String, color: EnumChatFormatting): ChatComponentText { - val text = ChatComponentText(string) - text.chatStyle.color = color - return text - } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatFormatter.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatFormatter.kt deleted file mode 100644 index ea06519d6..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatFormatter.kt +++ /dev/null @@ -1,312 +0,0 @@ -package at.hannibal2.skyhanni.features.chat.playerchat - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.PlayerSendChatEvent -import at.hannibal2.skyhanni.features.MarkedPlayerManager -import at.hannibal2.skyhanni.utils.LorenzLogger -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraft.client.Minecraft -import net.minecraft.event.ClickEvent -import net.minecraft.event.HoverEvent -import net.minecraft.util.ChatComponentText -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.regex.Pattern - -class PlayerChatFormatter { - - private val loggerPlayerChat = LorenzLogger("chat/player") - - private val sbaIconList = listOf( - "§5ቾ", // mage - "§c⚒", // barbarian - "§7♲", // ironman - //TODO test if bingo is working - "§aⒷ", // bingo rank 1 - "§9Ⓑ", // bingo rank 2 - "§5Ⓑ" // bingo rank 3 - - //maybe coming soon - //"§6Ⓑ" // bingo rank 4 - ) - - private val patternUrl = - Pattern.compile("^https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$") - - //§6[⌬57] §r§8[§r§b235§r§8] §r§6[MVP§r§c++§r§6] hannibal2§r§f: Hello World! - private val patternElitePrefix = Pattern.compile("§6\\[⌬(\\d+)] (.+)") - - //§8[§9109§8] §b[MVP§c+§b] 4Apex§f§r§f: omg selling - private val patternSkyBlockLevel = Pattern.compile("§8\\[§(.)(\\d+)§8] (.+)") - - // SBA is adding another §d in front of the message - //§dTo §r§b[MVP§r§3+§r§b] Skyfall55§r§7: §r§7hello :) - private var patternPrivateMessage = Pattern.compile("(§d)+(To|From) §r(.+)§r§7: §r§7(.+)") - - @SubscribeEvent - fun onChatMessage(event: LorenzChatEvent) { - if (!LorenzUtils.isOnHypixel) return - - if (shouldBlock(event.message)) { - event.blockedReason = "player_chat" - } - } - - @SubscribeEvent(receiveCanceled = true) - fun onChatWithUrl(event: PlayerSendChatEvent) { - if (!LorenzUtils.inSkyblock) return - - for (chatComponent in event.chatComponents) { - val text = chatComponent.unformattedText - if (patternUrl.matcher(text).matches()) { - chatComponent.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.OPEN_URL, text) - } - } - } - - private fun shouldBlock(originalMessage: String): Boolean { - if (handlePrivateMessage(originalMessage)) return true - - //since hypixel sends own chat messages really weird " §r§8[§r§d205§r§8] §r§6[MVP§r§c++§r§6] hannibal2" - var rawMessage = originalMessage.replace("§r", "").trim() - - val matcherElite = patternElitePrefix.matcher(rawMessage) - val elitePrefix = if (matcherElite.matches()) { - val elitePosition = matcherElite.group(1).toInt() - rawMessage = matcherElite.group(2) - when (SkyHanniMod.feature.chat.eliteFormat) { - 0 -> "§6[⌬$elitePosition] " - 1 -> "§6§l⌬$elitePosition " - 2 -> "" - else -> "" - } - } else { - "" - } - - - val level: Int - val levelColor: String - val matcher = patternSkyBlockLevel.matcher(rawMessage) - if (matcher.matches()) { - levelColor = matcher.group(1) - level = matcher.group(2).toInt() - rawMessage = matcher.group(3) - } else { - level = -1 - levelColor = "" - } - - val split = if (rawMessage.contains("§7§7: ")) { - rawMessage.split("§7§7: ") - } else if (rawMessage.contains("§f: ")) { - rawMessage.split("§f: ") - } else { - return false - } - - var rawName = split[0] - val channel = grabChannel(rawName) - - rawName = rawName.substring(channel.originalPrefix.length) - - val sbaData = fetchSBAIcons(rawName) - val sbaIcons = sbaData.first - rawName = sbaData.second - - val name = grabName(rawName) ?: return false - - val message = split[1].removeColor() - callEvent(channel, name, message, level, levelColor, elitePrefix, sbaIcons) - return true - } - - private fun fetchSBAIcons(rawName: String): Pair<String, String> { - val iconsSplit = rawName.split(" ") - var sbaIcons = "" - var toRemove = 0 - for (text in iconsSplit) { - sbaIconList.find { text.contains(it) }?.let { - sbaIcons += " $it" - toRemove++ - } - } - var name = iconsSplit.dropLast(toRemove).joinToString(" ") - - // Test if any unknown icons are left - if (!name.split(" ").last().any { it in 'A'..'Z' || it in 'a'..'z' }) { - println(" ") - println("Unknown chat icon detected!") - LorenzUtils.chat("§c[SkyHanni] Unknown chat icon detected!") - println("name 1: '$rawName'") - println("name 2: '$name'") - name = rawName - } - - return Pair(sbaIcons, name) - } - - private fun handlePrivateMessage(originalMessage: String): Boolean { - val matcher = patternPrivateMessage.matcher(originalMessage) - if (!matcher.matches()) return false - val direction = matcher.group(2) - var rawName = matcher.group(3) - - val sbaData = fetchSBAIcons(rawName) - val sbaIcons = sbaData.first - rawName = sbaData.second - - val name = grabName(rawName) ?: return false - - val message = matcher.group(4) - val colon = if (SkyHanniMod.feature.chat.playerColonHider) "" else ":" - LorenzUtils.chat("§d$direction $name$sbaIcons§f$colon $message") - loggerPlayerChat.log("[Msg_$direction] $name: $message") - return true - } - - private fun grabChannel(name: String): PlayerMessageChannel { - return PlayerMessageChannel.values() - .find { it != PlayerMessageChannel.ALL && name.startsWith(it.originalPrefix) } - ?: PlayerMessageChannel.ALL - } - - private fun grabName(rawName: String, clean: Boolean = false): String? { - val nameSplit = rawName.removeColor().split(" ") - val last = nameSplit.last() - val cleanName = if (last.endsWith("]")) { - nameSplit[nameSplit.size - 2] - } else { - last - } - - val first = nameSplit[0] - if (first != cleanName) { - if (!first.contains("VIP") && !first.contains("MVP")) { - //TODO support yt + admin - return null - } - } - - if (clean) { - return cleanName - } - - val markedPlayer = MarkedPlayerManager.isMarkedPlayer(cleanName) && SkyHanniMod.feature.markedPlayers.highlightInChat - return if (SkyHanniMod.feature.chat.playerRankHider) { - if (markedPlayer) "§e$cleanName" else "§b$cleanName" - } else { - if (markedPlayer) { - if (rawName.contains(" ")) { - rawName[0] + " §e" + cleanName - } else { - "§e$cleanName" - } - } else { - rawName - } - } - } - - private fun callEvent( - channel: PlayerMessageChannel, - formattedName: String, - message: String, - level: Int, - levelColor: String, - elitePrefix: String, - sbaIcons: String, - ) { - val cleanName = grabName(formattedName, true)!! - loggerPlayerChat.log("[$channel] $cleanName: $message") - - - val chatComponents = mutableListOf<ChatComponentText>() - for (line in message.split(" ")) { - chatComponents.add(ChatComponentText(line)) - } - - val event = PlayerSendChatEvent(channel, cleanName, message, chatComponents) - event.postAndCatch() - - if (event.cancelledReason != "") { - loggerPlayerChat.log("cancelled: " + event.cancelledReason) - return - } - - val channelPrefix = getChannelPrefix(channel) - val colon = if (SkyHanniMod.feature.chat.playerColonHider) "" else ":" - val levelFormat = getLevelFormat(formattedName + sbaIcons, level, levelColor) - - val nameText = ChatComponentText("$channelPrefix$elitePrefix$levelFormat§f$colon") - if (SkyHanniMod.feature.chat.neuProfileViewer) { - nameText.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/pv $cleanName") - nameText.chatStyle.chatHoverEvent = HoverEvent( - HoverEvent.Action.SHOW_TEXT, - ChatComponentText("§7Click to open the §cNEU Profile Viewer §7for $formattedName") - ) - } - - addChat(nameText, chatComponents) - } - - private fun addChat(prefixComponent: ChatComponentText, chatComponents: MutableList<ChatComponentText>) { - val empty = ChatComponentText(" ") - - val result = ChatComponentText("") - result.appendSibling(prefixComponent) - - for (chatComponent in chatComponents) { - result.appendSibling(empty) - result.appendSibling(chatComponent) - } - - Minecraft.getMinecraft().thePlayer.addChatMessage(result) - } - - private fun getLevelFormat(name: String, level: Int, levelColor: String): String { - if (level == -1) return name - - return when (SkyHanniMod.feature.chat.skyblockLevelDesign) { - 0 -> "§8[§${levelColor}${level}§8] $name" - 1 -> "§${levelColor}§l${level} $name" - 2 -> "$name §8[§${levelColor}${level}§8]" - 3 -> name - else -> "§8[§${levelColor}${level}§8] $name" - } - } - - private fun getChannelPrefix(channel: PlayerMessageChannel): String { - if (channel == PlayerMessageChannel.ALL && !SkyHanniMod.feature.chat.allChannelPrefix) return "" - - val color = channel.prefixColor - val small = channel.prefixSmall - val large = channel.prefixLarge - return when (SkyHanniMod.feature.chat.channelDesign) { - 0 -> "$color$large §8> " - 1 -> "$color$small> " - 2 -> "§8<$color$small§8> " - 3 -> "§8[$color$small§8] " - 4 -> "§8($color$small§8) " - else -> "$color$large §8> " - } - } - - companion object { - - fun testAllChat() { - val name = Minecraft.getMinecraft().thePlayer.name - val message = - "§6[⌬499] §8[§b123§8] §6[MVP§c++§6] $name§f: This is a all chat test message and will not be sent to hypixel." - LorenzChatEvent(message, ChatComponentText(message)).postAndCatch() - } - - fun testGuildChat() { - val name = Minecraft.getMinecraft().thePlayer.name - val message = - "§2Guild > §6[MVP§f++§6] $name §2[GuildRank]§f: This is a guild chat test message and will not be sent to hypixel." - LorenzChatEvent(message, ChatComponentText(message)).postAndCatch() - } - } -}
\ No newline at end of file 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 new file mode 100644 index 000000000..9225ced72 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerChatModifier.kt @@ -0,0 +1,106 @@ +package at.hannibal2.skyhanni.features.chat.playerchat + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.features.MarkedPlayerManager +import net.minecraft.util.ChatComponentText +import net.minecraft.util.IChatComponent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class PlayerChatModifier { + + private val patterns = mutableListOf<Regex>() + + init { + patterns.add("§(?:a|b|6)\\[(?:VIP|MVP)(?:(?:§.|\\+)*)] (\\w{2,16})".toRegex()) // ranked player everywhere + patterns.add("§(?:7|a|b|6)((?:\\w+){2,16})§r(?!§7x)".toRegex()) // nons in notification message + patterns.add("§7((?:\\w+){2,16})§7§r".toRegex()) // nons user chat + } + + @SubscribeEvent + fun onChatReceive(event: LorenzChatEvent) { + val foundCommands = mutableListOf<IChatComponent>() + val message = event.chatComponent + + 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<IChatComponent>, message: IChatComponent) { + val clickEvent = message.chatStyle.chatClickEvent + if (clickEvent != null) { + if (foundCommands.size == 1) { + if (foundCommands[0].chatStyle.chatClickEvent.value == clickEvent.value) { + return + } + } + foundCommands.add(message) + } + } + + private fun cutMessage(input: String): String { + var string = input + + //all players same color in chat + string = string.replace("§r§7: ", "§r§f: ") + + if (SkyHanniMod.feature.chat.chatFilter) { + if (string.contains("§r§f: ")) { + if (PlayerChatFilter.shouldChatFilter(string)) { + string = string.replace("§r§f: ", "§r§7: ") + } + } + } + + if (SkyHanniMod.feature.chat.playerRankHider) { + for (pattern in patterns) { + string = string.replace(pattern, "§b$1") + } + string = string.replace("§(?:7|a|b|6)((?:\\w+){2,16})'s", "§b$1's") + string = string.replace("§(?:7|a|b|6)((?:\\w+){2,16}) (§.)", "§b$1 $2") + } + + if (SkyHanniMod.feature.markedPlayers.highlightInChat) { + for (markedPlayer in MarkedPlayerManager.playerNamesToMark) { + string = string.replace(markedPlayer, "§e$markedPlayer") + } + } + + return string + } + +// private fun shouldChatFilter(input: String): Boolean { +// val text = input.lowercase() +// +// //Low baller +// if (text.contains("lowballing")) return true +// if (text.contains("lowballer")) return true +// +// //Trade +// if (text.contains("buy")) return true +// if (text.contains("sell")) return true +// if (text.contains("on my ah")) return true +// +// +// return false +// } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerMessageChannel.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerMessageChannel.kt deleted file mode 100644 index b75f2c970..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/playerchat/PlayerMessageChannel.kt +++ /dev/null @@ -1,17 +0,0 @@ -package at.hannibal2.skyhanni.features.chat.playerchat - -enum class PlayerMessageChannel( - val prefixColor: String, - val prefixSmall: String, - val prefixLarge: String, - val originalPrefix: String, -) { - - ALL("§f", "A", "All", ""), - ALL_GUESTING("§a", "g", "Guest", "§a[✌] "), - ALL_DUNGEON_DEAD("§7", "D", "Dead", "§7[GHOST] "), - PARTY("§9", "P", "Party", "§9Party §8> "), - GUILD("§2", "G", "Guild", "§2Guild > "), - COOP("§b", "CC", "Co-op", "§bCo-op > "), - -}
\ No newline at end of file |