From 46673f3daca72edb75441f0826a67eedaae33a75 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 20 Jul 2023 20:13:44 +0700 Subject: [PATCH] one of the worst fix owo --- .../chomens_bot/plugins/ChatPlugin.java | 48 ++++++++++++++----- .../chomens_bot/plugins/CommandSpyPlugin.java | 2 +- .../plugins/CommandSuggestionPlugin.java | 2 +- .../chomens_bot/plugins/DiscordPlugin.java | 17 +++++-- .../chomens_bot/plugins/LoggerPlugin.java | 9 ++-- .../chomens_bot/plugins/SelfCarePlugin.java | 37 +++++++------- 6 files changed, 72 insertions(+), 43 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java index 84aa319..526cd25 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java @@ -92,9 +92,14 @@ public class ChatPlugin extends Bot.Listener { if (id.equals(bot.commandSuggestion.id)) isCommandSuggestions = true; } catch (Exception ignored) {} + final String string = ComponentUtilities.stringify(component); + final String ansi = ComponentUtilities.stringifyAnsi(component); + for (Listener listener : listeners) { - if (!isCommandSuggestions) listener.systemMessageReceived(component); - listener.systemMessageReceived(component, isCommandSuggestions); + if (string.length() < 25_000) { + if (!isCommandSuggestions) listener.systemMessageReceived(component, string, ansi); + listener.systemMessageReceived(component, isCommandSuggestions, string, ansi); + } if (playerMessage != null) listener.playerMessageReceived(playerMessage); } @@ -131,13 +136,20 @@ public class ChatPlugin extends Bot.Listener { Component.text(packet.getContent()) ); + final Component unsignedContent = packet.getUnsignedContent(); + + final String translation = getTranslationByChatType(packet.getChatType()); + + String string = null; + String ansi = null; + if (translation != null && unsignedContent != null) { + string = ComponentUtilities.stringify(unsignedContent); + ansi = ComponentUtilities.stringifyAnsi(unsignedContent); + } + for (Listener listener : listeners) { listener.playerMessageReceived(playerMessage); - final Component unsignedContent = packet.getUnsignedContent(); - - final String translation = getTranslationByChatType(packet.getChatType()); - if (translation != null && unsignedContent == null) { TranslatableComponent component = Component.translatable(translation); @@ -151,9 +163,13 @@ public class ChatPlugin extends Bot.Listener { component = component.args(playerMessage.displayName, playerMessage.contents); } - listener.systemMessageReceived(component); + if (string.length() > 25_000) continue; + + listener.systemMessageReceived(component, string, ansi); } else { - listener.systemMessageReceived(unsignedContent); + if (string.length() > 25_000) continue; + + listener.systemMessageReceived(unsignedContent, string, ansi); } } } @@ -187,8 +203,10 @@ public class ChatPlugin extends Bot.Listener { translatableComponent = translatableComponent.args(name, content); } + final String string = ComponentUtilities.stringify(component); + final String ansi = ComponentUtilities.stringifyAnsi(component); for (Listener listener : listeners) { - listener.systemMessageReceived(translatableComponent); + listener.systemMessageReceived(translatableComponent, string, ansi); } for (ChatParser parser : chatParsers) { @@ -207,9 +225,15 @@ public class ChatPlugin extends Bot.Listener { final PlayerMessage playerMessage = new PlayerMessage(parsedFromMessage.sender, packet.getName(), parsedFromMessage.contents); + final String string = ComponentUtilities.stringify(component); + final String ansi = ComponentUtilities.stringifyAnsi(component); + for (Listener listener : listeners) { listener.playerMessageReceived(playerMessage); - listener.systemMessageReceived(component); + + if (string.length() > 25_000) continue; + + listener.systemMessageReceived(component, string, ansi); } } } catch (Exception e) { @@ -325,7 +349,7 @@ public class ChatPlugin extends Bot.Listener { public static class Listener { public void playerMessageReceived (PlayerMessage message) {} - public void systemMessageReceived (Component component) {} - public void systemMessageReceived (Component component, boolean isCommandSuggestions) {} + public void systemMessageReceived (Component component, String string, String ansi) {} + public void systemMessageReceived (Component component, boolean isCommandSuggestions, String string, String ansi) {} } } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSpyPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSpyPlugin.java index bb3849c..26240b8 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSpyPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSpyPlugin.java @@ -22,7 +22,7 @@ public class CommandSpyPlugin extends ChatPlugin.Listener { } @Override - public void systemMessageReceived(Component component) { + public void systemMessageReceived(Component component, String string, String ansi) { TextComponent textComponent; try { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java index f4913bd..1262e0c 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java @@ -20,7 +20,7 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener { } @Override - public void systemMessageReceived(Component component, boolean isCommandSuggestions) { + public void systemMessageReceived(Component component, boolean isCommandSuggestions, String string, String ansi) { if (!isCommandSuggestions) return; try { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java index 502a672..8ddc654 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java @@ -59,9 +59,20 @@ public class DiscordPlugin { bot.chat.addListener(new ChatPlugin.Listener() { @Override - public void systemMessageReceived (Component component) { - final String content = ComponentUtilities.stringifyAnsi(component); - sendMessage(CodeBlockUtilities.escape(content.replace("\u001b[9", "\u001b[3")), channelId); + public void systemMessageReceived (Component component, String string, String ansi) { + if (string.length() > 2048) { + sendMessage(CodeBlockUtilities.escape(string), channelId); + } else { + sendMessage( + CodeBlockUtilities.escape( + ansi + .replace( + "\u001b[9", "\u001b[3" + ) + ), + channelId + ); + } } }); } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java index 5838934..451aed8 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java @@ -78,11 +78,8 @@ public class LoggerPlugin extends ChatPlugin.Listener { } @Override - public void systemMessageReceived(Component component) { - final String stringMessage = ComponentUtilities.stringify(component); - final String ansiMessage = ComponentUtilities.stringifyAnsi(component); - - log(ansiMessage, false, logToConsole); - log(stringMessage, true, false); + public void systemMessageReceived(Component component, String string, String ansi) { + log(ansi, false, logToConsole); + log(string, true, false); } } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java index 088b38e..09f9817 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java @@ -14,7 +14,6 @@ import com.github.steveice10.packetlib.event.session.DisconnectedEvent; import com.github.steveice10.packetlib.packet.Packet; import land.chipmunk.chayapak.chomens_bot.Bot; import land.chipmunk.chayapak.chomens_bot.Configuration; -import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities; import net.kyori.adventure.text.Component; import org.cloudburstmc.math.vector.Vector3i; @@ -47,31 +46,29 @@ public class SelfCarePlugin extends Bot.Listener { bot.chat.addListener(new ChatPlugin.Listener() { @Override - public void systemMessageReceived(Component component) { - final String message = ComponentUtilities.stringify(component); + public void systemMessageReceived(Component component, String string, String ansi) { + if (string.equals("Successfully enabled CommandSpy")) cspy = true; + else if (string.equals("Successfully disabled CommandSpy")) cspy = false; - if (message.equals("Successfully enabled CommandSpy")) cspy = true; - else if (message.equals("Successfully disabled CommandSpy")) cspy = false; + else if (string.equals("Vanish for " + bot.username + ": enabled")) vanish = true; + else if (string.equals("You are now completely invisible to normal users, and hidden from in-game commands.")) vanish = true; + else if (string.equals("Vanish for " + bot.username + ": disabled")) vanish = false; - else if (message.equals("Vanish for " + bot.username + ": enabled")) vanish = true; - else if (message.equals("You are now completely invisible to normal users, and hidden from in-game commands.")) vanish = true; - else if (message.equals("Vanish for " + bot.username + ": disabled")) vanish = false; + else if (string.equals("You no longer have a nickname.")) nickname = true; + else if (string.startsWith("Your nickname is now ")) nickname = false; - else if (message.equals("You no longer have a nickname.")) nickname = true; - else if (message.startsWith("Your nickname is now ")) nickname = false; + else if (string.equals("SocialSpy for " + bot.username + ": enabled")) socialspy = true; + else if (string.equals("SocialSpy for " + bot.username + ": disabled")) socialspy = false; - else if (message.equals("SocialSpy for " + bot.username + ": enabled")) socialspy = true; - else if (message.equals("SocialSpy for " + bot.username + ": disabled")) socialspy = false; + else if (string.startsWith("You have been muted")) muted = true; + else if (string.equals("You have been unmuted.")) muted = false; - else if (message.startsWith("You have been muted")) muted = true; - else if (message.equals("You have been unmuted.")) muted = false; + else if (string.equals("You now have the tag: " + bot.config.selfCare.prefix.prefix)) prefix = true; + else if (string.startsWith("You no longer have a tag")) prefix = false; + else if (string.startsWith("You now have the tag: ")) prefix = false; - else if (message.equals("You now have the tag: " + bot.config.selfCare.prefix.prefix)) prefix = true; - else if (message.startsWith("You no longer have a tag")) prefix = false; - else if (message.startsWith("You now have the tag: ")) prefix = false; - - else if (message.equals("Successfully set your username to \"" + bot.username + "\"")) username = true; - else if (message.startsWith("Successfully set your username to \"")) username = false; + else if (string.equals("Successfully set your username to \"" + bot.username + "\"")) username = true; + else if (string.startsWith("Successfully set your username to \"")) username = false; } });