Skip to content

Commit

Permalink
Do not take chunk snapshot async.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jul 19, 2020
1 parent 3cc887b commit ee4c6ef
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,9 @@ private int limitCount(Material md) {
/**
* Count the blocks on the island
* @param result - the CompletableFuture that should be completed when this scan is done
* @param chunk - the chunk to scan
* @param chunkSnapshot - the chunk to scan
*/
private void scanAsync(CompletableFuture<Boolean> result, Chunk chunk) {
// Get a thread-safe snapshot of the chunk
ChunkSnapshot chunkSnapshot = chunk.getChunkSnapshot();
private void scanAsync(CompletableFuture<Boolean> result, ChunkSnapshot chunkSnapshot, Chunk chunk) {
for (int x = 0; x< 16; x++) {
// Check if the block coordinate is inside the protection zone and if not, don't count it
if (chunkSnapshot.getX() * 16 + x < island.getMinProtectedX() || chunkSnapshot.getX() * 16 + x >= island.getMinProtectedX() + island.getProtectionRange() * 2) {
Expand Down Expand Up @@ -442,7 +440,8 @@ private CompletableFuture<Boolean> scanChunk(@Nullable Chunk chunk) {
}
// Count blocks in chunk
CompletableFuture<Boolean> result = new CompletableFuture<>();
Bukkit.getScheduler().runTaskAsynchronously(BentoBox.getInstance(), () -> scanAsync(result, chunk));
ChunkSnapshot snapshot = chunk.getChunkSnapshot();
Bukkit.getScheduler().runTaskAsynchronously(BentoBox.getInstance(), () -> scanAsync(result, snapshot, chunk));
return result;
}

Expand Down

0 comments on commit ee4c6ef

Please sign in to comment.