fix: PVP/伤害权限双重检查修复 + PHP删除用户组同步
1. PVP/伤害不生效: onEntityDamage中对PVP玩家先检查denyAllDamage再检查denyPVP,避免重复getArea调 2. PHP删除用户组: handleDeleteUserGroup先删成员表再删组表,确保同步完整
This commit is contained in:
@@ -9342,51 +9342,73 @@ public class AreaProtection implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ===== 攻击生物逻辑 =====
|
// ===== 攻击生物逻辑 =====
|
||||||
if (!(e.getDamager() instanceof Player)) return;
|
if (e.getDamager() instanceof Player && !(e.getEntity() instanceof Player)) {
|
||||||
if (e.getEntity() instanceof Player) return; // PVP走下面的逻辑
|
Player mobAttacker = (Player) e.getDamager();
|
||||||
Player mobAttacker = (Player) e.getDamager();
|
AreaConfig acMob = getArea(
|
||||||
AreaConfig acMob = getArea(
|
mobAttacker.getWorld().getName(),
|
||||||
mobAttacker.getWorld().getName(),
|
mobAttacker.getLocation().getBlockX(),
|
||||||
mobAttacker.getLocation().getBlockX(),
|
mobAttacker.getLocation().getBlockY(),
|
||||||
mobAttacker.getLocation().getBlockY(),
|
mobAttacker.getLocation().getBlockZ());
|
||||||
mobAttacker.getLocation().getBlockZ());
|
if (acMob != null && getEffectiveDeny(mobAttacker, acMob, "denyMobAttack")) {
|
||||||
if (acMob != null && getEffectiveDeny(mobAttacker, acMob, "denyMobAttack")) {
|
// ★ 公共建筑设施:访客允许攻击敌对生物
|
||||||
// ★ 公共建筑设施:访客允许攻击敌对生物
|
if (!acMob.isPublicBuilding || mobAttacker.getName().equalsIgnoreCase(acMob.owner) || isAreaAdmin(mobAttacker)) {
|
||||||
if (!acMob.isPublicBuilding || mobAttacker.getName().equalsIgnoreCase(acMob.owner) || isAreaAdmin(mobAttacker)) {
|
e.setCancelled(true);
|
||||||
e.setCancelled(true);
|
mobAttacker.sendMessage("§c§l[区域防护] §f此区域禁止攻击生物");
|
||||||
mobAttacker.sendMessage("§c§l[区域防护] §f此区域禁止攻击生物");
|
return;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== PVP 逻辑 =====
|
// ===== PVP 逻辑 =====
|
||||||
if (!(e.getDamager() instanceof Player)) return;
|
if (e.getDamager() instanceof Player && e.getEntity() instanceof Player) {
|
||||||
if (!(e.getEntity() instanceof Player)) return;
|
Player attacker = (Player) e.getDamager();
|
||||||
Player attacker = (Player) e.getDamager();
|
Player victim = (Player) e.getEntity();
|
||||||
Player victim = (Player) e.getEntity();
|
|
||||||
|
|
||||||
// 受害者领地禁止PVP → 阻断
|
// 受害者领地禁止所有伤害 → 阻断
|
||||||
AreaConfig acVictim = getArea(
|
AreaConfig acVictim = getArea(
|
||||||
victim.getWorld().getName(),
|
victim.getWorld().getName(),
|
||||||
victim.getLocation().getBlockX(),
|
victim.getLocation().getBlockX(),
|
||||||
victim.getLocation().getBlockY(),
|
victim.getLocation().getBlockY(),
|
||||||
victim.getLocation().getBlockZ());
|
victim.getLocation().getBlockZ());
|
||||||
if (acVictim != null && getEffectiveDeny(victim, acVictim, "denyPVP")) {
|
if (acVictim != null && getEffectiveDeny(victim, acVictim, "denyAllDamage")) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
attacker.sendMessage("§c§l[区域防护] §f该领地禁止PVP");
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 攻击者领地禁止PVP → 阻断
|
// 攻击者领地禁止所有伤害 → 阻断
|
||||||
AreaConfig acAttacker = getArea(
|
AreaConfig acAttacker = getArea(
|
||||||
attacker.getWorld().getName(),
|
attacker.getWorld().getName(),
|
||||||
attacker.getLocation().getBlockX(),
|
attacker.getLocation().getBlockX(),
|
||||||
attacker.getLocation().getBlockY(),
|
attacker.getLocation().getBlockY(),
|
||||||
attacker.getLocation().getBlockZ());
|
attacker.getLocation().getBlockZ());
|
||||||
if (acAttacker != null && getEffectiveDeny(attacker, acAttacker, "denyPVP")) {
|
if (acAttacker != null && getEffectiveDeny(attacker, acAttacker, "denyAllDamage")) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
attacker.sendMessage("§c§l[区域防护] §f此区域禁止PVP");
|
return;
|
||||||
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");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 攻击者领地禁止PVP → 阻断
|
||||||
|
if (acAttacker == null) acAttacker = getArea(
|
||||||
|
attacker.getWorld().getName(),
|
||||||
|
attacker.getLocation().getBlockX(),
|
||||||
|
attacker.getLocation().getBlockY(),
|
||||||
|
attacker.getLocation().getBlockZ());
|
||||||
|
if (acAttacker != null && getEffectiveDeny(attacker, acAttacker, "denyPVP")) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
attacker.sendMessage("§c§l[区域防护] §f此区域禁止PVP");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -855,6 +855,30 @@ public class UserGroupManager {
|
|||||||
return list;
|
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同步 ====================
|
||||||
|
|
||||||
/** 推送成员变更到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并打印日志
|
// ★ 仅在有实际变化时才reload并打印日志
|
||||||
if (changed > 0) {
|
if (changed > 0) {
|
||||||
ugm.loadGroupConfigs();
|
ugm.loadGroupConfigs();
|
||||||
|
|||||||
Reference in New Issue
Block a user