diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/AuthPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/AuthPlugin.java index d217d908..310f57ad 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/AuthPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/AuthPlugin.java @@ -34,8 +34,8 @@ public class AuthPlugin extends PlayersPlugin.Listener { bot.players.addListener(this); bot.chat.addListener(new ChatPlugin.Listener() { @Override - public void systemMessageReceived(Component component, String string, String ansi) { - AuthPlugin.this.systemMessageReceived(component); + public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, String string, String ansi) { + AuthPlugin.this.systemMessageReceived(component, isCommandSuggestions, isAuth); } }); bot.executor.scheduleAtFixedRate(this::check, 0, 1, TimeUnit.SECONDS); @@ -45,15 +45,15 @@ public class AuthPlugin extends PlayersPlugin.Listener { public void playerJoined(PlayerEntry target) { if (!target.profile.getName().equals(bot.config.ownerName) || !bot.options.useCore) return; - bot.executor.schedule(() -> sendVerificationMessage(target), 2, TimeUnit.SECONDS); + bot.executor.schedule(() -> sendVerificationMessage(target, true), 2, TimeUnit.SECONDS); } - public void sendVerificationMessage (PlayerEntry entry) { + public void sendVerificationMessage (PlayerEntry entry, boolean setTimeJoined) { started = true; final long currentTime = System.currentTimeMillis(); - timeJoined = currentTime; + if (setTimeJoined) timeJoined = currentTime; final long time = currentTime / 10_000; @@ -79,13 +79,9 @@ public class AuthPlugin extends PlayersPlugin.Listener { started = false; } - private void systemMessageReceived (Component component) { + private void systemMessageReceived (Component component, boolean isCommandSuggestions, boolean isAuth) { try { - if (!(component instanceof TextComponent)) return; - - final String content = ((TextComponent) component).content(); - - if (!content.equals(id)) return; + if (isCommandSuggestions || !isAuth) return; final List children = component.children(); @@ -116,7 +112,7 @@ public class AuthPlugin extends PlayersPlugin.Listener { final long timeSinceJoined = System.currentTimeMillis() - timeJoined; - if (!hasCorrectHash) sendVerificationMessage(entry); + if (!hasCorrectHash) sendVerificationMessage(entry, false); if (timeSinceJoined > bot.config.ownerAuthentication.timeout && !hasCorrectHash) { bot.filter.mute(entry, "Not verified"); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java index 7653d26d..1d58daec 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java @@ -91,19 +91,21 @@ public class ChatPlugin extends Bot.Listener { if (playerMessage != null) break; } - boolean ignore = false; + boolean isCommandSuggestions = false; + boolean isAuth = false; if (component instanceof TextComponent t_component) { final String id = t_component.content(); - if (id.equals(bot.commandSuggestion.id) || id.equals(bot.auth.id)) ignore = true; + if (id.equals(bot.commandSuggestion.id)) isCommandSuggestions = true; + else if (id.equals(bot.auth.id)) isAuth = true; } final String string = ComponentUtilities.stringify(component); final String ansi = ComponentUtilities.stringifyAnsi(component); for (Listener listener : listeners) { - if (!ignore) listener.systemMessageReceived(component, string, ansi); - listener.systemMessageReceived(component, ignore, string, ansi); + if (!isCommandSuggestions && !isAuth) listener.systemMessageReceived(component, string, ansi); + listener.systemMessageReceived(component, isCommandSuggestions, isAuth, string, ansi); if (playerMessage != null) listener.playerMessageReceived(playerMessage); } @@ -363,6 +365,6 @@ public class ChatPlugin extends Bot.Listener { public static class Listener { public void playerMessageReceived (PlayerMessage message) {} public void systemMessageReceived (Component component, String string, String ansi) {} - public void systemMessageReceived (Component component, boolean isCommandSuggestions, String string, String ansi) {} + public void systemMessageReceived (Component component, boolean isCommandSuggestions, boolean isAuth, String string, String ansi) {} } } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java index 1262e0ce..272bbd35 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java @@ -20,7 +20,7 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener { } @Override - public void systemMessageReceived(Component component, boolean isCommandSuggestions, String string, String ansi) { + public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, String string, String ansi) { if (!isCommandSuggestions) return; try {