diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java index d14ee96..eea3829 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java @@ -30,10 +30,7 @@ import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import org.cloudburstmc.math.vector.Vector3i; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -55,6 +52,8 @@ public class CorePlugin extends PositionPlugin.Listener { public Vector3i block = null; + public final List placeBlockQueue = Collections.synchronizedList(new ArrayList<>()); + private int nextTransactionId = 0; private final Map> transactions = new HashMap<>(); @@ -120,6 +119,27 @@ public class CorePlugin extends PositionPlugin.Listener { return CorePlugin.this.systemMessageReceived(component); } }); + + bot.tick.addListener(new TickPlugin.Listener() { + @Override + public void onTick() { + try { + final List clonedQueue = new ArrayList<>(placeBlockQueue); + + if (clonedQueue.isEmpty()) return; + + if (clonedQueue.size() > 500) { + placeBlockQueue.clear(); + return; + } + + forceRunPlaceBlock(clonedQueue.get(0)); + placeBlockQueue.remove(0); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); } public boolean hasRateLimit () { @@ -258,6 +278,10 @@ public class CorePlugin extends PositionPlugin.Listener { } public void runPlaceBlock (String command) { + bot.executorService.submit(() -> placeBlockQueue.add(command)); + } + + private void forceRunPlaceBlock (String command) { if (!ready || !bot.options.useCore) return; final NbtMapBuilder blockEntityTagBuilder = NbtMap.builder(); diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/IPFilterPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/IPFilterPlugin.java index e15413e..6ebb438 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/IPFilterPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/IPFilterPlugin.java @@ -36,6 +36,8 @@ public class IPFilterPlugin extends PlayersPlugin.Listener { } private void check (PlayerEntry target) { + if (bot.options.useCorePlaceBlock) return; // it will spam the place block core so i ignored this + final CompletableFuture future = bot.players.getPlayerIP(target); if (future == null) return;