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); }