From b6ea705fd6f63af1e680f83c6b4f6ecf56332663 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Tue, 26 Mar 2024 16:00:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=8C=BA=E5=9D=97?= =?UTF-8?q?=E5=BC=BA=E5=8A=A0=E5=89=8D=E7=9A=84=E6=B8=85=E7=90=86=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E5=9B=A0=E4=B8=BA=E4=B8=96=E7=95=8C=E6=9C=AA=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=AE=8C=E6=88=90=E5=AF=BC=E8=87=B4=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++ pom.xml | 2 +- .../essentialsd/utils/ConfigManager.java | 58 ++++++++++++------- src/main/resources/config.yml | 7 +++ 4 files changed, 51 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index c31cb1f..ccf64e6 100644 --- a/README.md +++ b/README.md @@ -154,12 +154,19 @@ ForceLoadChunks: ## 配置文件参考 ```yaml +# 附魔瓶经验值倍率 ExpBottleRatio: 1.0 +# 强加载区块列表 ForceLoadChunks: # - world:0:0 # - world_the_end:-12:12 +# 区块操作延迟(强加载清理、设置) 秒 +# 过低可能导致世界未加载完成时触发操作引起报错 +# -1 为禁用强加载区块操作 +ChunkOperateDelay: 10 + Debug: false ``` diff --git a/pom.xml b/pom.xml index 21d467c..f5ed7c9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.lunadeer EssentialsD - 1.12.8 + 1.12.10 jar EssentialsD diff --git a/src/main/java/cn/lunadeer/essentialsd/utils/ConfigManager.java b/src/main/java/cn/lunadeer/essentialsd/utils/ConfigManager.java index 02b38f6..1f9b759 100644 --- a/src/main/java/cn/lunadeer/essentialsd/utils/ConfigManager.java +++ b/src/main/java/cn/lunadeer/essentialsd/utils/ConfigManager.java @@ -23,6 +23,7 @@ public class ConfigManager { _debug = _file.getBoolean("Debug", false); _exp_bottle_ratio = (float) _file.getDouble("ExpBottleRatio", 1.0); _force_load_chunks = _file.getStringList("ForceLoadChunks"); + _chunk_operate_delay = _file.getInt("ChunkOperateDelay", 10); } public Boolean isDebug() { @@ -45,40 +46,52 @@ public class ConfigManager { _plugin.saveConfig(); } + public Integer getChunkOperateDelay() { + return _chunk_operate_delay; + } + + public void setChunkOperateDelay(Integer delay) { + _chunk_operate_delay = delay; + _file.set("ChunkOperateDelay", delay); + _plugin.saveConfig(); + } + public void ApplyForceLoadChunks() { - // remove all force loaded chunks - EssentialsD.globalScheduler.run(EssentialsD.instance, (instance) -> { + if (_chunk_operate_delay < 0) { + XLogger.info("加载区块操作已禁用"); + return; + } + EssentialsD.globalScheduler.runDelayed(EssentialsD.instance, (instance) -> { + // remove all force loaded chunks int count = 0; for (World world : EssentialsD.instance.getServer().getWorlds()) { XLogger.debug("清除所有强加载区块: " + world.getName()); - Collection chunks = world.getForceLoadedChunks(); // todo 这里有问题 + Collection chunks = world.getForceLoadedChunks(); for (Chunk chunk : chunks) { count++; world.setChunkForceLoaded(chunk.getX(), chunk.getZ(), false); } } XLogger.info("清除所有强加载区块: " + count); - }); - // world:0:0 - for (String s : _force_load_chunks) { - String[] split = s.split(":"); - if (split.length != 3) { - XLogger.warn("ForceLoadChunks 配置错误: " + s); - continue; - } - String world_name = split[0]; - int x = Integer.parseInt(split[1]); - int z = Integer.parseInt(split[2]); - World world = _plugin.getServer().getWorld(world_name); - if (world == null) { - XLogger.warn("ForceLoadChunks 配置错误: 世界 " + world_name + " 不存在"); - continue; - } - EssentialsD.globalScheduler.run(EssentialsD.instance, (instance) -> { + // world:0:0 + for (String s : _force_load_chunks) { + String[] split = s.split(":"); + if (split.length != 3) { + XLogger.warn("ForceLoadChunks 配置错误: " + s); + continue; + } + String world_name = split[0]; + int x = Integer.parseInt(split[1]); + int z = Integer.parseInt(split[2]); + World world = _plugin.getServer().getWorld(world_name); + if (world == null) { + XLogger.warn("ForceLoadChunks 配置错误: 世界 " + world_name + " 不存在"); + continue; + } world.setChunkForceLoaded(x, z, true); XLogger.info("标记强加载区块: " + world_name + " " + x + " " + z); - }); - } + } + }, _chunk_operate_delay * 20); } @@ -87,5 +100,6 @@ public class ConfigManager { private boolean _debug; private float _exp_bottle_ratio; private List _force_load_chunks; + private Integer _chunk_operate_delay; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index fb62657..d2ee3f8 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,7 +1,14 @@ +# 附魔瓶经验值倍率 ExpBottleRatio: 1.0 +# 强加载区块列表 ForceLoadChunks: # - world:0:0 # - world_the_end:-12:12 +# 区块操作延迟(强加载清理、设置) 秒 +# 过低可能导致世界未加载完成时触发操作引起报错 +# -1 为禁用强加载区块操作 +ChunkOperateDelay: 10 + Debug: false \ No newline at end of file