diff --git a/src/main/java/me/trouper/butler/commands/SwarmManager.java b/src/main/java/me/trouper/butler/commands/SwarmManager.java index b04545d..f1ae57a 100644 --- a/src/main/java/me/trouper/butler/commands/SwarmManager.java +++ b/src/main/java/me/trouper/butler/commands/SwarmManager.java @@ -1,11 +1,9 @@ package me.trouper.butler.commands; -import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.DoubleArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import io.netty.util.concurrent.CompleteFuture; import me.trouper.butler.modules.SwarmPlusMaster; import me.trouper.butler.server.Connection; import me.trouper.butler.utils.MathUtils; @@ -15,28 +13,29 @@ import meteordevelopment.meteorclient.commands.arguments.ModuleArgumentType; import meteordevelopment.meteorclient.commands.arguments.PlayerArgumentType; import meteordevelopment.meteorclient.commands.arguments.SettingArgumentType; import meteordevelopment.meteorclient.commands.arguments.SettingValueArgumentType; -import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.systems.modules.Module; -import net.minecraft.client.MinecraftClient; import net.minecraft.command.CommandSource; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; import java.awt.geom.Point2D; import java.util.List; -import java.util.Random; -import java.util.concurrent.*; import static com.mojang.brigadier.Command.SINGLE_SUCCESS; public class SwarmManager extends Command { public SwarmManager() { - super("manager", "Sends a message."); + super("manager", "Control your Hive"); } private static boolean circling = false; + /* + Welcome to the tree-of-hell (Supported by ImproperIssues, this 350+ line nested tree is supposedly "perfectly fine" and the proper way to code this) + The easiest way to navigate it is to Ctrl+f the branch you want to go to. + Scrolling through this is NOT fun. + */ + @Override public void build(LiteralArgumentBuilder builder) { builder.then(literal("chat") @@ -52,6 +51,10 @@ public class SwarmManager extends Command { })) ) .then(literal("list").executes(context -> { + if (SwarmPlusMaster.swarmServer == null) { + error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!"); + return SINGLE_SUCCESS; + } List connections = SwarmPlusMaster.swarmServer.getConnections().stream().toList(); StringBuilder connectionList = new StringBuilder(); int pointer = 0; @@ -59,22 +62,19 @@ public class SwarmManager extends Command { pointer++; connectionList.append("\n%s: %s on %s".formatted(pointer, connection.getClientSideName(),connection.getAddress())); } - info("Swarm connections: " + connectionList.toString()); + info("Swarm connections: " + connectionList); return SINGLE_SUCCESS; })) .then(literal("kick").then(argument("target",StringArgumentType.string()) .executes(context -> { - String target = context.getArgument("target", String.class); if (SwarmPlusMaster.swarmServer == null) { error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!"); return SINGLE_SUCCESS; } - //info("Looping %s connections".formatted(SwarmPlusMaster.swarmServer.connectionCount())); + String target = context.getArgument("target", String.class); for (Connection connection : SwarmPlusMaster.swarmServer.getConnections()) { - //info("Looping connections: %s user %s".formatted(connection.getAddress(),connection.getClientSideName())); if (connection.getClientSideName().equals(target)) connection.disconnect(); - //info("Disconnected %s".formatted(target),"DO YOU NEED AN ARGUMENT AGAIN?????"); } return SINGLE_SUCCESS; })) @@ -123,6 +123,7 @@ public class SwarmManager extends Command { error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!"); return SINGLE_SUCCESS; } + Module module = ModuleArgumentType.get(context); Setting setting = SettingArgumentType.get(context); String value = SettingValueArgumentType.get(context); @@ -146,6 +147,7 @@ public class SwarmManager extends Command { error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!"); return SINGLE_SUCCESS; } + int rad = context.getArgument("radius",Integer.class); int n = SwarmPlusMaster.swarmServer.connectionCount(); Point2D.Double[] distribution = MathUtils.distributePoints(MeteorClient.mc.player.getX(),MeteorClient.mc.player.getZ(),rad,n); @@ -166,14 +168,17 @@ public class SwarmManager extends Command { error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!"); return SINGLE_SUCCESS; } + int roundX = (int) Math.round(MeteorClient.mc.player.getX()); int roundY = (int) Math.round(MeteorClient.mc.player.getY()); int roundZ = (int) Math.round(MeteorClient.mc.player.getZ()); + SwarmPlusMaster.swarmServer.broadcast("[BARITONE] gotoxyz %s %s %s".formatted( roundX, roundY, roundZ )); + SwarmManager.this.info("Pathing (highlight)all bots(default) to the host."); return SINGLE_SUCCESS; }) @@ -183,10 +188,12 @@ public class SwarmManager extends Command { error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!"); return SINGLE_SUCCESS; } + String target = StringArgumentType.getString(context,"target"); int roundX = (int) Math.round(MeteorClient.mc.player.getX()); int roundY = (int) Math.round(MeteorClient.mc.player.getY()); int roundZ = (int) Math.round(MeteorClient.mc.player.getZ()); + for (Connection connection : SwarmPlusMaster.swarmServer.getConnections().stream().toList()) { if (!connection.getClientSideName().equalsIgnoreCase(target)) continue; connection.sendMessage("[BARITONE] gotoxyz %s %s %s".formatted( @@ -197,6 +204,7 @@ public class SwarmManager extends Command { SwarmManager.this.info("Pathing (highlight)%s(default) to the host.",target); return SINGLE_SUCCESS; } + SwarmManager.this.error("Could not find a connection with the name (highlight)%s",target); return SINGLE_SUCCESS; })) @@ -222,10 +230,12 @@ public class SwarmManager extends Command { error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!"); return SINGLE_SUCCESS; } + SwarmPlusMaster.swarmServer.broadcast("[BARITONE] gotoxz %s %s".formatted( IntegerArgumentType.getInteger(context,"x"), IntegerArgumentType.getInteger(context,"z") )); + SwarmManager.this.info("Pathing all bots to (highlight)%s %s", IntegerArgumentType.getInteger(context,"x"), IntegerArgumentType.getInteger(context,"z")); @@ -239,11 +249,13 @@ public class SwarmManager extends Command { error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!"); return SINGLE_SUCCESS; } + SwarmPlusMaster.swarmServer.broadcast("[BARITONE] gotoxyz %s %s %s".formatted( IntegerArgumentType.getInteger(context,"x"), IntegerArgumentType.getInteger(context,"y"), IntegerArgumentType.getInteger(context,"z") )); + SwarmManager.this.info("Pathing all bots to (highlight)%s %s %s", IntegerArgumentType.getInteger(context,"x"), IntegerArgumentType.getInteger(context,"y"), @@ -261,9 +273,11 @@ public class SwarmManager extends Command { error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!"); return SINGLE_SUCCESS; } + SwarmPlusMaster.swarmServer.broadcast("[LOOK] absolute %s %s".formatted( context.getArgument("pitch",double.class), context.getArgument("yaw",double.class))); + SwarmManager.this.info("Bots now facing (highlight)%s %s", context.getArgument("pitch",double.class), context.getArgument("yaw",double.class)); @@ -278,6 +292,7 @@ public class SwarmManager extends Command { error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!"); return SINGLE_SUCCESS; } + SwarmPlusMaster.swarmServer.broadcast("[LOOK] player %s".formatted(context.getArgument("target",PlayerEntity.class).getName().getString())); SwarmManager.this.info("Bots now targeting (highlight)%s",context.getArgument("target",PlayerEntity.class).getName().getString()); return SINGLE_SUCCESS; @@ -291,11 +306,32 @@ public class SwarmManager extends Command { error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!"); return SINGLE_SUCCESS; } + PlayerEntity pe = PlayerArgumentType.get(context); SwarmPlusMaster.swarmServer.broadcast("[BARITONE] follow %s".formatted(pe.getName().getString())); SwarmManager.this.info("Bots now following (highlight)%s(default).",pe.getName().getString()); return SINGLE_SUCCESS; }) + .then(literal("snake") + .executes(context -> { + if (SwarmPlusMaster.swarmServer == null) { + error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!"); + return SINGLE_SUCCESS; + } + + String pointer = MeteorClient.mc.player.getName().getString(); + StringBuilder lineOrder = new StringBuilder("Line order: "); + lineOrder.append("%s <- ".formatted(pointer)); + + for (Connection connection : SwarmPlusMaster.swarmServer.getConnections()) { + lineOrder.append("%s <- ".formatted(pointer)); + connection.sendMessage("[BARITONE] follow %s".formatted(pointer)); + pointer = connection.getClientSideName(); + } + + SwarmManager.this.info("Bots are now following in a snake. " + lineOrder); + return SINGLE_SUCCESS; + })) .then(literal("circle") .then(argument("radius",IntegerArgumentType.integer(1)) .then(argument("update-freq", IntegerArgumentType.integer(0,10000)) @@ -308,35 +344,36 @@ public class SwarmManager extends Command { circling = !circling; SwarmManager.this.info("Bots are %s circling (highlight)%s(default).",circling ? "now" : "no longer", pe.getName().getString()); - if (circling) { - int delay = IntegerArgumentType.getInteger(context,"update-freq"); - if (delay <= 0){ - SwarmManager.this.error("CHECK YOUR CONSOLE BOI + INVALID INTEGER INPUT"); - return SINGLE_SUCCESS; - } + if (!circling) return SINGLE_SUCCESS; - Thread thread = new Thread(() -> { - while (circling) { - try { - int rad = context.getArgument("radius",Integer.class); - int n = SwarmPlusMaster.swarmServer.connectionCount(); - Point2D.Double[] distribution = MathUtils.distributePoints(MeteorClient.mc.player.getX(),MeteorClient.mc.player.getZ(),rad,n); - int index = 0; - for (Connection connection : SwarmPlusMaster.swarmServer.getConnections()) { - int x = (int) Math.round(distribution[index].x); - int z = (int) Math.round(distribution[index].y); - connection.sendMessage("[BARITONE] gotoxz %s %s".formatted(x,z)); - index++; - } - Thread.sleep(delay); - } catch (Exception ex) { - ex.printStackTrace(); - SwarmManager.this.error("CHECK YOUR CONSOLE BOI"); - } - } - }); - thread.start(); + int delay = IntegerArgumentType.getInteger(context,"update-freq"); + if (delay <= 0){ + SwarmManager.this.error("CHECK YOUR CONSOLE BOI + INVALID INTEGER INPUT"); + return SINGLE_SUCCESS; } + + Thread thread = new Thread(() -> { + while (circling) { + try { + int rad = context.getArgument("radius",Integer.class); + int n = SwarmPlusMaster.swarmServer.connectionCount(); + Point2D.Double[] distribution = MathUtils.distributePoints(MeteorClient.mc.player.getX(),MeteorClient.mc.player.getZ(),rad,n); + int index = 0; + for (Connection connection : SwarmPlusMaster.swarmServer.getConnections()) { + int x = (int) Math.round(distribution[index].x); + int z = (int) Math.round(distribution[index].y); + connection.sendMessage("[BARITONE] gotoxz %s %s".formatted(x,z)); + index++; + } + Thread.sleep(delay); + } catch (Exception ex) { + ex.printStackTrace(); + SwarmManager.this.error("CHECK YOUR CONSOLE BOI"); + } + } + }); + thread.start(); + return SINGLE_SUCCESS; })) ) @@ -352,6 +389,7 @@ public class SwarmManager extends Command { return SINGLE_SUCCESS; })) .then(literal("stop").executes(context -> { + circling = false; SwarmPlusMaster.swarmServer.broadcast("[STOP]"); return SINGLE_SUCCESS; })) diff --git a/src/main/java/me/trouper/butler/modules/SwarmPlusWorker.java b/src/main/java/me/trouper/butler/modules/SwarmPlusWorker.java index dd76405..81ed558 100644 --- a/src/main/java/me/trouper/butler/modules/SwarmPlusWorker.java +++ b/src/main/java/me/trouper/butler/modules/SwarmPlusWorker.java @@ -7,6 +7,7 @@ import me.trouper.butler.server.Response; import me.trouper.butler.utils.MathUtils; import me.trouper.butler.utils.Text; import meteordevelopment.meteorclient.MeteorClient; +import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.config.Config; import meteordevelopment.meteorclient.systems.modules.Module; @@ -146,7 +147,7 @@ public class SwarmPlusWorker extends Module { System.exit(0); } default -> { - SwarmPlusWorker.this.error("An error occurred when receiving a packet from the host. (highlight)%s",full); + SwarmPlusWorker.this.error("An error occurred when receiving a packet from the host. (highlight)%s", full); } } }