From 4f5d0f4c491dc2590ed17267a48fbb0757a3dd7a Mon Sep 17 00:00:00 2001 From: Chip <65827213+ChipmunkMC@users.noreply.github.com> Date: Tue, 10 Jan 2023 15:29:55 -0500 Subject: [PATCH] Fix chat parsing a bit --- .../chipmunk/chipmunkbot/systemChat/KaboomChatParser.java | 7 ++++--- .../chipmunkbot/systemChat/MinecraftChatParser.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkbot/systemChat/KaboomChatParser.java b/src/main/java/land/chipmunk/chipmunkbot/systemChat/KaboomChatParser.java index 34f342a..69194d4 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/systemChat/KaboomChatParser.java +++ b/src/main/java/land/chipmunk/chipmunkbot/systemChat/KaboomChatParser.java @@ -35,14 +35,14 @@ public class KaboomChatParser implements SystemChatParser { } public PlayerMessage parse (TranslatableComponent message) { - if (!message.key().equals("%") || message.args().size() != 1 || !message.style().equals(empty)) return parse(message.args().get(0)); + if (!message.key().equals("%") || message.args() == null || message.args().size() != 1 || !message.style().equals(empty)) return parse(message.args().get(0)); return null; } public PlayerMessage parse (TextComponent message) { List children = message.children(); - if (!message.content().equals("") || !message.style().equals(empty) || children.size() < 3) return null; + if (!message.content().equals("") || !message.style().equals(empty) || children == null || children.size() < 3) return null; final Map parameters = new HashMap<>(); @@ -59,7 +59,8 @@ public class KaboomChatParser implements SystemChatParser { return null; } - MutablePlayerListEntry sender = client.playerList().getEntry(prefix.append(displayName)); + MutablePlayerListEntry sender = client.playerList().getEntry(Component.empty().append(prefix).append(displayName)); + if (sender == null) sender = client.playerList().getEntry(prefix.append(displayName)); // deprecated if (sender == null) sender = new MutablePlayerListEntry(new GameProfile(new UUID(0l, 0l), null), GameMode.SURVIVAL, 0, displayName, 0L, null, new byte[0]); parameters.put("sender", displayName); diff --git a/src/main/java/land/chipmunk/chipmunkbot/systemChat/MinecraftChatParser.java b/src/main/java/land/chipmunk/chipmunkbot/systemChat/MinecraftChatParser.java index 6a887e5..fa550c9 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/systemChat/MinecraftChatParser.java +++ b/src/main/java/land/chipmunk/chipmunkbot/systemChat/MinecraftChatParser.java @@ -41,7 +41,7 @@ public class MinecraftChatParser implements SystemChatParser { public PlayerMessage parse (TranslatableComponent message) { final List args = message.args(); final String key = message.key(); - if (args.size() < 2 || !typeMap.containsKey(key)) return null; + if (args == null || args.size() < 2 || !typeMap.containsKey(key)) return null; final String type = typeMap.get(key);