From 42873589f6835453ae7429efe7831d0b53cc48be Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Fri, 7 Jul 2023 20:49:04 +0700 Subject: [PATCH] check for `: ` in commandspy --- .../chomens_bot/plugins/CommandSpyPlugin.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) 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 edb0b259..bbe8fde0 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 @@ -23,33 +23,33 @@ public class CommandSpyPlugin extends ChatPlugin.Listener { @Override public void systemMessageReceived(Component component) { - TextComponent textComponent = null; + TextComponent textComponent; try { textComponent = (TextComponent) component; - } catch (ClassCastException e) { - return; - } - final List children = textComponent.children(); + final List children = textComponent.children(); - if ( - ( - textComponent.color() != NamedTextColor.AQUA || - textComponent.color() != NamedTextColor.YELLOW || - textComponent.style().isEmpty() - ) && - children.size() < 2 - ) return; + if ( + ( + textComponent.color() != NamedTextColor.AQUA || + textComponent.color() != NamedTextColor.YELLOW || + textComponent.style().isEmpty() + ) && + children.size() < 2 + ) return; - final String username = textComponent.content(); - final String command = ComponentUtilities.stringify(children.get(1)); + if (!((TextComponent) children.get(0)).content().equals(": ")) return; - final MutablePlayerListEntry sender = bot.players.getEntry(username); + final String username = textComponent.content(); + final String command = ComponentUtilities.stringify(children.get(1)); - if (sender == null) return; + final MutablePlayerListEntry sender = bot.players.getEntry(username); - for (Listener listener : listeners) listener.commandReceived(sender, command); + if (sender == null) return; + + for (Listener listener : listeners) listener.commandReceived(sender, command); + } catch (ClassCastException ignored) {} } public void addListener (Listener listener) { listeners.add(listener); }