修复: 领地管理员永不被PHP perm_change降级 + 测试场KEEP_INVENTORY=false
- AreaProtection.updateVisitorPermFromWeb: admin角色永远保留, perm_change只更新permissions JSON不动role - PVPTestManager: KEEP_INVENTORY从true改为false, onPlayerDeath不再直接clearInventory, 改由onRespawn统一还原
This commit is contained in:
@@ -8215,30 +8215,36 @@ public class AreaProtection implements Listener {
|
||||
int landId = getLandIdFromDb(lname);
|
||||
if (landId < 0) continue;
|
||||
|
||||
// ★ 角色同步:仅当 PHP 显式携带 role(change_visitor_role)时才切换,
|
||||
// 避免"调整访客权限"时把已授权的管理员误降级为访客
|
||||
// ★ 角色同步铁律:admin 永远不允许被 PHP 的 perm_change 降级。
|
||||
// PHP 的 handleUpdateVisitorPerm 本身已拦截 admin/member,
|
||||
// 但竞态(admin 在 Java 设置后、同步到 PHP 前,PHP 已发 perm_change)
|
||||
// 仍可能导致此方法收到 role="visitor" 降级请求。
|
||||
// 解决:admin 只能通过 change_visitor_role(显式角色切换)改变,
|
||||
// perm_change 只更新 permissions JSON,不动 role。
|
||||
String effectiveRole = "visitor";
|
||||
if (role != null && !role.isEmpty()) {
|
||||
effectiveRole = role.toLowerCase();
|
||||
boolean isAdmin = isLandAdmin(lname, playerName);
|
||||
if ("admin".equalsIgnoreCase(role)) {
|
||||
setLandAdmin(lname, playerName, true);
|
||||
} else if ("visitor".equalsIgnoreCase(role) && isAdmin) {
|
||||
setLandAdmin(lname, playerName, false);
|
||||
} else if ("member".equalsIgnoreCase(role) && isAdmin) {
|
||||
// ★ PHP 发来 member 角色但玩家是管理员 — 不能降级,保留 admin
|
||||
plugin.getLogger().warning("[防护][更新权限] 拦截角色降级: " + playerName
|
||||
+ " @ " + lname + " 尝试从 admin 降为 member,已保留 admin");
|
||||
effectiveRole = "admin";
|
||||
}
|
||||
} else {
|
||||
// 未带 role 时,沿用本地已有角色;若本地无记录则默认 visitor
|
||||
boolean isAdmin = false;
|
||||
{
|
||||
String localRole = getLocalRole(landId, playerName);
|
||||
if (localRole != null && !localRole.isEmpty()) {
|
||||
effectiveRole = localRole;
|
||||
}
|
||||
isAdmin = "admin".equalsIgnoreCase(effectiveRole);
|
||||
}
|
||||
|
||||
if (isAdmin) {
|
||||
// ★ 管理员:永远保留 admin 角色,只更新 permissions JSON
|
||||
effectiveRole = "admin";
|
||||
} else if (role != null && !role.isEmpty()) {
|
||||
// 非管理员:显式角色切换(来自 change_visitor_role)
|
||||
effectiveRole = role.toLowerCase();
|
||||
if ("admin".equalsIgnoreCase(role)) {
|
||||
setLandAdmin(lname, playerName, true);
|
||||
effectiveRole = "admin";
|
||||
}
|
||||
// ★ 移除旧逻辑:不再允许通过 perm_change 将 admin 降为 visitor/member
|
||||
}
|
||||
// role 为空或 visitor + 非 admin:effectiveRole 保持 localRole 或默认 visitor
|
||||
|
||||
plugin.getLogger().info("[防护][更新权限] 入参 land=" + lname + " player=" + playerName
|
||||
+ " role=" + role + " localRole=" + getLocalRole(landId, playerName)
|
||||
+ " effectiveRole=" + effectiveRole
|
||||
|
||||
@@ -171,12 +171,13 @@ public class PVPTestManager implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
// 世界规则:常昼 / 无天气 / 关闭自然刷怪(只有我们生成的练习生物)/ 死亡不掉装备 / PVP 开启
|
||||
// 世界规则:常昼 / 无天气 / 关闭自然刷怪(只有我们生成的练习生物)/ PVP 开启
|
||||
// ★ KEEP_INVENTORY=false:死亡掉落由事件处理器清空掉落物+复活时还原,避免gamerule与事件冲突
|
||||
w.setPVP(true);
|
||||
w.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
||||
w.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
||||
w.setGameRule(GameRule.DO_MOB_SPAWNING, false);
|
||||
w.setGameRule(GameRule.KEEP_INVENTORY, true);
|
||||
w.setGameRule(GameRule.KEEP_INVENTORY, false);
|
||||
w.setTime(6000);
|
||||
w.setKeepSpawnInMemory(false);
|
||||
|
||||
@@ -993,7 +994,11 @@ public class PVPTestManager implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/** 死亡:清空测试装备掉落物 + 强制不保留背包,防止玩家死亡界面/快速重连携带测试场装备 */
|
||||
/** 死亡:清空测试装备掉落物 + 强制不保留背包。
|
||||
* KEEP_INVENTORY=false(gamerule) 保证服务器会清空背包;
|
||||
* e.setKeepInventory(false) 双重保险;e.getDrops().clear() 防掉落物落地。
|
||||
* ★ 不在 DeathEvent 里直接 clearInventory(Paper快照机制可能导致无效),
|
||||
* 改由 onRespawn 统一从备份还原。 */
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
Player p = e.getEntity();
|
||||
@@ -1003,12 +1008,8 @@ public class PVPTestManager implements Listener {
|
||||
// 不保留经验
|
||||
e.setKeepLevel(false);
|
||||
e.setDroppedExp(0);
|
||||
// ★ 关键:不保留背包,死亡后身上清空(onRespawn 会立即还原原背包)
|
||||
// 不保留背包(配合 gamerule=false 双重保险)
|
||||
e.setKeepInventory(false);
|
||||
// 主动清空玩家身上的测试装备,防止死亡界面显示测试装备
|
||||
p.getInventory().clear();
|
||||
p.getInventory().setArmorContents(null);
|
||||
p.getInventory().setItemInOffHand(null);
|
||||
}
|
||||
|
||||
/** 死亡:保留背包(KEEP_INVENTORY),送回主世界并还原 */
|
||||
|
||||
Reference in New Issue
Block a user