actually improve the systemMessageReceived thing

This commit is contained in:
Chayapak 2023-04-24 14:43:55 +07:00
parent dd5980cddf
commit 287b02256e
4 changed files with 12 additions and 22 deletions

View file

@ -81,9 +81,8 @@ public class ChatPlugin extends SessionAdapter {
PlayerMessage commandSpyMessage;
commandSpyMessage = commandSpyParser.parse(component);
final String message = ComponentUtilities.stringify(component);
for (ChatListener listener : listeners) {
listener.systemMessageReceived(message, component);
listener.systemMessageReceived(component);
if (playerMessage != null) listener.playerMessageReceived(playerMessage);
if (commandSpyMessage != null) listener.commandSpyMessageReceived(commandSpyMessage);
}
@ -112,19 +111,13 @@ public class ChatPlugin extends SessionAdapter {
playerMessage.contents()
);
listener.systemMessageReceived(
ComponentUtilities.stringify(component),
component
);
listener.systemMessageReceived(component);
} else {
final Component unsignedContent = packet.getUnsignedContent();
if (unsignedContent == null) return;
listener.systemMessageReceived(
ComponentUtilities.stringify(unsignedContent),
unsignedContent
);
listener.systemMessageReceived(unsignedContent);
}
}
}
@ -154,10 +147,7 @@ public class ChatPlugin extends SessionAdapter {
for (ChatListener listener : listeners) {
listener.playerMessageReceived(playerMessage);
listener.systemMessageReceived(
ComponentUtilities.stringify(component),
component
);
listener.systemMessageReceived(component);
}
}
} else {
@ -176,10 +166,7 @@ public class ChatPlugin extends SessionAdapter {
for (ChatListener listener : listeners) {
listener.playerMessageReceived(playerMessage);
listener.systemMessageReceived(
ComponentUtilities.stringify(component),
component
);
listener.systemMessageReceived(component);
}
}
}
@ -248,6 +235,6 @@ public class ChatPlugin extends SessionAdapter {
public static class ChatListener {
public void playerMessageReceived (PlayerMessage message) {}
public void commandSpyMessageReceived (PlayerMessage message) {}
public void systemMessageReceived (String message, Component component) {}
public void systemMessageReceived (Component component) {}
}
}

View file

@ -58,7 +58,7 @@ public class DiscordPlugin {
bot.chat().addListener(new ChatPlugin.ChatListener() {
@Override
public void systemMessageReceived (String ignoredMessage, Component component) {
public void systemMessageReceived (Component component) {
final String content = ComponentUtilities.stringifyAnsi(component);
sendMessage(EscapeCodeBlock.escape(content.replace("\u001b[9", "\u001b[3")), channelId);
}

View file

@ -82,7 +82,7 @@ public class LoggerPlugin extends ChatPlugin.ChatListener {
}
@Override
public void systemMessageReceived(String message, Component component) {
public void systemMessageReceived(Component component) {
final String ansiMessage = ComponentUtilities.stringifyAnsi(component);
log(ansiMessage);
}

View file

@ -19,6 +19,7 @@ import com.github.steveice10.packetlib.packet.PacketProtocol;
import com.nukkitx.math.vector.Vector3i;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.Configuration;
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
import lombok.Getter;
import lombok.Setter;
import net.kyori.adventure.text.Component;
@ -52,7 +53,9 @@ public class SelfCarePlugin extends SessionAdapter {
bot.chat().addListener(new ChatPlugin.ChatListener() {
@Override
public void systemMessageReceived(String message, Component component) {
public void systemMessageReceived(Component component) {
final String message = ComponentUtilities.stringify(component);
if (message.equals("Successfully enabled CommandSpy")) cspy = true;
else if (message.equals("Successfully disabled CommandSpy")) cspy = false;