第58批修复:
- 领地误删致命bug:AreaProtection 改用 userExistsIgnoreCase(SQL异常返回true,不误删) - getConnection 自动重连:连接已关闭时重建,解决 SN/信誉同步 database connection closed - userExists/userExistsIgnoreCase/userExistsStrict 改用 getConnection() 自动重连 - AI配置解析跳过诊断日志:findProviderUrl 返回 null 时输出具体供应商名和路径,便于排查 0个模型 问题
This commit is contained in:
@@ -274,7 +274,10 @@ public class AIChatManager {
|
||||
boolean isCustom = supplierConfig.has("baseurl");
|
||||
boolean isBuiltin = supplierConfig.has("供应商名字");
|
||||
|
||||
if (!isCustom && !isBuiltin) continue;
|
||||
if (!isCustom && !isBuiltin) {
|
||||
plugin.getLogger().info("[AI聊天] 配置跳过[" + key + "]: 既无baseurl也无供应商名字");
|
||||
continue;
|
||||
}
|
||||
|
||||
String baseUrl;
|
||||
String apiKey = getStr(supplierConfig, "apikey");
|
||||
@@ -286,9 +289,14 @@ public class AIChatManager {
|
||||
} else {
|
||||
String providerName = getStr(supplierConfig, "供应商名字");
|
||||
baseUrl = findProviderUrl(providerName);
|
||||
if (baseUrl == null || baseUrl.isEmpty()) {
|
||||
plugin.getLogger().warning("[AI聊天] 配置跳过[" + key + "]: 内置供应商 '" + providerName + "' 在 供应商.json 中找不到URL");
|
||||
plugin.getLogger().warning("[AI聊天] 诊断: 请确认 供应商.json 中存在路径 '" + providerName + "',且路径拼写完全正确");
|
||||
}
|
||||
}
|
||||
|
||||
if (baseUrl == null || baseUrl.isEmpty() || apiKey == null || apiKey.isEmpty()) {
|
||||
plugin.getLogger().warning("[AI聊天] 配置跳过[" + key + "]: baseUrl=" + baseUrl + ", apiKey=" + apiKey);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -10911,8 +10911,11 @@ public class AreaProtection implements Listener {
|
||||
String reason = (String) o[1];
|
||||
if (reason == null) {
|
||||
if (dbMgr == null) continue;
|
||||
// ★ 第58批修复:SQL 异常时 userExists 返回 false,
|
||||
// 会把 DB 抖动误判为"账户已注销"从而删领地。
|
||||
// 改用 userExistsIgnoreCase(异常返回 true,宁可放过)。
|
||||
try {
|
||||
if (!dbMgr.userExists(ac.owner)) {
|
||||
if (!dbMgr.userExistsIgnoreCase(ac.owner)) {
|
||||
reason = "账户已注销";
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
@@ -526,7 +526,24 @@ public class DatabaseManager {
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取数据库连接,连接已关闭时自动重连。★ 第58批修复:避免 SN/信誉同步等模块拿到已关闭连接报 "database connection closed"。 */
|
||||
public Connection getConnection() {
|
||||
try {
|
||||
if (db == null || db.isClosed()) {
|
||||
File dbDir = new File(dataFolder, "登录凭证");
|
||||
dbDir.mkdirs();
|
||||
File dbFile = new File(dbDir, "login.db");
|
||||
db = DriverManager.getConnection(
|
||||
"jdbc:sqlite:" + dbFile.getAbsolutePath());
|
||||
Statement st = db.createStatement();
|
||||
st.execute("PRAGMA journal_mode=WAL");
|
||||
st.execute("PRAGMA busy_timeout=5000");
|
||||
st.close();
|
||||
logger.warning("[Sdf1_login] 数据库连接已自动重建");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.severe("[Sdf1_login] 数据库自动重连失败: " + e.getMessage());
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
@@ -704,7 +721,7 @@ public class DatabaseManager {
|
||||
|
||||
public boolean userExists(String name) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
PreparedStatement ps = getConnection().prepareStatement(
|
||||
"SELECT 1 FROM users "
|
||||
+ "WHERE player_name=?");
|
||||
ps.setString(1, name);
|
||||
@@ -724,7 +741,7 @@ public class DatabaseManager {
|
||||
public boolean userExistsIgnoreCase(String name) {
|
||||
if (name == null || name.isEmpty()) return false;
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
PreparedStatement ps = getConnection().prepareStatement(
|
||||
"SELECT 1 FROM users "
|
||||
+ "WHERE player_name=? "
|
||||
+ "COLLATE NOCASE");
|
||||
@@ -747,7 +764,7 @@ public class DatabaseManager {
|
||||
public boolean userExistsStrict(String name) {
|
||||
if (name == null || name.isEmpty()) return false;
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
PreparedStatement ps = getConnection().prepareStatement(
|
||||
"SELECT 1 FROM users "
|
||||
+ "WHERE player_name=? "
|
||||
+ "COLLATE NOCASE");
|
||||
|
||||
Reference in New Issue
Block a user