From 7eeec7ca00cf07152669dfb086dc874660d97997 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 23 Apr 2023 07:24:12 +0700 Subject: [PATCH] improve bot options? mabe mabe --- .idea/uiDesigner.xml | 124 ++++++++++++++ .idea/workspace.xml | 153 +++++++++--------- .../chipmunk/chayapak/chomens_bot/Bot.java | 30 ++-- .../chayapak/chomens_bot/Configuration.java | 4 +- .../chipmunk/chayapak/chomens_bot/Main.java | 15 +- .../chomens_bot/plugins/ChatPlugin.java | 2 +- .../chomens_bot/plugins/CorePlugin.java | 4 +- .../chomens_bot/plugins/SelfCarePlugin.java | 22 +-- .../chomens_bot/plugins/TrustedPlugin.java | 2 +- 9 files changed, 239 insertions(+), 117 deletions(-) create mode 100644 .idea/uiDesigner.xml diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9aa3c88..b5d027f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,7 +4,16 @@ - - - - - - - @@ -478,7 +480,14 @@ - diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java index 63397ec..66925f7 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java @@ -23,15 +23,13 @@ public class Bot { @Getter private final String host; @Getter private final int port; - private final String _username; - @Getter private final boolean kaboom; - @Getter private final String serverName; - @Getter @Setter private boolean useCore; - @Getter @Setter private boolean useChat; - @Getter private final boolean hasEssentials; - @Getter private final List allBots; + + @Getter private final Configuration.BotOption options; + @Getter private final Configuration config; + @Getter private List allBots; + @Getter private String username; @Getter public Session session; @@ -65,16 +63,14 @@ public class Bot { @Getter private MazePlugin maze; @Getter private ExploitsPlugin exploits; - public Bot (String host, int port, String _username, boolean kaboom, String serverName, boolean useCore, boolean useChat, boolean hasEssentials, List allBots, Configuration config) { - this.host = host; - this.port = port; - this._username = _username; - this.kaboom = kaboom; - this.serverName = serverName; - this.useCore = useCore; - this.useChat = useChat; - this.hasEssentials = hasEssentials; + public Bot (Configuration.BotOption botOption, List allBots, Configuration config) { + this.host = botOption.host; + this.port = botOption.port; + + this.options = botOption; + this.allBots = allBots; + this.config = config; ConsolePlugin.addListener(new ConsolePlugin.Listener() { @@ -111,6 +107,8 @@ public class Bot { } public void reconnect () { + final String _username = options.username(); + if (_username == null) username = RandomStringUtils.randomAlphabetic(8); else username = _username; 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 e4ae346..4e09511 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java @@ -26,7 +26,7 @@ public class Configuration { @Getter public List trusted = new ArrayList<>(); @Getter public SelfCare selfCare = new SelfCare(); - @Getter public Bots[] bots = new Bots[]{}; + @Getter public BotOption[] bots = new BotOption[]{}; public static class Core { @Getter public int layers = 3; @@ -73,7 +73,7 @@ public class Configuration { @Getter public int positionPacketsPerSecond = 10; } - public static class Bots { + public static class BotOption { @Getter public String host; @Getter public int port; @Getter public String username; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java index 3bfaf88..a6ff9ee 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Main.java @@ -48,7 +48,7 @@ public class Main { final Configuration config = _config; - Configuration.Bots[] botsOptions = config.bots(); + Configuration.BotOption[] botsOptions = config.bots(); // idk if these should be here lol, but it is just the discord stuff JDA jda = null; @@ -64,17 +64,8 @@ public class Main { System.exit(1); } - for (Configuration.Bots botOption : botsOptions) { - final String host = botOption.host(); - final int port = botOption.port(); - final String username = botOption.username(); - final boolean kaboom = botOption.kaboom(); - final String serverName = botOption.serverName(); - final boolean useCore = botOption.useCore(); - final boolean useChat = botOption.useChat(); - final boolean hasEssentials = botOption.hasEssentials(); - - final Bot bot = new Bot(host, port, username, kaboom, serverName, useCore, useChat, hasEssentials, allBots, config); + for (Configuration.BotOption botOption : botsOptions) { + final Bot bot = new Bot(botOption, allBots, config); allBots.add(bot); } 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 704eef2..62b1c6a 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 @@ -181,7 +181,7 @@ public class ChatPlugin extends SessionAdapter { } public void tellraw (Component component, String targets) { - if (bot.useChat()) { + if (bot.options().useChat()) { if (!targets.equals("@a")) return; // worst fix of all time!1! final String stringified = ComponentUtilities.stringifyMotd(component).replace("ยง", "&"); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java index 6db028f..d7f3072 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java @@ -54,7 +54,7 @@ public class CorePlugin extends PositionPlugin.PositionListener { public CorePlugin (Bot bot) { this.bot = bot; - this.kaboom = bot.kaboom(); + this.kaboom = bot.options().kaboom(); bot.position().addListener(this); @@ -78,7 +78,7 @@ public class CorePlugin extends PositionPlugin.PositionListener { public void run (String command) { if (!ready) return; - if (bot.useCore()) { + if (bot.options().useCore()) { bot.session().send(new ServerboundSetCommandBlockPacket( absoluteCorePosition(), command, 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 48a18c3..1322ff1 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 @@ -92,24 +92,24 @@ public class SelfCarePlugin extends SessionAdapter { if (selfCares.gamemode() && gamemode != GameMode.CREATIVE) bot.chat().send("/minecraft:gamemode creative @s[type=player]"); else if (selfCares.op() && permissionLevel < 2) bot.chat().send("/minecraft:op @s[type=player]"); - else if (selfCares.cspy() && !cspy && bot.kaboom()) bot.chat().send("/commandspy:commandspy on"); - 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()); + else if (selfCares.cspy() && !cspy && bot.options().kaboom()) bot.chat().send("/commandspy:commandspy on"); + else if (selfCares.prefix() && !prefix && bot.options().kaboom()) bot.chat().send("/extras:prefix &8[&eChomeNS Bot&8]"); + else if (selfCares.username() && !username && bot.options().kaboom()) bot.chat().send("/extras:username " + bot.username()); else if (selfCares.icu().enabled() && positionPacketsPerSecond > selfCares.icu().positionPacketsPerSecond()) bot.core().run("essentials:sudo * icu stop"); - else if (selfCares.vanish() && !vanish && !visibility && bot.hasEssentials()) { - if (bot.useChat()) bot.chat().send("/essentials:vanish enable"); + else if (selfCares.vanish() && !vanish && !visibility && bot.options().hasEssentials()) { + if (bot.options().useChat()) bot.chat().send("/essentials:vanish enable"); else bot.core().run("essentials:vanish " + bot.username() + " enable"); } - else if (selfCares.nickname() && !nickname && bot.hasEssentials()) { - if (bot.useChat()) bot.chat().send("/essentials:nickname off"); + else if (selfCares.nickname() && !nickname && bot.options().hasEssentials()) { + if (bot.options().useChat()) bot.chat().send("/essentials:nickname off"); else bot.core().run("essentials:nickname " + bot.username() + " off"); } - else if (selfCares.socialspy() && !socialspy && bot.hasEssentials()) { - if (bot.useChat()) bot.chat().send("/essentials:socialspy enable"); + else if (selfCares.socialspy() && !socialspy && bot.options().hasEssentials()) { + if (bot.options().useChat()) bot.chat().send("/essentials:socialspy enable"); else bot.core().run("essentials:socialspy " + bot.username() + " enable"); } - else if (selfCares.mute() && muted && bot.hasEssentials()) { - if (bot.useChat()) bot.chat().send("/essentials:mute " + bot.username()); + else if (selfCares.mute() && muted && bot.options().hasEssentials()) { + if (bot.options().useChat()) bot.chat().send("/essentials:mute " + bot.username()); else bot.core().run("essentials:mute " + bot.username()); } } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java index 0ab93aa..7cf3eef 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java @@ -36,7 +36,7 @@ public class TrustedPlugin extends PlayersPlugin.PlayerListener { final Component component = Component.translatable( "[%s] [%s] %s", Component.text("ChomeNS Bot").color(NamedTextColor.YELLOW), - Component.text(this.bot.serverName()).color(NamedTextColor.GRAY), + Component.text(this.bot.options().serverName()).color(NamedTextColor.GRAY), message.color(NamedTextColor.WHITE) ).color(NamedTextColor.DARK_GRAY);