From 55a9d6a746362cb6bc20e7f49393283c7ab16912 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:07:56 +0700 Subject: [PATCH] add botuser and username self care --- .../chayapak/chomens_bot/Configuration.java | 1 + .../chomens_bot/commands/BotUserCommand.java | 79 +++++++++++++++++++ .../plugins/CommandHandlerPlugin.java | 1 + .../chomens_bot/plugins/PlayersPlugin.java | 2 + .../chomens_bot/plugins/SelfCarePlugin.java | 14 ++-- src/main/resources/default-config.yml | 7 +- 6 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BotUserCommand.java diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java index 47178cc..540459a 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java @@ -57,6 +57,7 @@ public class Configuration { @Getter public boolean mute = true; @Getter public boolean prefix = true; + @Getter public boolean username = true; } public static class Bots { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BotUserCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BotUserCommand.java new file mode 100644 index 0000000..b537578 --- /dev/null +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BotUserCommand.java @@ -0,0 +1,79 @@ +package land.chipmunk.chayapak.chomens_bot.commands; + +import land.chipmunk.chayapak.chomens_bot.Bot; +import land.chipmunk.chayapak.chomens_bot.command.Command; +import land.chipmunk.chayapak.chomens_bot.command.CommandContext; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.ArrayList; +import java.util.List; + +public class BotUserCommand implements Command { + public String name() { return "botuser"; } + + public String description() { + return "Shows the bot's username and UUID"; + } + + public List usage() { + final List usages = new ArrayList<>(); + usages.add(""); + + return usages; + } + + public List alias() { + final List aliases = new ArrayList<>(); + aliases.add(""); + + return aliases; + } + + public int trustLevel() { + return 0; + } + + public Component execute(CommandContext context, String[] args, String[] fullArgs) { + final Bot bot = context.bot(); + + final String username = bot.username(); + final String uuid = bot.players().getBotEntry().profile().getIdAsString(); + + context.sendOutput( + Component.translatable( + "The bot's username is: %s and the UUID is: %s", + Component + .text(username) + .hoverEvent( + HoverEvent.showText( + Component + .text("Click here to copy the username to your clipboard") + .color(NamedTextColor.GREEN) + ) + ) + .clickEvent( + ClickEvent.copyToClipboard(username) + ) + .color(NamedTextColor.GOLD), + Component + .text(uuid) + .hoverEvent( + HoverEvent.showText( + Component + .text("Click here to copy the UUID to your clipboard") + .color(NamedTextColor.GREEN) + ) + ) + .clickEvent( + ClickEvent.copyToClipboard(uuid) + ) + .color(NamedTextColor.AQUA) + ) + ); + + return Component.text("success"); + } +} diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java index f2dd301..f077b9a 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java @@ -49,6 +49,7 @@ public class CommandHandlerPlugin { registerCommand(new CloopCommand()); registerCommand(new WeatherCommand()); registerCommand(new ServerInfoCommand()); + registerCommand(new BotUserCommand()); } public void registerCommand (Command command) { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java index 105404d..2cf26cd 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java @@ -73,6 +73,8 @@ public class PlayersPlugin extends SessionAdapter { return null; } + public MutablePlayerListEntry getBotEntry () { return getEntry(bot.username()); } + private MutablePlayerListEntry getEntry (PlayerListEntry other) { return getEntry(other.getProfile().getId()); } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java index ce8ad47..7fd7148 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java @@ -41,6 +41,7 @@ public class SelfCarePlugin extends SessionAdapter { private boolean socialspy = false; private boolean muted = false; private boolean prefix = false; + private boolean username = true; public SelfCarePlugin (Bot bot) { this.bot = bot; @@ -67,12 +68,12 @@ public class SelfCarePlugin extends SessionAdapter { else if (message.equals("You now have the tag: [ChomeNS Bot]") || // for 1.19.2 (or 1.19?) and older clones message.equals("You now have the tag: &8[&eChomeNS Bot&8]") - ) { - prefix = true; - return; - } - if (message.startsWith("You no longer have a tag")) prefix = false; - if (message.startsWith("You now have the tag: ")) prefix = false; + ) prefix = true; + else if (message.startsWith("You no longer have a tag")) prefix = false; + else if (message.startsWith("You now have the tag: ")) prefix = false; + + else if (message.equals("Successfully set your username to \"" + bot.username() + "\"")) username = true; + else if (message.startsWith("Successfully set your username to \"")) username = false; } }); } @@ -88,6 +89,7 @@ public class SelfCarePlugin extends SessionAdapter { else if (selfCares.socialspy() && !socialspy) bot.chat().send("/essentials:socialspy enable"); else if (selfCares.mute() && muted) bot.chat().send("/essentials:mute " + bot.username()); else if (selfCares.prefix() && !prefix && bot.kaboom()) bot.chat().send("/extras:prefix &8[&eChomeNS Bot&8]"); + else if (selfCares.username() && !username && bot.kaboom()) bot.chat().send("/extras:username " + bot.username()); } @Override diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index 96ce6c7..25178bf 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -32,7 +32,7 @@ core: # PLEASE give valid JSON component here else the core don't refill at all customName: '[{"text":"ChomeNS ","color":"yellow"},{"text":"Core","color":"green"},{"text":"™","color":"gold"}]' selfCare: - checkInterval: 1000, + checkInterval: 1000 # vanilla op: true @@ -45,9 +45,12 @@ selfCare: socialspy: true mute: true - # extras + # commandspy cspy: true + + # extras prefix: true + username: true # do NOT set this to false unless you know what you are doing bots: # username and kaboom are optional. # for username if it doesn't exist it will default to random username