9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-26 10:29:13 +00:00

Fix some async config disappear after reload (#298)

* fix async config disappear

* fix comment of AsyncPathfinding config
This commit is contained in:
hayanesuru
2025-04-26 00:01:52 +08:00
committed by GitHub
parent efe2191b1f
commit 28543d51dd
3 changed files with 31 additions and 15 deletions

View File

@@ -10,7 +10,7 @@ public class AsyncMobSpawning extends ConfigModules {
}
public static boolean enabled = true;
public static boolean asyncMobSpawningInitialized;
private static boolean asyncMobSpawningInitialized;
@Override
public void onLoaded() {
@@ -26,9 +26,12 @@ public class AsyncMobSpawning extends ConfigModules {
须在Paper配置文件中打开 per-player-mob-spawns 才能生效.""");
// This prevents us from changing the value during a reload.
if (!asyncMobSpawningInitialized) {
asyncMobSpawningInitialized = true;
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
if (asyncMobSpawningInitialized) {
config.getConfigSection(getBasePath());
return;
}
asyncMobSpawningInitialized = true;
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
}
}

View File

@@ -16,9 +16,26 @@ public class AsyncPathfinding extends ConfigModules {
public static int asyncPathfindingKeepalive = 60;
public static int asyncPathfindingQueueSize = 0;
public static PathfindTaskRejectPolicy asyncPathfindingRejectPolicy = PathfindTaskRejectPolicy.FLUSH_ALL;
private static boolean asyncPathfindingInitialized;
@Override
public void onLoaded() {
config.addCommentRegionBased(getBasePath() + ".reject-policy",
"""
The policy to use when the queue is full and a new task is submitted.
FLUSH_ALL: All pending tasks will be run on server thread.
CALLER_RUNS: Newly submitted task will be run on server thread.""",
"""
当队列满时, 新提交的任务将使用以下策略处理.
FLUSH_ALL: 所有等待中的任务都将在主线程上运行.
CALLER_RUNS: 新提交的任务将在主线程上运行."""
);
if (asyncPathfindingInitialized) {
config.getConfigSection(getBasePath());
return;
}
asyncPathfindingInitialized = true;
final int availableProcessors = Runtime.getRuntime().availableProcessors();
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
asyncPathfindingMaxThreads = config.getInt(getBasePath() + ".max-threads", asyncPathfindingMaxThreads);
@@ -37,15 +54,6 @@ public class AsyncPathfinding extends ConfigModules {
if (asyncPathfindingQueueSize <= 0)
asyncPathfindingQueueSize = asyncPathfindingMaxThreads * 256;
asyncPathfindingRejectPolicy = PathfindTaskRejectPolicy.fromString(config.getString(getBasePath() + ".reject-policy", availableProcessors >= 12 && asyncPathfindingQueueSize < 512 ? PathfindTaskRejectPolicy.FLUSH_ALL.toString() : PathfindTaskRejectPolicy.CALLER_RUNS.toString(), config.pickStringRegionBased(
"""
The policy to use when the queue is full and a new task is submitted.
FLUSH_ALL: All pending tasks will be run on server thread.
CALLER_RUNS: Newly submitted task will be run on server thread.""",
"""
当队列满时, 新提交的任务将使用以下策略处理.
FLUSH_ALL: 所有等待中的任务都将在主线程上运行.
CALLER_RUNS: 新提交的任务将在主线程上运行."""
)));
asyncPathfindingRejectPolicy = PathfindTaskRejectPolicy.fromString(config.getString(getBasePath() + ".reject-policy", availableProcessors >= 12 && asyncPathfindingQueueSize < 512 ? PathfindTaskRejectPolicy.FLUSH_ALL.toString() : PathfindTaskRejectPolicy.CALLER_RUNS.toString()));
}
}

View File

@@ -4,6 +4,7 @@ package org.dreeam.leaf.config.modules.async;
import org.dreeam.leaf.async.ai.AsyncGoalExecutor;
import org.dreeam.leaf.config.ConfigModules;
import org.dreeam.leaf.config.EnumConfigCategory;
import org.dreeam.leaf.config.LeafConfig;
import org.dreeam.leaf.config.annotations.Experimental;
import java.util.concurrent.ArrayBlockingQueue;
@@ -23,7 +24,7 @@ public class AsyncTargetFinding extends ConfigModules {
public static boolean searchEntity = true;
public static boolean searchPlayer = false;
public static boolean searchPlayerTempt = false;
public static boolean asyncTargetFindingInitialized;
private static boolean asyncTargetFindingInitialized;
@Override
public void onLoaded() {
@@ -32,12 +33,15 @@ public class AsyncTargetFinding extends ConfigModules {
This moves the expensive entity target search calculations to a background thread while
keeping the actual entity validation on the main thread.""",
"""
**实验性功能**
这会将昂贵的实体目标搜索计算移至后台线程, 同时在主线程上保持实际的实体验证.""");
if (asyncTargetFindingInitialized) {
config.getConfigSection(getBasePath());
return;
}
asyncTargetFindingInitialized = true;
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
alertOther = config.getBoolean(getBasePath() + ".async-alert-other", true);
searchBlock = config.getBoolean(getBasePath() + ".async-search-block", false);
@@ -64,5 +68,6 @@ public class AsyncTargetFinding extends ConfigModules {
.setPriority(Thread.NORM_PRIORITY - 2)
.build(),
new ThreadPoolExecutor.CallerRunsPolicy());
LeafConfig.LOGGER.info("Using 1 threads for Async Target Finding");
}
}