mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-20 15:39:37 +00:00
Correctly shutdown AsyncLocator
This commit is contained in:
@@ -4,6 +4,7 @@ import net.minecraft.server.MinecraftServer;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dreeam.leaf.async.ai.AsyncGoalThread;
|
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.path.AsyncPathProcessor;
|
||||||
import org.dreeam.leaf.async.tracker.AsyncTracker;
|
import org.dreeam.leaf.async.tracker.AsyncTracker;
|
||||||
|
|
||||||
@@ -14,6 +15,15 @@ public class ShutdownExecutors {
|
|||||||
public static final Logger LOGGER = LogManager.getLogger("Leaf");
|
public static final Logger LOGGER = LogManager.getLogger("Leaf");
|
||||||
|
|
||||||
public static void shutdown(MinecraftServer server) {
|
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()) {
|
if (server.mobSpawnExecutor != null && server.mobSpawnExecutor.thread.isAlive()) {
|
||||||
LOGGER.info("Waiting for mob spawning thread to shutdown...");
|
LOGGER.info("Waiting for mob spawning thread to shutdown...");
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import net.minecraft.server.level.ServerLevel;
|
|||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
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.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@@ -24,7 +26,8 @@ import java.util.function.Consumer;
|
|||||||
// Original project: https://github.com/thebrightspark/AsyncLocator
|
// Original project: https://github.com/thebrightspark/AsyncLocator
|
||||||
public class 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() {
|
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)}
|
* 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.
|
* and returns a {@link LocateTask} with the futures for it.
|
||||||
|
|||||||
Reference in New Issue
Block a user