This commit is contained in:
Chayapak 2023-08-02 13:21:16 +07:00
parent da7c775ed3
commit 95d193d11c
6 changed files with 29 additions and 22 deletions

View file

@ -98,9 +98,12 @@ public class ChatPlugin extends Bot.Listener {
if (id.equals(bot.commandSuggestion.id)) isCommandSuggestions = true; if (id.equals(bot.commandSuggestion.id)) isCommandSuggestions = true;
} }
final String string = ComponentUtilities.stringify(component);
final String ansi = ComponentUtilities.stringifyAnsi(component);
for (Listener listener : listeners) { for (Listener listener : listeners) {
if (!isCommandSuggestions) listener.systemMessageReceived(component); if (!isCommandSuggestions) listener.systemMessageReceived(component, string, ansi);
listener.systemMessageReceived(component, isCommandSuggestions); listener.systemMessageReceived(component, isCommandSuggestions, string, ansi);
if (playerMessage != null) listener.playerMessageReceived(playerMessage); if (playerMessage != null) listener.playerMessageReceived(playerMessage);
} }
@ -157,9 +160,15 @@ public class ChatPlugin extends Bot.Listener {
component = component.args(playerMessage.displayName, playerMessage.contents); component = component.args(playerMessage.displayName, playerMessage.contents);
} }
listener.systemMessageReceived(component); final String string = ComponentUtilities.stringify(component);
final String ansi = ComponentUtilities.stringifyAnsi(component);
listener.systemMessageReceived(component, string, ansi);
} else { } else {
listener.systemMessageReceived(unsignedContent); final String string = ComponentUtilities.stringify(unsignedContent);
final String ansi = ComponentUtilities.stringifyAnsi(unsignedContent);
listener.systemMessageReceived(unsignedContent, string, ansi);
} }
} }
} }
@ -193,8 +202,11 @@ public class ChatPlugin extends Bot.Listener {
translatableComponent = translatableComponent.args(name, content); translatableComponent = translatableComponent.args(name, content);
} }
final String string = ComponentUtilities.stringify(translatableComponent);
final String ansi = ComponentUtilities.stringifyAnsi(translatableComponent);
for (Listener listener : listeners) { for (Listener listener : listeners) {
listener.systemMessageReceived(translatableComponent); listener.systemMessageReceived(translatableComponent, string, ansi);
} }
for (ChatParser parser : chatParsers) { for (ChatParser parser : chatParsers) {
@ -213,10 +225,13 @@ public class ChatPlugin extends Bot.Listener {
final PlayerMessage playerMessage = new PlayerMessage(parsedFromMessage.sender, packet.getName(), parsedFromMessage.contents); 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) { for (Listener listener : listeners) {
listener.playerMessageReceived(playerMessage); listener.playerMessageReceived(playerMessage);
listener.systemMessageReceived(component); listener.systemMessageReceived(component, string, ansi);
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -347,7 +362,7 @@ public class ChatPlugin extends Bot.Listener {
public static class Listener { public static class Listener {
public void playerMessageReceived (PlayerMessage message) {} public void playerMessageReceived (PlayerMessage message) {}
public void systemMessageReceived (Component component) {} public void systemMessageReceived (Component component, String string, String ansi) {}
public void systemMessageReceived (Component component, boolean isCommandSuggestions) {} public void systemMessageReceived (Component component, boolean isCommandSuggestions, String string, String ansi) {}
} }
} }

View file

@ -22,7 +22,7 @@ public class CommandSpyPlugin extends ChatPlugin.Listener {
} }
@Override @Override
public void systemMessageReceived(Component component) { public void systemMessageReceived(Component component, String string, String ansi) {
TextComponent textComponent; TextComponent textComponent;
try { try {

View file

@ -20,7 +20,7 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener {
} }
@Override @Override
public void systemMessageReceived(Component component, boolean isCommandSuggestions) { public void systemMessageReceived(Component component, boolean isCommandSuggestions, String string, String ansi) {
if (!isCommandSuggestions) return; if (!isCommandSuggestions) return;
try { try {

View file

@ -63,10 +63,7 @@ public class DiscordPlugin {
bot.chat.addListener(new ChatPlugin.Listener() { bot.chat.addListener(new ChatPlugin.Listener() {
@Override @Override
public void systemMessageReceived (Component component) { public void systemMessageReceived (Component component, String string, String ansi) {
final String string = ComponentUtilities.stringify(component);
final String ansi = ComponentUtilities.stringifyAnsi(component);
if (string.length() > 2048) { if (string.length() > 2048) {
sendMessage(CodeBlockUtilities.escape(string), channelId); sendMessage(CodeBlockUtilities.escape(string), channelId);
} else { } else {

View file

@ -88,14 +88,11 @@ public class LoggerPlugin extends ChatPlugin.Listener {
} }
@Override @Override
public void systemMessageReceived(Component component) { public void systemMessageReceived(Component component, String string, String ansi) {
final String string = ComponentUtilities.stringify(component);
if (logToConsole) { if (logToConsole) {
final String ansi = ComponentUtilities.stringifyAnsi(component);
log(ansi, false, true); log(ansi, false, true);
} }
log(string, true, false); log(string, true, false);
} }
} }

View file

@ -47,9 +47,7 @@ public class SelfCarePlugin extends Bot.Listener {
bot.chat.addListener(new ChatPlugin.Listener() { bot.chat.addListener(new ChatPlugin.Listener() {
@Override @Override
public void systemMessageReceived(Component component) { public void systemMessageReceived(Component component, String string, String ansi) {
final String string = ComponentUtilities.stringify(component);
if (string.equals("Successfully enabled CommandSpy")) cspy = true; if (string.equals("Successfully enabled CommandSpy")) cspy = true;
else if (string.equals("Successfully disabled CommandSpy")) cspy = false; else if (string.equals("Successfully disabled CommandSpy")) cspy = false;