From ac4c00d3f2109ad91dfdc1265d40b74e5f79960a Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Thu, 7 Dec 2023 14:27:08 +0100 Subject: [PATCH] Thanks Crazydev! --- .../core/pregenerator/LazyPregenerator.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/pregenerator/LazyPregenerator.java b/core/src/main/java/com/volmit/iris/core/pregenerator/LazyPregenerator.java index 47effb6d8..b53bfcc03 100644 --- a/core/src/main/java/com/volmit/iris/core/pregenerator/LazyPregenerator.java +++ b/core/src/main/java/com/volmit/iris/core/pregenerator/LazyPregenerator.java @@ -25,6 +25,7 @@ import org.bukkit.event.world.WorldUnloadEvent; import java.io.File; import java.io.IOException; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; @@ -145,12 +146,23 @@ public class LazyPregenerator extends Thread implements Listener { private void tickGenerate(Position2 chunk) { executorService.submit(() -> { + CountDownLatch latch = new CountDownLatch(1); if (PaperLib.isPaper()) { - PaperLib.getChunkAtAsync(world, chunk.getX(), chunk.getZ(), true).thenAccept((i) -> Iris.verbose("Generated Async " + chunk)); + PaperLib.getChunkAtAsync(world, chunk.getX(), chunk.getZ(), true) + .thenAccept((i) -> { + Iris.verbose("Generated Async " + chunk); + latch.countDown(); + }); } else { - J.s(() -> world.getChunkAt(chunk.getX(), chunk.getZ())); - Iris.verbose("Generated " + chunk); + J.s(() -> { + world.getChunkAt(chunk.getX(), chunk.getZ()); + Iris.verbose("Generated " + chunk); + latch.countDown(); + }); } + try { + latch.await(); + } catch (InterruptedException ignored) {} lazyGeneratedChunks.addAndGet(1); }); }