From 16c79115ee1aa0163abbcec1ba8ced827fac4398 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 13 Jul 2023 20:31:41 +0700 Subject: [PATCH] some stuff about the command suggestions --- .../chayapak/chomens_bot/plugins/ChatPlugin.java | 13 ++++++++++++- .../plugins/CommandSuggestionPlugin.java | 14 ++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) 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 d7798725..84aa3197 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 @@ -19,6 +19,7 @@ import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities; import land.chipmunk.chayapak.chomens_bot.util.IllegalCharactersUtilities; import land.chipmunk.chayapak.chomens_bot.util.UUIDUtilities; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; @@ -84,8 +85,17 @@ public class ChatPlugin extends Bot.Listener { if (playerMessage != null) break; } + boolean isCommandSuggestions = false; + try { + final String id = ((TextComponent) component).content(); + + if (id.equals(bot.commandSuggestion.id)) isCommandSuggestions = true; + } catch (Exception ignored) {} + for (Listener listener : listeners) { - listener.systemMessageReceived(component); + if (!isCommandSuggestions) listener.systemMessageReceived(component); + listener.systemMessageReceived(component, isCommandSuggestions); + if (playerMessage != null) listener.playerMessageReceived(playerMessage); } } @@ -316,5 +326,6 @@ public class ChatPlugin extends Bot.Listener { public static class Listener { public void playerMessageReceived (PlayerMessage message) {} public void systemMessageReceived (Component component) {} + public void systemMessageReceived (Component component, boolean isCommandSuggestions) {} } } 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 7b1cea02..19af0984 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,12 +20,10 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener { } @Override - public void systemMessageReceived(Component component) { + public void systemMessageReceived(Component component, boolean isCommandSuggestions) { + if (!isCommandSuggestions) return; + try { - final String tag = ((TextComponent) component).content(); - - if (!tag.equals(id)) return; - final List children = component.children(); if (children.size() != 1) return; @@ -36,7 +34,11 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener { output.add(Component.text(id)); for (Command command : bot.commandHandler.commands) { - output.add(Component.text(command.name)); + output.add( + Component + .text(command.name) + .append(Component.text(command.trustLevel.name())) + ); } bot.chat.tellraw(Component.join(JoinConfiguration.noSeparators(), output), player);