From f5db2e02a3487ddcb4e69288896812755a8c5250 Mon Sep 17 00:00:00 2001 From: Chipmunk <65827213+ChipmunkMC@users.noreply.github.com> Date: Sun, 30 Apr 2023 22:39:27 -0400 Subject: [PATCH] fix player messages --- .../chipmunk/chipmunkbot/plugins/ChatPlugin.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/land/chipmunk/chipmunkbot/plugins/ChatPlugin.java b/src/main/java/land/chipmunk/chipmunkbot/plugins/ChatPlugin.java index a0d3991..3b73dc2 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/plugins/ChatPlugin.java +++ b/src/main/java/land/chipmunk/chipmunkbot/plugins/ChatPlugin.java @@ -86,7 +86,18 @@ public class ChatPlugin extends SessionAdapter { public void packetReceived (Session session, ClientboundPlayerChatPacket packet) { final MutablePlayerListEntry sender = client.playerList().getEntry(packet.getSender()); if (sender == null) return; - final PlayerMessage playerMessage = new PlayerMessage(sender, packet.getUnsignedContent(), "minecraft:chat", packet.getName()); // TODO: Fix chatType + + PlayerMessage parsedFromMessage = null; + final Component component = packet.getUnsignedContent(); + + for (SystemChatParser parser : systemChatParsers) { + parsedFromMessage = parser.parse(component); + if (parsedFromMessage != null) break; + } + + if (parsedFromMessage == null) return; + + final PlayerMessage playerMessage = new PlayerMessage(sender, parsedFromMessage.contents(), "minecraft:chat", packet.getName()); // TODO: Fix chatType for (Listener listener : this.listeners) { listener.playerMessageReceived(playerMessage);