From 848efd343100bbf3850c32e2148754f8503efead Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Tue, 15 Aug 2023 19:51:25 +0700 Subject: [PATCH] remove kaboom and hasEssentials from config and make it d y n a m i c --- .../chipmunk/chayapak/chomens_bot/Bot.java | 4 +++ .../chayapak/chomens_bot/Configuration.java | 2 -- .../chomens_bot/plugins/CorePlugin.java | 7 ++-- .../plugins/PluginCheckerPlugin.java | 18 ++++++++++ .../chomens_bot/plugins/SelfCarePlugin.java | 18 +++++----- .../plugins/ServerPluginsManagerPlugin.java | 36 +++++++++++++++++++ src/main/resources/default-config.yml | 6 +--- 7 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PluginCheckerPlugin.java create mode 100644 src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ServerPluginsManagerPlugin.java 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 2799af2..fcf4eb3 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java @@ -75,6 +75,8 @@ public class Bot { public PacketSnifferPlugin packetSniffer; public VoiceChatPlugin voiceChat; public TagPlugin tag; + public ServerPluginsManagerPlugin serverPluginsManager; + public PluginCheckerPlugin pluginChecker; public Bot (Configuration.BotOption botOption, List bots, Configuration config) { this.host = botOption.host; @@ -121,6 +123,8 @@ public class Bot { this.packetSniffer = new PacketSnifferPlugin(this); this.voiceChat = new VoiceChatPlugin(this); this.tag = new TagPlugin(this); + this.serverPluginsManager = new ServerPluginsManagerPlugin(this); + this.pluginChecker = new PluginCheckerPlugin(this); for (Listener listener : listeners) listener.loadedPlugins(); 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 04b7d88..ca9b3e2 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java @@ -127,12 +127,10 @@ public class Configuration { public String host; public int port; public String username; - public boolean kaboom = false; public boolean creayun = false; public String serverName; public boolean useCore = true; public boolean useChat = false; - public boolean hasEssentials = true; public int reconnectDelay = 2000; public boolean removeNamespaces = false; public int chatQueueDelay = 125; 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 6905639..fbdcfdd 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 @@ -52,15 +52,12 @@ public class CorePlugin extends PositionPlugin.Listener { private int nextTransactionId = 0; private final Map> transactions = new HashMap<>(); - private final boolean kaboom; - private int commandsPerSecond = 0; private boolean shouldRefill = false; public CorePlugin (Bot bot) { this.bot = bot; - this.kaboom = bot.options.kaboom; this.fromSize = Vector3i.from( bot.config.core.start.x, @@ -124,7 +121,7 @@ public class CorePlugin extends PositionPlugin.Listener { } private void forceRun (String command) { - if (kaboom) { + if (bot.pluginChecker.hasExtras) { bot.session.send(new ServerboundSetCommandBlockPacket( block, command, @@ -207,7 +204,7 @@ public class CorePlugin extends PositionPlugin.Listener { ); final Session session = bot.session; - session.send(new ServerboundSetCreativeModeSlotPacket(36, new ItemStack(kaboom ? 492 /* repeating command block id */ : 373 /* command block id */, 64, tag))); + session.send(new ServerboundSetCreativeModeSlotPacket(36, new ItemStack(bot.pluginChecker.hasExtras ? 492 /* repeating command block id */ : 373 /* command block id */, 64, tag))); session.send(new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, temporaryBlockPosition, Direction.NORTH, 0)); session.send(new ServerboundUseItemOnPacket(temporaryBlockPosition, Direction.UP, Hand.MAIN_HAND, 0.5f, 0.5f, 0.5f, false, 1)); } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PluginCheckerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PluginCheckerPlugin.java new file mode 100644 index 0000000..a6d08cb --- /dev/null +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PluginCheckerPlugin.java @@ -0,0 +1,18 @@ +package land.chipmunk.chayapak.chomens_bot.plugins; + +import land.chipmunk.chayapak.chomens_bot.Bot; + +import java.util.concurrent.TimeUnit; + +public class PluginCheckerPlugin extends Bot.Listener { + public boolean hasExtras; + public boolean hasEssentials; + + public PluginCheckerPlugin(Bot bot) { + // dumb + bot.executor.scheduleAtFixedRate(() -> { + hasExtras = bot.serverPluginsManager.plugins.contains("Extras"); + hasEssentials = bot.serverPluginsManager.plugins.contains("Essentials"); + }, 0, 5, TimeUnit.SECONDS); + } +} 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 7cbc697..06cb680 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 @@ -86,29 +86,31 @@ public class SelfCarePlugin extends Bot.Listener { public void check () { final Configuration.SelfCare selfCares = bot.config.selfCare; + final boolean kaboom = bot.pluginChecker.hasExtras; + // chat only if (selfCares.op && permissionLevel < 2) bot.chat.send("/minecraft:op @s[type=player]"); else if (selfCares.gamemode && gamemode != GameMode.CREATIVE) bot.chat.send("/minecraft:gamemode creative @s[type=player]"); - else if (selfCares.cspy && !cspy && bot.options.kaboom) bot.chat.send("/commandspy:commandspy on"); - else if (selfCares.prefix.enabled && !prefix && bot.options.kaboom) bot.chat.send("/extras:prefix " + bot.config.selfCare.prefix.prefix); - else if (selfCares.username && !username && bot.options.kaboom) bot.chat.send("/extras:username " + bot.username); + else if (selfCares.cspy && !cspy && kaboom) bot.chat.send("/commandspy:commandspy on"); + else if (selfCares.prefix.enabled && !prefix && kaboom) bot.chat.send("/extras:prefix " + bot.config.selfCare.prefix.prefix); + else if (selfCares.username && !username && kaboom) bot.chat.send("/extras:username " + bot.username); // core - // TODO: improve lol + // TODO: improve lol, this is ohio else if (selfCares.icu.enabled && positionPacketsPerSecond > selfCares.icu.positionPacketsPerSecond) bot.core.run("essentials:sudo * icu stop"); - else if (selfCares.vanish && !vanish && !visibility && bot.options.hasEssentials) { + else if (selfCares.vanish && !vanish && !visibility && bot.pluginChecker.hasEssentials) { if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:vanish enable"); else bot.core.run("essentials:vanish " + bot.username + " enable"); } - else if (selfCares.nickname && !nickname && bot.options.hasEssentials) { + else if (selfCares.nickname && !nickname && bot.pluginChecker.hasEssentials) { if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:nick off"); else bot.core.run("essentials:nickname " + bot.username + " off"); } - else if (selfCares.socialspy && !socialspy && bot.options.hasEssentials) { + else if (selfCares.socialspy && !socialspy && bot.pluginChecker.hasEssentials) { if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:socialspy enable"); else bot.core.run("essentials:socialspy " + bot.username + " enable"); } - else if (selfCares.mute && muted && bot.options.hasEssentials) { + else if (selfCares.mute && muted && bot.pluginChecker.hasEssentials) { if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:mute " + bot.profile.getIdAsString()); else bot.core.run("essentials:mute " + bot.profile.getIdAsString()); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ServerPluginsManagerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ServerPluginsManagerPlugin.java new file mode 100644 index 0000000..df4c00f --- /dev/null +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ServerPluginsManagerPlugin.java @@ -0,0 +1,36 @@ +package land.chipmunk.chayapak.chomens_bot.plugins; + +import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundCommandSuggestionsPacket; +import com.github.steveice10.packetlib.event.session.ConnectedEvent; +import land.chipmunk.chayapak.chomens_bot.Bot; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class ServerPluginsManagerPlugin extends Bot.Listener { + private final Bot bot; + + public List plugins = new ArrayList<>(); + + public ServerPluginsManagerPlugin (Bot bot) { + this.bot = bot; + + bot.addListener(this); + } + + @Override + public void connected(ConnectedEvent event) { + final CompletableFuture future = bot.tabComplete.tabComplete("/ver "); + + future.thenApply((packet) -> { + final String[] matches = packet.getMatches(); + + // should i just use the plugins as the String array instead of a list? + plugins = new ArrayList<>(Arrays.asList(matches)); + + return packet; + }); + } +} diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index 27cb88f..9c1b9ee 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -101,24 +101,20 @@ eval: bots: # username - optional, if not specified it will just use a random username - # kaboom - defaults to false - # creayun - same as kaboom + # creayun - defaults to false # serverName - name it whatever you like, it will be used as server name in trusted broadcast and in console # useCore - if enabled it just sends the command using chat instead of using core. recommended to enable useChat too when this is enabled # useChat - when the bot tellraws it will chat instead of using the core to run tellraw - # hasEssentials - if the server has essentials plugin just set it to true!! ! !!31 # removeNamespaces - when the bot sends a command it will remove like `minecraft:` for example if set to true # coreRateLimit - will ignore commands if reached the ratelimit - host: 'localhost' port: 25565 username: 'ChomeNS_Bot' - kaboom: false creayun: false serverName: 'Localhost' useCore: true useChat: false - hasEssentials: false reconnectDelay: 2000 removeNamespaces: false chatQueueDelay: 125