From 49ad056a715381b0d037300ec95e066ce6e54bb8 Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Sun, 12 Jul 2026 18:27:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=80=E5=87=BA=E9=A2=86=E5=9C=B0?= =?UTF-8?q?=E7=AB=8B=E5=8D=B3=E6=B8=85=E9=99=A4=E6=95=88=E6=9E=9C=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E4=BE=9D=E8=B5=965=E7=A7=92=E5=BB=B6?= =?UTF-8?q?=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:playerMarkedEffects标记不可靠(hotUpdateRegionEffects会清空、 applyRegionEffects可能跳过添加),导致离开时marked为空→无延时任务→效果残留 修复: 1. 移动退出到野外:直接从oldAc.giveEffects读取效果列表,立即removePotionEffect 2. 传送到野外:同上逻辑 3. 领地→领地跨区域仍保留5秒延时差量清理 --- src/main/java/Sdf1_login/AreaProtection.java | 92 ++++++++++++-------- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/src/main/java/Sdf1_login/AreaProtection.java b/src/main/java/Sdf1_login/AreaProtection.java index e9c1d2c..88f1f33 100644 --- a/src/main/java/Sdf1_login/AreaProtection.java +++ b/src/main/java/Sdf1_login/AreaProtection.java @@ -3081,34 +3081,49 @@ public class AreaProtection implements Listener { "[防护-移动-离开] 取消旧延时"); } - // 创建延时清理 - if (marked != null && !marked.isEmpty()) { + // ★★★ 离开到野外(无新区域):立即清除领地给予的效果 ★★★ + if (newArea == null && oldAc != null + && oldAc.giveEffects != null && !oldAc.giveEffects.isEmpty()) { + plugin.getLogger().info( + "[防护-移动-离开野外] ★★★立即清除效果: 玩家=" + p.getName() + + " 区域=" + oldArea); + int cleared = 0; + for (String[] eff : oldAc.giveEffects) { + PotionEffectType type = resolveEffectType(eff[0]); + if (type != null) { + PotionEffect pe = p.getPotionEffect(type); + if (pe != null) { + p.removePotionEffect(type); + cleared++; + plugin.getLogger().info( + "[防护-移动-离开野外] ★清除: " + eff[0]); + } + } + } + removePlayerEffects(uid, oldArea); + plugin.getLogger().info( + "[防护-移动-离开野外] ★完成: 清除" + + cleared + "/" + oldAc.giveEffects.size() + "个效果"); + } + + // 创建延时清理(领地→领地跨区域差量清理) + if (marked != null && !marked.isEmpty() && newArea != null) { String clearArea = oldArea; UUID clearUid = uid; List toClear = new ArrayList<>(marked); pendingClearArea.put(uid, clearArea); pendingClearEffects.put(uid, toClear); - /* plugin.getLogger().info( - "[防护-移动-离开] ★★★创建延时任务: " - + toClear.size() + "个");*/ BukkitTask task = new BukkitRunnable() { @Override public void run() { - /* plugin.getLogger().info( - "[防护-移动-清理] ★★★延时触发!");*/ pendingClearTask.remove(clearUid); pendingClearArea.remove(clearUid); Player online = Bukkit.getPlayer(clearUid); - plugin.getLogger().info( - "[防护-移动-清理] 在线=" - + (online != null && online.isOnline()) - + " 效果数=" + toClear.size()); - if (online == null || !online.isOnline()) { removePlayerEffects( clearUid, clearArea); @@ -3119,10 +3134,6 @@ public class AreaProtection implements Listener { for (PotionEffectType type : toClear) { PotionEffect eff = online.getPotionEffect(type); - /* plugin.getLogger().info( - "[防护-移动-清理] 检查: " - + type.getName() - + " 身上=" + (eff != null));*/ if (eff != null) { online.removePotionEffect(type); cleared++; @@ -3130,7 +3141,7 @@ public class AreaProtection implements Listener { } removePlayerEffects(clearUid, clearArea); plugin.getLogger().info( - "[防护-移动-清理] + cleared" + toClear.size()); + "[防护-移动-清理] cleared " + cleared + "/" + toClear.size()); } }.runTaskLater(plugin, 100L); // 5秒 = 100 tick pendingClearTask.put(uid, task); @@ -4166,8 +4177,33 @@ public class AreaProtection implements Listener { pendingClearEffects.remove(uid); } - // 创建5秒延时清理 - if (marked != null && !marked.isEmpty()) { + // ★★★ 传送到野外(无目标区域):立即清除领地效果 ★★★ + if (toName == null && fromArea != null + && fromArea.giveEffects != null && !fromArea.giveEffects.isEmpty()) { + plugin.getLogger().info( + "[防护-传送-离开野外] ★★★立即清除效果: 玩家=" + p.getName() + + " 区域=" + fromName); + int cleared = 0; + for (String[] eff : fromArea.giveEffects) { + PotionEffectType type = resolveEffectType(eff[0]); + if (type != null) { + PotionEffect pe = p.getPotionEffect(type); + if (pe != null) { + p.removePotionEffect(type); + cleared++; + plugin.getLogger().info( + "[防护-传送-离开野外] ★清除: " + eff[0]); + } + } + } + removePlayerEffects(uid, fromName); + plugin.getLogger().info( + "[防护-传送-离开野外] ★完成: 清除" + + cleared + "/" + fromArea.giveEffects.size() + "个效果"); + } + + // 创建5秒延时清理(传送跨领地差量清理) + if (marked != null && !marked.isEmpty() && toName != null) { String clearArea = fromName; UUID clearUid = uid; List toClear = @@ -4175,26 +4211,14 @@ public class AreaProtection implements Listener { pendingClearArea.put(uid, clearArea); pendingClearEffects.put(uid, toClear); - /* plugin.getLogger().info( - "[防护-传送-离开] ★★★创建延时任务: " - + toClear.size() + "个效果");*/ - BukkitTask task = new BukkitRunnable() { @Override public void run() { - /* plugin.getLogger().info( - "[防护-传送-清理] ★★★延时触发!");*/ pendingClearTask.remove(clearUid); pendingClearArea.remove(clearUid); Player online = Bukkit.getPlayer(clearUid); -/* - plugin.getLogger().info( - "[防护-传送-清理] 在线=" - + (online != null && online.isOnline()) - + " 效果数=" + toClear.size() - + " 区域=" + clearArea);*/ if (online == null || !online.isOnline()) { @@ -4209,10 +4233,6 @@ public class AreaProtection implements Listener { for (PotionEffectType type : toClear) { PotionEffect eff = online.getPotionEffect(type); - /* plugin.getLogger().info( - "[防护-传送-清理] 检查: " - + type.getName() - + " 身上=" + (eff != null));*/ if (eff != null) { online.removePotionEffect(type); cleared++; @@ -4220,7 +4240,7 @@ public class AreaProtection implements Listener { } removePlayerEffects(clearUid, clearArea); plugin.getLogger().info( - "[防护-传送-清理] ★★★完成: 清除" + "[防护-传送-清理] cleared " + cleared + "/" + toClear.size()); } }.runTaskLater(plugin, 100L); // 5秒 = 100 tick