修复三个同步bug:配置即时同步+Timer D独立+债券余额即时推送

1. 配置同步:AreaProtection.updateAreaConfig()后立即触发requestImmediateLandSync()
2. Timer D独立:移除timersBCPaused检查,不再被全员离线暂停
3. Timer D不重复调度:玩家上线时不再重启Timer D(已独立运行)
4. syncLandData增加hash变化日志(便于排查同步问题)
5. 债券余额即时推送(上一轮已修复,本次重新编译)
This commit is contained in:
2026-06-27 19:39:03 +08:00
parent 179f3a8355
commit 7efa78dbf9
2 changed files with 30 additions and 8 deletions
@@ -5742,6 +5742,13 @@ public class AreaProtection implements Listener {
sender.sendMessage("§c未知配置项: " + key); sender.sendMessage("§c未知配置项: " + key);
return true; return true;
} }
// ★ 配置变更:立即触发PHP同步
try {
if (plugin.webManager != null) {
plugin.webManager.requestImmediateLandSync();
}
} catch (Exception ignored) {}
// ★ 更新后显示完整配置页面(而非仅打印"已更新") // ★ 更新后显示完整配置页面(而非仅打印"已更新")
if (plugin.areaCLIManager != null) { if (plugin.areaCLIManager != null) {
plugin.areaCLIManager.showConfigPage((Player) sender); plugin.areaCLIManager.showConfigPage((Player) sender);
+23 -8
View File
@@ -1246,11 +1246,20 @@ public class WebManager {
} catch (Exception e) { } catch (Exception e) {
plugin.getLogger().warning("[Web交易即时] 推送异常: " + e.getMessage()); plugin.getLogger().warning("[Web交易即时] 推送异常: " + e.getMessage());
} }
// ★ 关键修复:交易处理后立即推送余额快照到PHP
// 解决全员离线时Timer C暂停导致PHP余额不同步的bug
try {
lastBondBalanceHash = ""; // 清除hash缓存,强制推送
syncBondBalances();
} catch (Exception e) {
plugin.getLogger().warning("[Web交易即时] 余额推送异常: " + e.getMessage());
}
// 检查是否有待处理的推送 // 检查是否有待处理的推送
if (pendingImmediateTxSync) { if (pendingImmediateTxSync) {
pendingImmediateTxSync = false; pendingImmediateTxSync = false;
submitDbTask("即时推送-交易(延迟)", () -> { submitDbTask("即时推送-交易(延迟)", () -> {
try { syncBondTransactions(); } catch (Exception e) {} try { syncBondTransactions(); } catch (Exception e) {}
try { lastBondBalanceHash = ""; syncBondBalances(); } catch (Exception e) {}
}); });
} }
}); });
@@ -1344,15 +1353,14 @@ public class WebManager {
lastSyncDone = false; lastSyncDone = false;
// ★ 玩家上线恢复:重启Timer B/C(之前全员下线时已暂停) // ★ 玩家上线恢复:重启Timer B/C(之前全员下线时已暂停)
// ★ Timer D已独立运行,不再需要重启
if (timersBCPaused) { if (timersBCPaused) {
timersBCPaused = false; timersBCPaused = false;
long randB = (long)(Math.random() * 10) * 2; long randB = (long)(Math.random() * 10) * 2;
long randC = (long)(Math.random() * 10) * 2; long randC = (long)(Math.random() * 10) * 2;
long randD = (long)(Math.random() * 10) * 2;
scheduleTimerB(40L + randB); // 2秒后重启B scheduleTimerB(40L + randB); // 2秒后重启B
scheduleTimerC(120L + randC); // 6秒后重启C scheduleTimerC(120L + randC); // 6秒后重启C
scheduleTimerD(180L + randD); // 9秒后重启D plugin.getLogger().info("[合并C] ★ 玩家上线,Timer B/C已恢复(随机偏移B=" + (randB/20) + "s C=" + (randC/20) + "s)");
plugin.getLogger().info("[合并C] ★ 玩家上线,Timer B/C/D已恢复(随机偏移B=" + (randB/20) + "s C=" + (randC/20) + "s D=" + (randD/20) + "s)");
} }
// 玩家在线:全量批处理 // 玩家在线:全量批处理
@@ -1715,10 +1723,7 @@ public class WebManager {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
synchronized (scheduleLock) { lastRunTimestamps[TIMER_D] = now; } synchronized (scheduleLock) { lastRunTimestamps[TIMER_D] = now; }
// ★ 全员下线暂停 // ★ Timer D独立:不检查timersBCPaused(v17重构设计)
if (timersBCPaused) {
return;
}
// ★ PHP锁库退避检查 // ★ PHP锁库退避检查
if (phpBusyUntil > now) { if (phpBusyUntil > now) {
@@ -2018,6 +2023,12 @@ public class WebManager {
int aft = plugin.getBondManager().getBonds(playerName); int aft = plugin.getBondManager().getBonds(playerName);
plugin.getLogger().info("[CDK远程验证] 直接加债券: " + playerName + " +" + amount + " (" + bef + "->" + aft + ")"); plugin.getLogger().info("[CDK远程验证] 直接加债券: " + playerName + " +" + amount + " (" + bef + "->" + aft + ")");
// ★ 修复:远程CDK加债券后立即推送余额到PHP
try {
lastBondBalanceHash = "";
syncBondBalances();
} catch (Exception ex) { /* 静默 */ }
// 通知在线玩家 // 通知在线玩家
Player targetPlayer = Bukkit.getPlayerExact(playerName); Player targetPlayer = Bukkit.getPlayerExact(playerName);
if (targetPlayer != null && targetPlayer.isOnline()) { if (targetPlayer != null && targetPlayer.isOnline()) {
@@ -2896,7 +2907,11 @@ public class WebManager {
hashBuilder.append("cfg:").append(entry.getKey()).append("=").append(entry.getValue()).append(":"); hashBuilder.append("cfg:").append(entry.getKey()).append("=").append(entry.getValue()).append(":");
} }
String currentHash = lands.size() + ":" + hashBuilder.toString(); String currentHash = lands.size() + ":" + hashBuilder.toString();
if (currentHash.equals(lastLandDataHash)) return; if (currentHash.equals(lastLandDataHash)) {
// ★ hash未变化,静默跳过(但首次运行或强制刷新时会同步)
return;
}
plugin.getLogger().info("[防护-sync] hash变化: lands=" + lands.size() + " config=" + cfgForHash.size() + "项,开始同步");
lastLandDataHash = currentHash; lastLandDataHash = currentHash;
// 1. 同步领地列表(全字段) // 1. 同步领地列表(全字段)