From 3d0ceb4eb963c4e761754c8b55667534293402f2 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 9 Feb 2022 13:07:39 +0000 Subject: [PATCH] Add a count for chunks we're currently trying to load to not skip chunks at the end of a queue's edit --- .../plotsquared/bukkit/queue/BukkitChunkCoordinator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitChunkCoordinator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitChunkCoordinator.java index fc1dca0da..a6e5c7fe0 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitChunkCoordinator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitChunkCoordinator.java @@ -74,12 +74,13 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator { private final Consumer throwableConsumer; private final boolean unloadAfter; private final int totalSize; - private final AtomicInteger expectedSize; + private int batchSize; private PlotSquaredTask task; private boolean shouldCancel; private boolean finished; + private int loadingChunks = 0; @Inject private BukkitChunkCoordinator( @@ -151,7 +152,7 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator { Chunk chunk = this.availableChunks.poll(); if (chunk == null) { if (this.availableChunks.isEmpty()) { - if (this.requestedChunks.isEmpty()) { + if (this.requestedChunks.isEmpty() && loadingChunks == 0) { finish(); } else { requestBatch(); @@ -204,9 +205,11 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator { BlockVector2 chunk; for (int i = 0; i < this.batchSize && (chunk = this.requestedChunks.poll()) != null; i++) { // This required PaperLib to be bumped to version 1.0.4 to mark the request as urgent + loadingChunks++; PaperLib .getChunkAtAsync(this.bukkitWorld, chunk.getX(), chunk.getZ(), true, true) .whenComplete((chunkObject, throwable) -> { + loadingChunks--; if (throwable != null) { throwable.printStackTrace(); // We want one less because this couldn't be processed