125续15l-7g 修: pardon主号随MC同删通配记录, reload绝不补ban主号, 清理历史脏名
Auto Release / build (push) Successful in 4m37s

This commit is contained in:
youpaishidifu
2026-11-21 18:45:35 +08:00
parent 2f9cadca94
commit 94863ff178
@@ -164,16 +164,17 @@ public class WildcardBanManager {
if (!p.isEmpty()) primariesInJson.add(p.toLowerCase(Locale.ROOT)); if (!p.isEmpty()) primariesInJson.add(p.toLowerCase(Locale.ROOT));
} }
// ---- 与 MC banned-players 对账:主号已不在 MC 封禁里 → 移除对应通配记录 ---- // ★ 15l-7g 铁律(用户定调):通配 json 是主数据,MC 主号封禁只是镜像。
// pardon(unban)主号 = 用户明确解封 → 随 MC 同删:主号不在 MC 封禁里,
// 该通配记录直接移除,绝不在玩家重连时偷偷把主号 ban 回 MC。
// 历史脏封禁(如 2111_)一并 unban(一次性清理),不补 ban 正确主号。
List<JsonElement> kept = new ArrayList<>(); List<JsonElement> kept = new ArrayList<>();
int removed = 0; int removed = 0;
for (JsonElement el : entries) { for (JsonElement el : entries) {
if (el == null || !el.isJsonObject()) { kept.add(el); continue; } if (el == null || !el.isJsonObject()) { kept.add(el); continue; }
JsonObject obj = el.getAsJsonObject(); JsonObject obj = el.getAsJsonObject();
// ★ 15l-7f 修复:去掉 time/starttime 的中文检查——时间字段是「2026年11月21日 16点46分」 // 时间字段是中文格式(2026年11月21日 16点46分)必含中文,绝不据此丢记录(15l-7f 教训)。
// 中文格式,必含中文,旧逻辑因此把每条记录都丢弃 → 缓存永远空 → isWildcardBanned
// 匹配不到任何玩家(2111 正常加入的根因)。只保留 user 非空校验。
String user = str(obj, "user"); String user = str(obj, "user");
if (user.isEmpty()) { kept.add(el); continue; } // 无 user 的脏条目保留但不缓存 if (user.isEmpty()) { kept.add(el); continue; } // 无 user 的脏条目保留但不缓存
@@ -184,18 +185,17 @@ public class WildcardBanManager {
if (!primary.isEmpty()) { if (!primary.isEmpty()) {
String pl = primary.toLowerCase(Locale.ROOT); String pl = primary.toLowerCase(Locale.ROOT);
if (!mcHasBan(pl)) { if (!mcHasBan(pl)) {
// MC 没封主号:先尝试迁移历史脏封禁(如 2111_ → 2111), // ★ 主号不在 MC 封禁(已被 pardon)→ 随 MC 同删通配记录,
// 迁移成功则主号现已封、保留;失败且 MC 确无主号 → 视为已 unban,移除。 // 顺带 unban 历史脏名(主号_),但绝不补 ban 主号。
if (!migrateWrongBan(primary, user)) { cleanUpOnUnban(primary);
removed++; removed++;
continue; continue;
}
} }
cachedPatterns.add(user.toLowerCase(Locale.ROOT)); cachedPatterns.add(user.toLowerCase(Locale.ROOT));
// ★ 15l-7f 修复:主号同时进精确名单(旧逻辑只进 cachedPatterns, // 主号同时进精确名单:主号本人(2111)能被 isWildcardBanned 命中
// 主号本人 2111 无法被 isWildcardBanned 命中)。
cachedExactNames.add(pl); cachedExactNames.add(pl);
} else { } else {
// 纯通配(*_、*)无主号:通配记录独立生效,不进 MC 对账
cachedPatterns.add(user.toLowerCase(Locale.ROOT)); cachedPatterns.add(user.toLowerCase(Locale.ROOT));
} }
} else { } else {
@@ -211,7 +211,7 @@ public class WildcardBanManager {
if (removed > 0) { if (removed > 0) {
writeRaw(kept); writeRaw(kept);
plugin.getLogger().info("[通配封禁] 随 MC 同步清理 " + removed + " 条记录(主号已 unban)"); plugin.getLogger().info("[通配封禁] 随 MC 同步清理 " + removed + " 条记录(主号已 unban,绝不补 ban)");
} }
cachedFingerprint = fp; cachedFingerprint = fp;
@@ -221,30 +221,22 @@ public class WildcardBanManager {
} }
/** /**
* ★ 15l-7f:迁移历史脏封禁。旧 primaryOf 把 `2111_*` 的主号算成 `2111_`(带尾下划线), * ★ 15l-7g(用户定调):pardon 主号后的清理。
* 导致 MC banned-players.json 里封的是 `2111_` 这种不存在的名字,真主号 `2111` 从未被 MC 封。 * 主号已从 MC 封禁移除 → 只做一件事:unban 历史脏名(主号+"_",旧 primaryOf 误封的名字),
* 迁移逻辑:若正确主号不在 MC 封禁、但脏名(主号+"_")在 → unban 脏名 + 用正确主号重新封。 * 绝不补 ban 正确主号。补 ban 会让「pardon 后重进又被封」的 bug 复发
* 返回「主号现在是否在 MC 封禁中」。 * (15l-7f 教训:reload 里 migrateWrongBan 在玩家重连瞬间把刚 pardon 的主号 ban 回 MC)。
*/ */
private boolean migrateWrongBan(String primary, String target) { private void cleanUpOnUnban(String primary) {
org.bukkit.BanList bl = org.bukkit.Bukkit.getBanList(BanList.Type.NAME);
try { try {
if (bl.getBanEntry(primary) != null) { org.bukkit.BanList bl = org.bukkit.Bukkit.getBanList(BanList.Type.NAME);
return true; // 主号已正常封禁,无需迁移
}
String wrong = primary + "_"; String wrong = primary + "_";
if (bl.getBanEntry(wrong) != null) { if (bl.getBanEntry(wrong) != null) {
bl.pardon(wrong); bl.pardon(wrong);
plugin.getLogger().info("[通配封禁] 迁移历史脏封禁:unban " + wrong + " → 重新 ban 主号 " plugin.getLogger().info("[通配封禁] pardon 同步清理:unban 历史脏名 " + wrong
+ primary + "(来源 " + target + ")"); + "(主号 " + primary + " 已被 unban,不补 ban)");
} }
if (bl.getBanEntry(primary) == null) {
banInMinecraft(primary, target, "");
}
return bl.getBanEntry(primary) != null;
} catch (Exception ex) { } catch (Exception ex) {
plugin.getLogger().warning("[通配封禁] 迁移脏封禁失败(主号 " + primary + "): " + ex.getMessage()); plugin.getLogger().warning("[通配封禁] pardon 清理脏名失败(主号 " + primary + "): " + ex.getMessage());
return bl.getBanEntry(primary) != null;
} }
} }