fix: PVP/伤害权限双重检查修复 + PHP删除用户组同步
1. PVP/伤害不生效: onEntityDamage中对PVP玩家先检查denyAllDamage再检查denyPVP,避免重复getArea调 2. PHP删除用户组: handleDeleteUserGroup先删成员表再删组表,确保同步完整
This commit is contained in:
@@ -9342,8 +9342,7 @@ public class AreaProtection implements Listener {
|
||||
}
|
||||
|
||||
// ===== 攻击生物逻辑 =====
|
||||
if (!(e.getDamager() instanceof Player)) return;
|
||||
if (e.getEntity() instanceof Player) return; // PVP走下面的逻辑
|
||||
if (e.getDamager() instanceof Player && !(e.getEntity() instanceof Player)) {
|
||||
Player mobAttacker = (Player) e.getDamager();
|
||||
AreaConfig acMob = getArea(
|
||||
mobAttacker.getWorld().getName(),
|
||||
@@ -9358,19 +9357,41 @@ public class AreaProtection implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===== PVP 逻辑 =====
|
||||
if (!(e.getDamager() instanceof Player)) return;
|
||||
if (!(e.getEntity() instanceof Player)) return;
|
||||
if (e.getDamager() instanceof Player && e.getEntity() instanceof Player) {
|
||||
Player attacker = (Player) e.getDamager();
|
||||
Player victim = (Player) e.getEntity();
|
||||
|
||||
// 受害者领地禁止PVP → 阻断
|
||||
// 受害者领地禁止所有伤害 → 阻断
|
||||
AreaConfig acVictim = getArea(
|
||||
victim.getWorld().getName(),
|
||||
victim.getLocation().getBlockX(),
|
||||
victim.getLocation().getBlockY(),
|
||||
victim.getLocation().getBlockZ());
|
||||
if (acVictim != null && getEffectiveDeny(victim, acVictim, "denyAllDamage")) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// 攻击者领地禁止所有伤害 → 阻断
|
||||
AreaConfig acAttacker = getArea(
|
||||
attacker.getWorld().getName(),
|
||||
attacker.getLocation().getBlockX(),
|
||||
attacker.getLocation().getBlockY(),
|
||||
attacker.getLocation().getBlockZ());
|
||||
if (acAttacker != null && getEffectiveDeny(attacker, acAttacker, "denyAllDamage")) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// 受害者领地禁止PVP → 阻断
|
||||
if (acVictim == null) acVictim = getArea(
|
||||
victim.getWorld().getName(),
|
||||
victim.getLocation().getBlockX(),
|
||||
victim.getLocation().getBlockY(),
|
||||
victim.getLocation().getBlockZ());
|
||||
if (acVictim != null && getEffectiveDeny(victim, acVictim, "denyPVP")) {
|
||||
e.setCancelled(true);
|
||||
attacker.sendMessage("§c§l[区域防护] §f该领地禁止PVP");
|
||||
@@ -9378,7 +9399,7 @@ public class AreaProtection implements Listener {
|
||||
}
|
||||
|
||||
// 攻击者领地禁止PVP → 阻断
|
||||
AreaConfig acAttacker = getArea(
|
||||
if (acAttacker == null) acAttacker = getArea(
|
||||
attacker.getWorld().getName(),
|
||||
attacker.getLocation().getBlockX(),
|
||||
attacker.getLocation().getBlockY(),
|
||||
@@ -9389,6 +9410,7 @@ public class AreaProtection implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 展示框被点击(旋转/放入/取出)
|
||||
@EventHandler
|
||||
|
||||
@@ -855,6 +855,30 @@ public class UserGroupManager {
|
||||
return list;
|
||||
}
|
||||
|
||||
/** 删除不在PHP列表中的本地组(用于处理面板删除用户组后的同步) */
|
||||
public int removeGroupsNotIn(Set<String> phpGroupNames) {
|
||||
int removed = 0;
|
||||
Set<String> toRemove = new HashSet<>();
|
||||
for (String name : groupConfigs.keySet()) {
|
||||
String lower = name.toLowerCase();
|
||||
boolean found = false;
|
||||
for (String phpName : phpGroupNames) {
|
||||
if (phpName.equalsIgnoreCase(lower)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
toRemove.add(name);
|
||||
}
|
||||
}
|
||||
for (String name : toRemove) {
|
||||
groupConfigs.remove(name);
|
||||
removed++;
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
// ==================== PHP同步 ====================
|
||||
|
||||
/** 推送成员变更到PHP */
|
||||
|
||||
@@ -3393,6 +3393,32 @@ public class WebManager {
|
||||
}
|
||||
}
|
||||
|
||||
// ★ 删除PHP中已不存在的组:从PHP返回的完整JSON中解析所有组名
|
||||
Set<String> phpGroupNames = new HashSet<>();
|
||||
try {
|
||||
int idx = 0;
|
||||
while (idx < resp.length()) {
|
||||
String key = "\"group_name\":\"";
|
||||
int gi = resp.indexOf(key, idx);
|
||||
if (gi < 0) break;
|
||||
int start = gi + key.length();
|
||||
int end = resp.indexOf("\"", start);
|
||||
if (end > start) {
|
||||
phpGroupNames.add(resp.substring(start, end));
|
||||
}
|
||||
idx = end > start ? end : start + 1;
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
// 删除不在PHP列表中的本地组
|
||||
if (!phpGroupNames.isEmpty()) {
|
||||
int removed = ugm.removeGroupsNotIn(phpGroupNames);
|
||||
if (removed > 0) {
|
||||
changed++;
|
||||
plugin.getLogger().info("[防护-sync] 删除PHP中已不存在的用户组: " + removed + "个");
|
||||
}
|
||||
}
|
||||
|
||||
// ★ 仅在有实际变化时才reload并打印日志
|
||||
if (changed > 0) {
|
||||
ugm.loadGroupConfigs();
|
||||
|
||||
Reference in New Issue
Block a user