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 cfbc842..4482c50 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,6 +52,8 @@ public class CorePlugin extends PositionPlugin.Listener { private int nextTransactionId = 0; private final Map> transactions = new HashMap<>(); + private final List afterTicks = new ArrayList<>(); + private final boolean kaboom; private int commandsPerSecond = 0; @@ -163,9 +165,7 @@ public class CorePlugin extends PositionPlugin.Listener { final CompletableFuture future = new CompletableFuture<>(); transactions.put(transactionId, future); - final Runnable afterTick = () -> bot.session.send(new ServerboundBlockEntityTagQuery(transactionId, beforeBlock)); - - bot.executor.schedule(afterTick, 50, TimeUnit.MILLISECONDS); + afterTicks.add(() -> bot.session.send(new ServerboundBlockEntityTagQuery(transactionId, beforeBlock))); return future; } @@ -199,7 +199,15 @@ public class CorePlugin extends PositionPlugin.Listener { public void packetReceived (ClientboundBlockUpdatePacket packet) { final BlockChangeEntry entry = packet.getEntry(); - if (isCommandBlockUpdate(entry.getBlock())) return; + if (isCommandBlockUpdate(entry.getBlock())) { + for (Runnable runnable : afterTicks) { + runnable.run(); + } + + afterTicks.clear(); + + return; + } final Vector3i position = entry.getPosition(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PositionPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PositionPlugin.java index eed52c9..5f15a69 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PositionPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PositionPlugin.java @@ -7,6 +7,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.Client import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddPlayerPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket; +import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosPacket; import com.github.steveice10.packetlib.Session; import com.github.steveice10.packetlib.packet.Packet; import land.chipmunk.chayapak.chomens_bot.Bot; @@ -19,6 +20,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; // some part of the code used to be in a test plugin but i thought it would be useful in the future so i moved it here public class PositionPlugin extends Bot.Listener { @@ -34,7 +36,16 @@ public class PositionPlugin extends Bot.Listener { public PositionPlugin (Bot bot) { this.bot = bot; + bot.addListener(this); + + // notchian clients also does this, sends the position packet every second + bot.executor.scheduleAtFixedRate(() -> bot.session.send(new ServerboundMovePlayerPosPacket( + false, + position.getX(), + position.getY(), + position.getZ() + )), 0, 1, TimeUnit.SECONDS); } @Override