From 47e1ad3be597dfc617b67022853e24908c31a7c4 Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Fri, 26 Jun 2026 11:25:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=92=8C=E5=B9=B3=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E6=89=AB=E6=8F=8F=E8=8C=83=E5=9B=B4+=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E7=8E=A9=E5=AE=B6=E5=90=8C=E6=AD=A5+=E9=A2=86?= =?UTF-8?q?=E5=9C=B0=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Sdf1_login/AreaProtection.java | 20 +++++++++++++++----- src/main/java/Sdf1_login/WebManager.java | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/Sdf1_login/AreaProtection.java b/src/main/java/Sdf1_login/AreaProtection.java index c0f441d..6ec4792 100644 --- a/src/main/java/Sdf1_login/AreaProtection.java +++ b/src/main/java/Sdf1_login/AreaProtection.java @@ -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 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++; } } diff --git a/src/main/java/Sdf1_login/WebManager.java b/src/main/java/Sdf1_login/WebManager.java index 7dada57..47a5ee5 100644 --- a/src/main/java/Sdf1_login/WebManager.java +++ b/src/main/java/Sdf1_login/WebManager.java @@ -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) {}