9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00

Correctly shutdown AsyncLocator

This commit is contained in:
HaHaWTH
2025-07-23 17:30:26 +14:00
parent d50f8985fa
commit 6f552d491e
2 changed files with 14 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ import net.minecraft.server.MinecraftServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dreeam.leaf.async.ai.AsyncGoalThread;
import org.dreeam.leaf.async.locate.AsyncLocator;
import org.dreeam.leaf.async.path.AsyncPathProcessor;
import org.dreeam.leaf.async.tracker.AsyncTracker;
@@ -14,6 +15,15 @@ public class ShutdownExecutors {
public static final Logger LOGGER = LogManager.getLogger("Leaf");
public static void shutdown(MinecraftServer server) {
if (AsyncLocator.LOCATING_EXECUTOR_SERVICE != null) {
LOGGER.info("Waiting for structure locating executor to shutdown...");
AsyncLocator.LOCATING_EXECUTOR_SERVICE.shutdown();
try {
AsyncLocator.LOCATING_EXECUTOR_SERVICE.awaitTermination(60L, TimeUnit.SECONDS);
} catch (InterruptedException ignored) {
}
}
if (server.mobSpawnExecutor != null && server.mobSpawnExecutor.thread.isAlive()) {
LOGGER.info("Waiting for mob spawning thread to shutdown...");
try {

View File

@@ -11,6 +11,8 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.structure.Structure;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
@@ -24,7 +26,8 @@ import java.util.function.Consumer;
// Original project: https://github.com/thebrightspark/AsyncLocator
public class AsyncLocator {
private static final ExecutorService LOCATING_EXECUTOR_SERVICE;
public static final Logger LOGGER = LogManager.getLogger("Leaf Async Locator");
public static final ExecutorService LOCATING_EXECUTOR_SERVICE;
private AsyncLocator() {
}
@@ -65,12 +68,6 @@ public class AsyncLocator {
);
}
public static void shutdownExecutorService() {
if (LOCATING_EXECUTOR_SERVICE != null) {
LOCATING_EXECUTOR_SERVICE.shutdown();
}
}
/**
* Queues a task to locate a feature using {@link ServerLevel#findNearestMapStructure(TagKey, BlockPos, int, boolean)}
* and returns a {@link LocateTask} with the futures for it.