feat: core place block queue

This commit is contained in:
Chayapak 2024-11-17 17:49:06 +07:00
parent 9f10ca8a3e
commit 6c507219f2
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA
2 changed files with 30 additions and 4 deletions

View file

@ -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<String> placeBlockQueue = Collections.synchronizedList(new ArrayList<>());
private int nextTransactionId = 0;
private final Map<Integer, CompletableFuture<Component>> 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<String> 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();

View file

@ -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<String> future = bot.players.getPlayerIP(target);
if (future == null) return;