From 726896728189766f3c748ad1488e25a7bdab2c88 Mon Sep 17 00:00:00 2001 From: youpaishidifu <1@ypshidifu.cn> Date: Wed, 4 Nov 2026 09:28:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC76=E6=89=B9=E8=A1=A52=EF=BC=9AloadBlac?= =?UTF-8?q?klistFromPath=E5=A2=9E=E9=87=8F=E9=87=8D=E8=BD=BD=EF=BC=88?= =?UTF-8?q?=E6=8C=87=E7=BA=B9=E5=AF=B9=E6=AF=94=EF=BC=8C=E6=97=A0=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E9=97=AD=E5=98=B4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Sdf1_login/AIChatManager.java | 51 ++++++++++++--------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/main/java/Sdf1_login/AIChatManager.java b/src/main/java/Sdf1_login/AIChatManager.java index 0a84b2c..639f8a3 100644 --- a/src/main/java/Sdf1_login/AIChatManager.java +++ b/src/main/java/Sdf1_login/AIChatManager.java @@ -1831,38 +1831,47 @@ public class AIChatManager { } try { int totalCount = 0; - // ★ 第76批:支持目录扫描——路径是目录则遍历所有 .json,是文件则当单文件读 + // ★ 第76批补:增量重载——用指纹对比文件内容,无变化闭嘴、有变化才打印 + // 复用 blacklistFileKeywords/blacklistFileHashes 映射 + java.util.List targetFiles = new java.util.ArrayList<>(); if (resolved.isDirectory()) { File[] jsonFiles = resolved.listFiles((dir, name) -> name.endsWith(".json")); if (jsonFiles != null) { - for (File jsonFile : jsonFiles) { - try { - String content = Files.readString(jsonFile.toPath(), StandardCharsets.UTF_8); - JsonArray arr = JsonParser.parseString(content).getAsJsonArray(); - for (JsonElement el : arr) { - if (el.isJsonPrimitive()) { - blacklist.add(el.getAsString()); - totalCount++; - } - } - plugin.getLogger().info("[AI聊天] 已加载黑名单文件: " + jsonFile.getName() + "(" + arr.size() + " 个关键词)"); - } catch (Exception e) { - plugin.getLogger().warning("[AI聊天] 加载黑名单文件失败: " + jsonFile.getName() + " - " + e.getMessage()); - } - } + targetFiles.addAll(java.util.Arrays.asList(jsonFiles)); } } else { - // 单文件 - String content = Files.readString(resolved.toPath(), StandardCharsets.UTF_8); + targetFiles.add(resolved); + } + for (File jsonFile : targetFiles) { + String fileName = jsonFile.getName(); + String content = Files.readString(jsonFile.toPath(), StandardCharsets.UTF_8); + String newHash = crc32(content); + String oldHash = blacklistFileHashes.get(fileName); + if (newHash.equals(oldHash)) { + continue; // 文件没变 → 内存不动,闭嘴 + } + // 有变化或新文件:加载关键词 + java.util.List newKeywords = new java.util.ArrayList<>(); JsonArray arr = JsonParser.parseString(content).getAsJsonArray(); for (JsonElement el : arr) { if (el.isJsonPrimitive()) { - blacklist.add(el.getAsString()); - totalCount++; + newKeywords.add(el.getAsString()); } } + if (blacklistFileKeywords.containsKey(fileName)) { + blacklist.removeAll(blacklistFileKeywords.get(fileName)); + plugin.getLogger().info("[AI聊天] 黑名单文件已更新: " + fileName + "(" + newKeywords.size() + " 个关键词)"); + } else { + plugin.getLogger().info("[AI聊天] 已加载黑名单文件: " + fileName + "(" + newKeywords.size() + " 个关键词)"); + } + blacklist.addAll(newKeywords); + blacklistFileKeywords.put(fileName, newKeywords); + blacklistFileHashes.put(fileName, newHash); + totalCount += newKeywords.size(); + } + if (totalCount > 0) { + plugin.getLogger().info("[AI聊天] 已从路径加载黑名单: " + rawPath + "(" + totalCount + " 个关键词)"); } - plugin.getLogger().info("[AI聊天] 已从路径加载黑名单: " + rawPath + "(" + totalCount + " 个关键词)"); } catch (Exception e) { plugin.getLogger().warning("[AI聊天] 加载黑名单路径失败: " + rawPath + " - " + e.getMessage()); }