二十二批:修复主线程SQLite同步读致watchdog卡服 + 错位配置目录检测
- restoreInventory/hideInventoryDelayed 的 loadInventoryBackup 挪异步线程读库,背包写回仍在主线程;restoreInventory 增加 afterRestore 回调保持「先恢复背包、再发菜单雪球」原顺序(Main autoLogin + LoginManager 注册/登录三处调用点同步改) - DatabaseManager 连接增加 PRAGMA busy_timeout=5000,争锁5秒快速失败而非无限等待 - BanBroadcastManager 启动时检测错位配置目录 plugins/ban/(插件只读 plugins/Sdf1_login/ban/),发现即警告指明正确路径(Linux宝塔服实测:旧版规则配置.md放错目录被误认为安全升级没生效)
This commit is contained in:
@@ -93,6 +93,27 @@ public class BanBroadcastManager implements Listener {
|
||||
reloadConfig();
|
||||
scheduleNext();
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
// ★ 二十二批:错位配置检测 —— 曾有人把 规则配置.md/json 放到
|
||||
// plugins/ban/(插件只读 plugins/Sdf1_login/ban/),表现为
|
||||
// 「安全升级没生效」。发现即警告并指明正确路径。
|
||||
try {
|
||||
File wrongDir = new File(
|
||||
plugin.getDataFolder().getParentFile(),
|
||||
"ban");
|
||||
if (wrongDir.isDirectory()) {
|
||||
String[] wrongs = wrongDir.list((d, n) ->
|
||||
n.equals("规则配置.md")
|
||||
|| n.toLowerCase(Locale.ROOT)
|
||||
.endsWith(".json"));
|
||||
if (wrongs != null && wrongs.length > 0) {
|
||||
warn("检测到错位配置目录 plugins/ban/(含 "
|
||||
+ String.join(", ", wrongs)
|
||||
+ ")——本插件只读取 "
|
||||
+ banDir.getPath()
|
||||
+ ",该目录内的配置不会生效!");
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
long cut0 = resolveStartCutoff();
|
||||
plugin.getLogger().info("[封禁播报] 已启动,模式=" + modeName()
|
||||
+ " 间隔=" + minInterval + "~" + maxInterval + "s 每页" + pageSize + "条"
|
||||
|
||||
@@ -32,6 +32,11 @@ public class DatabaseManager {
|
||||
+ dbFile.getAbsolutePath());
|
||||
Statement st = db.createStatement();
|
||||
st.execute("PRAGMA journal_mode=WAL");
|
||||
// ★ 二十二批:busy_timeout —— WAL 下读写仍会与
|
||||
// db-worker/长事务争锁,无超时会让主线程
|
||||
// sqlite3_step 无限等待(watchdog 卡点之一),
|
||||
// 5秒等锁后报 SQLITE_BUSY 快速失败。
|
||||
st.execute("PRAGMA busy_timeout=5000");
|
||||
|
||||
// 用户表
|
||||
st.execute("CREATE TABLE IF NOT EXISTS "
|
||||
|
||||
@@ -83,9 +83,10 @@ public class LoginManager {
|
||||
plugin.getDb().setField(name,
|
||||
"register_time",
|
||||
System.currentTimeMillis());
|
||||
plugin.restoreInventory(p);
|
||||
// ★ 二十二批:DB 读挪异步线程,菜单雪球延后到恢复完成回调
|
||||
plugin.restoreInventory(p,
|
||||
() -> plugin.giveMenuSnowball(p));
|
||||
plugin.recordIPLogin(p);
|
||||
plugin.giveMenuSnowball(p);
|
||||
|
||||
p.sendMessage(plugin.getConfig2()
|
||||
.msg("reg_success"));
|
||||
@@ -286,9 +287,10 @@ public class LoginManager {
|
||||
p.setAllowFlight(false);
|
||||
p.setFlying(false);
|
||||
// 只在有有效备份时恢复
|
||||
plugin.restoreInventory(p);
|
||||
// ★ 二十二批:DB 读挪异步线程,菜单雪球延后到恢复完成回调
|
||||
plugin.restoreInventory(p,
|
||||
() -> plugin.giveMenuSnowball(p));
|
||||
plugin.recordIPLogin(p);
|
||||
plugin.giveMenuSnowball(p);
|
||||
if (tempPassword) {
|
||||
// ★ 确保这行存在
|
||||
plugin.getNeedsPasswordChange().add(name);
|
||||
|
||||
@@ -2115,73 +2115,86 @@ public class Main extends JavaPlugin
|
||||
}
|
||||
|
||||
public void restoreInventory(Player p) {
|
||||
String name = p.getName();
|
||||
try {
|
||||
String[] backup =
|
||||
db.loadInventoryBackup(name);
|
||||
if (backup == null
|
||||
|| !isValidBackup(backup)) {
|
||||
return;
|
||||
restoreInventory(p, null);
|
||||
}
|
||||
|
||||
debugPrintBase64("恢复前", name,
|
||||
backup[0]);
|
||||
|
||||
/**
|
||||
* ★ 二十二批:背包读写分离 —— DB 读挪异步线程(共享 SQLite 连接
|
||||
* 上的同步 SELECT 会与 WebManager db-worker 争锁,曾致主线程
|
||||
* 卡10秒触发 Paper watchdog 转储),背包写回(setContents 等
|
||||
* Bukkit API)仍在主线程执行。afterRestore 在恢复完成后于主线程
|
||||
* 回调,保持「先恢复背包、再发菜单雪球」的原调用顺序。
|
||||
*/
|
||||
public void restoreInventory(Player p,
|
||||
Runnable afterRestore) {
|
||||
final String name = p.getName();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
||||
String[] backup = null;
|
||||
try {
|
||||
backup = db.loadInventoryBackup(name);
|
||||
} catch (Exception e) {
|
||||
getLogger().severe(
|
||||
"[Sdf1_login] 还原背包失败: " + name);
|
||||
e.printStackTrace();
|
||||
}
|
||||
final String[] b = backup;
|
||||
Bukkit.getScheduler().runTask(this, () -> {
|
||||
try {
|
||||
if (b != null && isValidBackup(b)) {
|
||||
debugPrintBase64("恢复前", name, b[0]);
|
||||
ItemStack[] contents =
|
||||
InventorySerializer
|
||||
.fromBase64(backup[0]);
|
||||
.fromBase64(b[0]);
|
||||
if (contents != null)
|
||||
p.getInventory()
|
||||
.setContents(contents);
|
||||
|
||||
if (backup[1] != null
|
||||
&& !backup[1].isEmpty()) {
|
||||
if (b[1] != null && !b[1].isEmpty()) {
|
||||
ItemStack[] armor =
|
||||
InventorySerializer
|
||||
.fromBase64(
|
||||
backup[1]);
|
||||
.fromBase64(b[1]);
|
||||
if (armor != null)
|
||||
p.getInventory()
|
||||
.setArmorContents(
|
||||
armor);
|
||||
}
|
||||
|
||||
if (backup[2] != null
|
||||
&& !backup[2].isEmpty()) {
|
||||
if (b[2] != null && !b[2].isEmpty()) {
|
||||
ItemStack[] extra =
|
||||
InventorySerializer
|
||||
.fromBase64(
|
||||
backup[2]);
|
||||
.fromBase64(b[2]);
|
||||
if (extra != null)
|
||||
p.getInventory()
|
||||
.setExtraContents(
|
||||
extra);
|
||||
}
|
||||
|
||||
int lv = Integer.parseInt(
|
||||
backup[3]);
|
||||
int lv = Integer.parseInt(b[3]);
|
||||
if (lv > 0) p.setLevel(lv);
|
||||
double xp = Double.parseDouble(
|
||||
backup[4]);
|
||||
if (xp > 0)
|
||||
p.setExp((float) xp);
|
||||
|
||||
double xp = Double.parseDouble(b[4]);
|
||||
if (xp > 0) p.setExp((float) xp);
|
||||
debugPrintBase64("恢复后", name,
|
||||
InventorySerializer.toBase64(
|
||||
p.getInventory()
|
||||
.getContents()));
|
||||
|
||||
getLogger().info(
|
||||
"[Sdf1_login] " + name
|
||||
+ " 背包已恢复");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
getLogger().severe(
|
||||
"[Sdf1_login] 还原背包失败: "
|
||||
+ name);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (afterRestore != null) {
|
||||
try {
|
||||
afterRestore.run();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void backupInventory(Player p) {
|
||||
String name = p.getName();
|
||||
@@ -2257,18 +2270,29 @@ public class Main extends JavaPlugin
|
||||
if (!p.isOnline()) return;
|
||||
if (!isFrozen(p)) return;
|
||||
|
||||
// 从数据库加载已有备份
|
||||
String[] existing =
|
||||
db.loadInventoryBackup(name);
|
||||
// ★ 二十二批:DB 读挪异步线程(watchdog 卡点 =
|
||||
// 主线程同步 SELECT 与 db-worker 争锁),结果回主线程
|
||||
// 重查 isOnline/isFrozen 再动背包。
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
||||
String[] existing = null;
|
||||
try {
|
||||
existing = db.loadInventoryBackup(name);
|
||||
} catch (Exception e) {
|
||||
getLogger().severe(
|
||||
"[Sdf1_login] 加载背包备份失败: " + name);
|
||||
e.printStackTrace();
|
||||
}
|
||||
final String[] ex = existing;
|
||||
Bukkit.getScheduler().runTask(this, () -> {
|
||||
if (!p.isOnline()) return;
|
||||
if (!isFrozen(p)) return;
|
||||
|
||||
// 调试打印
|
||||
debugPrintBase64("加入-加载DB", name,
|
||||
existing != null
|
||||
? existing[0] : null);
|
||||
ex != null ? ex[0] : null);
|
||||
|
||||
// 无有效备份 → 跳过清空背包
|
||||
if (existing == null
|
||||
|| !isValidBackup(existing)) {
|
||||
if (ex == null || !isValidBackup(ex)) {
|
||||
getLogger().info(
|
||||
"[Sdf1_login] " + name
|
||||
+ " 无有效备份,"
|
||||
@@ -2278,6 +2302,8 @@ public class Main extends JavaPlugin
|
||||
|
||||
// 有有效备份 → 清空当前背包
|
||||
hideInventory(p);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ===== Microsoft OAuth正版验证(Java仅开session+轮询,所有输入交web后端) =====
|
||||
@@ -2420,10 +2446,9 @@ public class Main extends JavaPlugin
|
||||
});
|
||||
}
|
||||
|
||||
// 只在有有效备份时恢复
|
||||
restoreInventory(p);
|
||||
|
||||
giveMenuSnowball(p);
|
||||
// 只在有有效备份时恢复(菜单雪球延后到恢复完成回调,
|
||||
// 保持「先恢复背包、再发菜单雪球」原顺序)
|
||||
restoreInventory(p, () -> giveMenuSnowball(p));
|
||||
p.sendMessage("§a[Sdf1_login] §f您已自动登录!");
|
||||
if (welcome != null) welcome.onLogin(p);
|
||||
// ★ 未绑定邮箱:登录后提示(聊天 + actionbar 15秒)
|
||||
|
||||
Reference in New Issue
Block a user