修复和平模式扫描范围+在线玩家同步+领地数据同步

This commit is contained in:
2026-06-26 11:25:57 +08:00
parent 46b483848c
commit 47e1ad3be5
2 changed files with 16 additions and 6 deletions
+15 -5
View File
@@ -1996,15 +1996,25 @@ public class AreaProtection implements Listener {
if (!ac.peaceMode) continue;
// 对该区域边界内的实体扫描
// 简化:扫描该区域周围一定范围的实体
double centerX = (ac.x1 + ac.x2) / 2.0;
double centerZ = (ac.z1 + ac.z2) / 2.0;
World world = Bukkit.getWorld(ac.world);
if (world == null) continue;
// 扫描区域中心 ±50 格的实体
// ★ 根据领地实际大小计算扫描范围(取x和z范围的最大值,加边距)
int rangeX = Math.abs(ac.x2 - ac.x1) / 2 + 10;
int rangeZ = Math.abs(ac.z2 - ac.z1) / 2 + 10;
int range = Math.max(rangeX, rangeZ);
// 限制最大扫描范围避免性能问题
range = Math.min(range, 200);
// ★ 使用世界实际高度范围
int minY = world.getMinHeight();
int maxY = world.getMaxHeight();
int heightRange = (maxY - minY) / 2;
List<Entity> nearby = new java.util.ArrayList<>(world.getNearbyEntities(
new Location(world, centerX, world.getMaxHeight() / 2, centerZ), 50, 50, 50));
new Location(world, centerX, (minY + maxY) / 2.0, centerZ), range, heightRange, range));
for (Entity ent : nearby) {
if (!isHostile(ent.getType().name())) continue;
@@ -2025,8 +2035,8 @@ public class AreaProtection implements Listener {
Long protectUntil = protectedEntities.get(uid);
if (protectUntil != null && (protectUntil - now) > 0) continue;
// 清理
banEntity(ent);
// ★ 直接删除实体(传送可能卡住或重新刷新)
ent.remove();
cleared++;
}
}
+1 -1
View File
@@ -874,7 +874,7 @@ public class WebManager {
submitDbTask("首次-pushWebLoginCredentials", () -> pushWebLoginCredentials());
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
// 普通同步操作低优先级(每个任务间随机间隔2-4秒,避免PHP端DB锁)
submitNormalDbTask("首次-syncOnlinePlayers", () -> syncOnlinePlayers(), true);
submitDbTask("首次-syncOnlinePlayers", () -> syncOnlinePlayers(), true);
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}
submitNormalDbTask("首次-syncShopData", () -> syncShopData());
try { Thread.sleep(6000 + (long)(Math.random() * 8000)); } catch (InterruptedException ignored) {}