diff --git a/build-number.txt b/build-number.txt index c802063a..a6ae6d78 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -2198 \ No newline at end of file +2206 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/ChomeNSModIntegrationPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/ChomeNSModIntegrationPlugin.java index 1977318e..09769c8f 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/ChomeNSModIntegrationPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/ChomeNSModIntegrationPlugin.java @@ -222,11 +222,11 @@ public class ChomeNSModIntegrationPlugin implements ChatPlugin.Listener, Players final String id = textComponent.content(); - if (!id.equals(ID)) return true; - - if (component.children().size() != 1) return true; - - if (!(component.children().getFirst() instanceof TextComponent dataComponent)) return true; + if ( + !id.equals(ID) || + component.children().size() != 1 || + !(component.children().getFirst() instanceof TextComponent dataComponent) + ) return true; final String data = dataComponent.content(); diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/CommandSpyPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/CommandSpyPlugin.java index 1e23f3d8..64df63ef 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/CommandSpyPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/CommandSpyPlugin.java @@ -22,34 +22,29 @@ public class CommandSpyPlugin implements ChatPlugin.Listener { } @Override - public boolean systemMessageReceived(Component component, String string, String ansi) { - TextComponent textComponent; + public boolean systemMessageReceived (Component component, String string, String ansi) { + final List children = component.children(); - try { - textComponent = (TextComponent) component; + if ( + !(component instanceof TextComponent textComponent) || + children.size() != 2 || + textComponent.style().isEmpty() || + ( + textComponent.color() != NamedTextColor.AQUA && + textComponent.color() != NamedTextColor.YELLOW + ) || + !(children.getFirst() instanceof TextComponent) || + !(children.getLast() instanceof TextComponent) + ) return true; - final List children = textComponent.children(); + final String username = textComponent.content(); + final String command = ComponentUtilities.stringify(children.getLast()); - if ( - ( - textComponent.color() != NamedTextColor.AQUA || - textComponent.color() != NamedTextColor.YELLOW || - textComponent.style().isEmpty() - ) && - children.size() != 2 - ) return true; + final PlayerEntry sender = bot.players.getEntry(username); - if (!((TextComponent) children.getFirst()).content().equals(": ")) return true; + if (sender == null) return true; - final String username = textComponent.content(); - final String command = ComponentUtilities.stringify(children.get(1)); - - final PlayerEntry sender = bot.players.getEntry(username); - - if (sender == null) return true; - - for (Listener listener : listeners) listener.commandReceived(sender, command); - } catch (ClassCastException ignored) {} + for (Listener listener : listeners) listener.commandReceived(sender, command); return true; } diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/CommandSuggestionPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/CommandSuggestionPlugin.java index 745816e1..d017ae7a 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/CommandSuggestionPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/CommandSuggestionPlugin.java @@ -10,53 +10,51 @@ import java.util.ArrayList; import java.util.List; public class CommandSuggestionPlugin implements ChatPlugin.Listener { - private final Bot bot; + public static final String ID = "chomens_bot_request_command_suggestion"; - public final String id = "chomens_bot_request_command_suggestion"; + private final Bot bot; public CommandSuggestionPlugin (Bot bot) { this.bot = bot; + bot.chat.addListener(this); } @Override public boolean systemMessageReceived(Component component, String string, String ansi) { - if (!(component instanceof TextComponent idComponent)) return true; + final List children = component.children(); - if (!idComponent.content().equals(id)) return true; + if ( + !(component instanceof TextComponent idComponent) || + !idComponent.content().equals(ID) || + children.size() != 1 || + !(children.getFirst() instanceof TextComponent playerComponent) + ) return true; - try { - final List children = component.children(); + final String player = playerComponent.content(); - if (children.size() != 1) return true; + final List output = new ArrayList<>(); + output.add(Component.text(ID)); - final String player = ((TextComponent) children.getFirst()).content(); + for (Command command : CommandHandlerPlugin.commands) { + if (command.consoleOnly) continue; - final List output = new ArrayList<>(); - output.add(Component.text(id)); + final boolean hasAliases = command.aliases.length != 0; - for (Command command : CommandHandlerPlugin.commands) { - if (command.consoleOnly) continue; + Component outputComponent = Component + .text(command.name) + .append(Component.text(command.trustLevel.name())) + .append(Component.text(hasAliases)); - final boolean hasAliases = command.aliases.length != 0; - - Component outputComponent = Component - .text(command.name) - .append(Component.text(command.trustLevel.name())) - .append(Component.text(hasAliases)); - - if (hasAliases) { - for (String alias : command.aliases) outputComponent = outputComponent.append(Component.text(alias)); - } - - output.add(outputComponent); + if (hasAliases) { + for (String alias : command.aliases) outputComponent = outputComponent.append(Component.text(alias)); } - bot.chat.tellraw(Component.join(JoinConfiguration.noSeparators(), output), player); + output.add(outputComponent); + } - return false; - } catch (Exception ignored) {} + bot.chat.tellraw(Component.join(JoinConfiguration.noSeparators(), output), player); - return true; + return false; } } diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/QueryPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/QueryPlugin.java index 219cff9c..1b17a137 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/QueryPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/QueryPlugin.java @@ -31,22 +31,23 @@ public class QueryPlugin extends Bot.Listener implements ChatPlugin.Listener { public boolean systemMessageReceived (Component component, String string, String ansi) { if (!(component instanceof TextComponent textComponent)) return true; + final UUID inputId = UUIDUtilities.tryParse(textComponent.content()); + + if (inputId == null || !ids.contains(inputId)) return true; + + ids.remove(inputId); + + final List children = component.children(); + + if ( + children.size() > 2 || + !(children.getFirst() instanceof TextComponent firstChild) + ) return false; + try { - final UUID inputId = UUIDUtilities.tryParse(textComponent.content()); - - if (inputId == null || !ids.contains(inputId)) return true; + final long transactionId = Long.parseLong(firstChild.content()); - ids.remove(inputId); - - final List children = component.children(); - - if (children.size() > 2) return false; - - if (!(children.getFirst() instanceof TextComponent)) return true; - - final long transactionId = Long.parseLong(((TextComponent) children.getFirst()).content()); - - if (!transactions.containsKey(transactionId)) return true; + if (!transactions.containsKey(transactionId)) return false; final CompletableFuture future = transactions.get(transactionId); @@ -67,9 +68,9 @@ public class QueryPlugin extends Bot.Listener implements ChatPlugin.Listener { } return false; - } catch (ClassCastException | NumberFormatException ignored) {} - - return true; + } catch (NumberFormatException e) { + return true; + } } private Triple, Long, UUID> getFutureAndId () {