堆叠(StackConfigManager)
- 用户口径「配置损坏就交还MC原版堆叠逻辑,插件不管」:
① restoreDefaultStackSize 由 def=64 写死改为 resetData(MAX_STACK_SIZE)
重置为 Material 类型默认值(告示牌/旗帜 vanilla=16,鸡蛋=64)。
旧写死 64 会把告示牌 max 从 16 抬到 64,「交还原版」交还失败。
② 坏 json(lastJsonParseFailed)时强制 stackEnabled=false,7 个事件处理器
入口 if(!stackEnabled)return 全 return,不写任何组件、不还原、不干预,
真正交还 MC 原版。修复旧 bug:坏 json 下 stackEnabled 保持 true →
热重载仍写组件 → 必须冷启动才还原(用户实测)。
③ clearAll(catch 兜底/文件缺失)也强制 stackEnabled=false 保持语义一致。
好搜/联网(WebSearchTool)
- 用户反馈「AI 调用好搜时结果完全错」:问「旋风人/Breeze」给抖音
「Cyclo Chambers 循环房间 烟花模拟器」视频摘要,模型照抄回给玩家。
- isValidResult 加三层判定:长度>20 + 垃圾特征(烟花模拟器/减压/#游戏视频/
循环房间/抖音号)+ 相关性闸(结果须命中 query 核心词,纯无关判无效换通道)。
- 无关结果计入失败次数(searchEx 全通道无关→返回 null+attempted →
AIChatManager 算 publicFail 进 searchFailCount,事不过三老实告知)。
This commit is contained in:
@@ -177,11 +177,18 @@ public class StackConfigManager implements Listener {
|
|||||||
// 用户口径「json 损坏就停用堆叠」——坏 json 时 MD 表(模板占位行如 gold/示范-苹果)
|
// 用户口径「json 损坏就停用堆叠」——坏 json 时 MD 表(模板占位行如 gold/示范-苹果)
|
||||||
// 不应当有效配置,否则 gold 行被解析 → tableParsed=true → 不清空 → 堆叠照常。
|
// 不应当有效配置,否则 gold 行被解析 → tableParsed=true → 不清空 → 堆叠照常。
|
||||||
// 仅「无 json 块」(首次安装 extractAndLoad 提取后)才回退 MD 表。
|
// 仅「无 json 块」(首次安装 extractAndLoad 提取后)才回退 MD 表。
|
||||||
|
// ★ 续16-遗留7(交还原版,2026-11-14 用户口径):坏 json 时强制 stackEnabled=false。
|
||||||
|
// 旧逻辑坏 json 不清 stackEnabled(保持 true)→ 热重载下 7 个事件处理器仍跑,
|
||||||
|
// onInventoryOpen/click 走 cfgMax<=0 → restoreDefaultStackSize 仍写组件 → 告示牌
|
||||||
|
// max 被抬到 64(旧 def=64 写死)→ 「交还原版」交还失败、堆叠仍生效(必须冷启动才还原)。
|
||||||
|
// 改:坏 json 直接 stackEnabled=false → 处理器入口 if(!stackEnabled)return 全 return,
|
||||||
|
// 不写任何组件、不还原、不干预 → 真正交还 MC 原版堆叠逻辑,插件完全不管。
|
||||||
boolean tableParsed = false;
|
boolean tableParsed = false;
|
||||||
if (!jsonHasValidConfig) {
|
if (!jsonHasValidConfig) {
|
||||||
if (lastJsonParseFailed) {
|
if (lastJsonParseFailed) {
|
||||||
// json 块解析失败(用户删坏花括号)→ 直接清空映射
|
// json 块解析失败(用户删坏花括号)→ 直接清空映射 + 强制停用
|
||||||
plugin.getLogger().warning("[物品堆叠] ★ JSON 块解析失败(坏配置),已清空全部堆叠映射(停用本功能)");
|
stackEnabled = false; // ★ 交还原版:坏配置下处理器全 return
|
||||||
|
plugin.getLogger().warning("[物品堆叠] ★ JSON 块解析失败(坏配置),已清空全部堆叠映射并强制停用(交还MC原版堆叠逻辑)");
|
||||||
newMap.clear();
|
newMap.clear();
|
||||||
newRaw.clear();
|
newRaw.clear();
|
||||||
} else {
|
} else {
|
||||||
@@ -256,10 +263,11 @@ public class StackConfigManager implements Listener {
|
|||||||
private void clearAll(String reason) {
|
private void clearAll(String reason) {
|
||||||
stackMap.clear();
|
stackMap.clear();
|
||||||
rawConfig.clear();
|
rawConfig.clear();
|
||||||
|
stackEnabled = false; // ★ 续16-遗留8(交还原版):坏配置下强制停用,处理器全 return 不写组件
|
||||||
// ★ 续16-遗留7:置 null 而非设当前指纹 → 下次任何 checkAndReload 必因 hash 不等触发 reload+rescan,
|
// ★ 续16-遗留7:置 null 而非设当前指纹 → 下次任何 checkAndReload 必因 hash 不等触发 reload+rescan,
|
||||||
// 保证坏配置下在线玩家「已堆叠物品」被强制拆散还原,不依赖文件再次变更。
|
// 保证坏配置下在线玩家「已堆叠物品」被强制拆散还原,不依赖文件再次变更。
|
||||||
lastFileHash = null;
|
lastFileHash = null;
|
||||||
plugin.getLogger().warning("[物品堆叠] ★ 配置无效,已清空全部堆叠映射并停用本功能: " + reason);
|
plugin.getLogger().warning("[物品堆叠] ★ 配置无效,已清空全部堆叠映射并强制停用(交还MC原版堆叠逻辑): " + reason);
|
||||||
// 映射已清空 → applyStackSize 不再写新组件;已写入组件的物品需还原(强制拆散)
|
// 映射已清空 → applyStackSize 不再写新组件;已写入组件的物品需还原(强制拆散)
|
||||||
rescanOnlinePlayers();
|
rescanOnlinePlayers();
|
||||||
}
|
}
|
||||||
@@ -738,25 +746,26 @@ public class StackConfigManager implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasComponent) return false;
|
if (!hasComponent) return false;
|
||||||
// ★ 续16-遗留7(修 bug 物品,2026-11-14):def 不能用 item.getMaxStackSize()——
|
// ★ 续16-遗留7(交还原版,2026-11-14 用户口径「配置损坏就交还MC原版堆叠逻辑,插件不管」):
|
||||||
// 该物品若已带 16/1/99 等异常组件,getMaxStackSize() 读到的就是旧值,
|
// 旧逻辑把 def 写死 64(setData(MAX_STACK_SIZE, 64))——但告示牌/旗帜 vanilla 默认上限
|
||||||
// 写回会保留异常 max → 数量超 max → 客户端渲染成「未知物品」(紫色问号)。
|
// 其实是 16(不是 64),鸡蛋/不死图腾才是 64。写死 64 会让告示牌 max 从 16 被抬到 64,
|
||||||
// 固定 64(Paper 26.x 绝大多数物品 vanilla 默认):还原后物品 max=64,
|
// 「交还原版」交还失败(仍能堆到 64 而非原版 16)。
|
||||||
// 数量超 64 的会被后续 applyStackSize 钳到 64,杜绝未知物品。
|
// 改为 resetData(MAX_STACK_SIZE):Paper 26.x 官方「重置为类型默认值」API,
|
||||||
int def = 64;
|
// 把物品 max_stack_size 组件重置回该 Material 的 vanilla 默认(告示牌→16,鸡蛋→64)。
|
||||||
|
// 等价于 unsetData 但更明确表达「还原为原生默认」语义。
|
||||||
try {
|
try {
|
||||||
item.setData(io.papermc.paper.datacomponent.DataComponentTypes.MAX_STACK_SIZE, def);
|
item.resetData(io.papermc.paper.datacomponent.DataComponentTypes.MAX_STACK_SIZE);
|
||||||
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
// 兜底:无 resetData 能力(旧 Paper)→ unsetData 删组件回退类型默认
|
||||||
try {
|
try {
|
||||||
ItemMeta meta = item.getItemMeta();
|
item.unsetData(io.papermc.paper.datacomponent.DataComponentTypes.MAX_STACK_SIZE);
|
||||||
if (meta != null) {
|
return true;
|
||||||
meta.setMaxStackSize(def);
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
}
|
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
|
// 两条路都失败(物品无该组件能力)→ 视为未还原
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===================== 事件监听 =====================
|
// ===================== 事件监听 =====================
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ public class WebSearchTool {
|
|||||||
if (apiKey != null && !apiKey.isEmpty()) {
|
if (apiKey != null && !apiKey.isEmpty()) {
|
||||||
attempted++;
|
attempted++;
|
||||||
String dsResult = deepseekSearch(query, apiKey);
|
String dsResult = deepseekSearch(query, apiKey);
|
||||||
if (dsResult != null && isValidResult(dsResult)) return new SearchOutcome(dsResult, attempted);
|
if (dsResult != null && isValidResult(dsResult, query)) return new SearchOutcome(dsResult, attempted);
|
||||||
System.out.println("[WebSearchTool] DeepSeek Search 结果无效,换通道重试, query=" + query);
|
System.out.println("[WebSearchTool] DeepSeek Search 结果无效,换通道重试, query=" + query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ public class WebSearchTool {
|
|||||||
}
|
}
|
||||||
attempted++;
|
attempted++;
|
||||||
String result = publicSearch(backend, query);
|
String result = publicSearch(backend, query);
|
||||||
if (result != null && isValidResult(result)) return new SearchOutcome(result, attempted);
|
if (result != null && isValidResult(result, query)) return new SearchOutcome(result, attempted);
|
||||||
System.out.println("[WebSearchTool] " + backend + " 结果无效,换下一通道, query=" + query);
|
System.out.println("[WebSearchTool] " + backend + " 结果无效,换下一通道, query=" + query);
|
||||||
}
|
}
|
||||||
System.out.println("[WebSearchTool] 搜索无有效结果: 已试 " + attempted + " 通道("
|
System.out.println("[WebSearchTool] 搜索无有效结果: 已试 " + attempted + " 通道("
|
||||||
@@ -115,13 +115,51 @@ public class WebSearchTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ★ 第121批续16-遗留5:结果有效性判定。
|
* ★ 第121批续16-遗留5 + 续16-遗留8(好搜结果完全无关,2026-11-14 用户反馈):结果有效性判定。
|
||||||
* 好搜/必应等后端即使没匹配到内容也会拼出「搜索结果(共0条,来源:XX):」头,
|
* <p>
|
||||||
* 旧逻辑把这种空壳当成功返回 → 模型拿到手只能说「没查到」。
|
* 旧逻辑只判「长度 > 20 字」,好搜对冷门/精确 query 会返回 1 条**完全无关的抖音短视频**
|
||||||
* 判定:去掉头尾空白后长度 > 20 字(真正 5 条结果至少上百字)才算有效。
|
* (如问「旋风人」→ 给「Cyclo Chambers 循环房间 烟花模拟器」),长度远超 20 → 误判有效
|
||||||
|
* → 模型照抄这无关结果回答玩家(用户截图实证:模型把抖音视频摘要当「查到的资料」回给玩家)。
|
||||||
|
* <p>
|
||||||
|
* 新判定三层:
|
||||||
|
* <ol>
|
||||||
|
* <li>长度 > 20(防 0 条空壳);</li>
|
||||||
|
* <li>不含垃圾特征(「烟花模拟器」「减压」「#游戏视频」「抖音」等娱乐/短视频词);</li>
|
||||||
|
* <li>相关性闸:结果文本必须命中 query 的核心词(query 各词至少 1 个出现在结果里),
|
||||||
|
* 纯无关结果(如「Cyclo Chambers」对「旋风人/Breeze」)判无效 → 换下一通道。</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* @param query 本次搜索关键词(用于相关性判定)
|
||||||
|
* @param result 后端返回的结果文本
|
||||||
*/
|
*/
|
||||||
|
private static boolean isValidResult(String result, String query) {
|
||||||
|
if (result == null || result.trim().length() <= 20) return false;
|
||||||
|
String low = result.toLowerCase();
|
||||||
|
// 垃圾特征过滤:娱乐/短视频/无关视频摘要
|
||||||
|
String[] junk = {"烟花模拟器", "减压游戏", "#游戏视频", "循环房间", "抖音号"};
|
||||||
|
for (String j : junk) if (low.contains(j.toLowerCase())) {
|
||||||
|
System.out.println("[WebSearchTool] 结果命中垃圾特征「" + j + "」,判无效");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 相关性闸:query 各非停用词,至少 1 个出现在结果里
|
||||||
|
if (query != null && !query.isEmpty()) {
|
||||||
|
boolean anyHit = false;
|
||||||
|
String[] words = query.toLowerCase().split("[\\s,,、;;!!??]+");
|
||||||
|
for (String w : words) {
|
||||||
|
if (w.length() < 2) continue; // 跳过单字/标点
|
||||||
|
if (low.contains(w)) { anyHit = true; break; }
|
||||||
|
}
|
||||||
|
if (!anyHit) {
|
||||||
|
System.out.println("[WebSearchTool] 结果与 query「" + query + "」无词交集,判无关无效");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 兼容旧签名(不传 query 时只做长度+垃圾特征判定) */
|
||||||
private static boolean isValidResult(String result) {
|
private static boolean isValidResult(String result) {
|
||||||
return result != null && result.trim().length() > 20;
|
return isValidResult(result, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** searchEx 的返回载体:有效结果文本 + 尝试过的通道数 */
|
/** searchEx 的返回载体:有效结果文本 + 尝试过的通道数 */
|
||||||
|
|||||||
Reference in New Issue
Block a user