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 90b1642..7482bc0 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java @@ -54,7 +54,6 @@ public class Bot { public CommandSpyPlugin commandSpy; public PositionPlugin position; public ServerPluginsManagerPlugin serverPluginsManager; - public PluginCheckerPlugin pluginChecker; public SelfCarePlugin selfCare; public CorePlugin core; public TeamPlugin team; @@ -103,7 +102,6 @@ public class Bot { this.commandSpy = new CommandSpyPlugin(this); this.position = new PositionPlugin(this); this.serverPluginsManager = new ServerPluginsManagerPlugin(this); - this.pluginChecker = new PluginCheckerPlugin(this); this.selfCare = new SelfCarePlugin(this); this.core = new CorePlugin(this); this.team = new TeamPlugin(this); 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 4a82c89..9eaffe6 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 @@ -122,7 +122,7 @@ public class CorePlugin extends PositionPlugin.Listener { } private void forceRun (String command) { - if (bot.pluginChecker.hasExtras) { + if (bot.serverPluginsManager.hasPlugin(ServerPluginsManagerPlugin.EXTRAS)) { bot.session.send(new ServerboundSetCommandBlockPacket( block, command, @@ -205,7 +205,18 @@ public class CorePlugin extends PositionPlugin.Listener { ); final Session session = bot.session; - session.send(new ServerboundSetCreativeModeSlotPacket(36, new ItemStack(bot.pluginChecker.hasExtras ? 492 /* repeating command block id */ : 373 /* command block id */, 64, tag))); + session.send( + new ServerboundSetCreativeModeSlotPacket( + 36, + new ItemStack( + bot.serverPluginsManager.hasPlugin(ServerPluginsManagerPlugin.EXTRAS) ? + 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 deleted file mode 100644 index a6d08cb..0000000 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PluginCheckerPlugin.java +++ /dev/null @@ -1,18 +0,0 @@ -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 06cb680..2bf9d9d 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,7 +86,8 @@ public class SelfCarePlugin extends Bot.Listener { public void check () { final Configuration.SelfCare selfCares = bot.config.selfCare; - final boolean kaboom = bot.pluginChecker.hasExtras; + final boolean kaboom = bot.serverPluginsManager.hasPlugin(ServerPluginsManagerPlugin.EXTRAS); + final boolean hasEssentials = bot.serverPluginsManager.hasPlugin(ServerPluginsManagerPlugin.ESSENTIALS); // chat only if (selfCares.op && permissionLevel < 2) bot.chat.send("/minecraft:op @s[type=player]"); @@ -96,25 +97,25 @@ public class SelfCarePlugin extends Bot.Listener { else if (selfCares.username && !username && kaboom) bot.chat.send("/extras:username " + bot.username); // core - // 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.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.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.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.pluginChecker.hasEssentials) { - if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:mute " + bot.profile.getIdAsString()); - else bot.core.run("essentials:mute " + bot.profile.getIdAsString()); + else if (hasEssentials) { + // TODO: improve lol, this is ohio - muted = false; // too lazy fix and probably the worst fix? + if (selfCares.vanish && !vanish && !visibility) { + if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:vanish enable"); + else bot.core.run("essentials:vanish " + bot.username + " enable"); + } else if (selfCares.nickname && !nickname) { + if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:nick off"); + else bot.core.run("essentials:nickname " + bot.username + " off"); + } else if (selfCares.socialspy && !socialspy) { + if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:socialspy enable"); + else bot.core.run("essentials:socialspy " + bot.username + " enable"); + } else if (selfCares.mute && muted) { + if (bot.options.useChat) bot.chat.sendCommandInstantly("essentials:mute " + bot.profile.getIdAsString()); + else bot.core.run("essentials:mute " + bot.profile.getIdAsString()); + + muted = false; // too lazy fix + } } } 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 index df4c00f..9821c2b 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ServerPluginsManagerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ServerPluginsManagerPlugin.java @@ -10,6 +10,9 @@ import java.util.List; import java.util.concurrent.CompletableFuture; public class ServerPluginsManagerPlugin extends Bot.Listener { + public static final String EXTRAS = "Extras"; + public static final String ESSENTIALS = "Essentials"; + private final Bot bot; public List plugins = new ArrayList<>(); @@ -33,4 +36,6 @@ public class ServerPluginsManagerPlugin extends Bot.Listener { return packet; }); } + + public boolean hasPlugin (String plugin) { return plugins.contains(plugin); } }