四个修复:
1. JSON 块泄漏(截图1):checkAndShowPending 读取 content 后剥离 markdown 内嵌 json 动作配置块
(stripJsonBlock 正则 (?s)),展示正文不再含 accept/deny 元数据。
parseActionConfig 仍在原文上调用(配置解析不受影响),展示与解析解耦。
2. CLI 组件泄露(截图3):showList 的 Component.text("§e"+i+"§f "+Component.text(key))
外层 + 触发内层 Component.toString() → 打印 ComponentImpl{content=...,style=...,decorations=...}。
改为直接字符串拼接 key。
3. CLI 吞普通聊天(截图铁证 come on baby/?/不是保护吗?全被当协议名拦截):
onChat 拦截范围收窄——只拦截数字 1~N、精确等于已签协议 key、或匹配「公告:xxx」/「xxx.md」的聊天;
其它普通聊天放行(只提示 /rules 查看方式,不 cancel)。
4. 书与笔元数据创建失败("元数据创建失败"):
改用 new ItemStack(Material.BOOK,1).getItemMeta() 直接取 BookMeta(vanilla BOOK 专属 meta 类型);
兜底:若 instanceof 仍失败,聊天贴全文(paginate 150/页)不卡死。
5. 隐私隔离(用户铁令"只能查看自己签过的和用户协议"):
玩家通知回执筛选从"遍历目录下所有 .md"改为"按 玩家名. 前缀筛选"(notiDir.listFiles(n.startsWith(playerName+"."))),
只看自己签过的,不再列出他人签过的协议。
编译 rc=0,jar 9d1893d6。
This commit is contained in:
@@ -195,11 +195,14 @@ public class CustomScreenManager implements Listener {
|
||||
// 提取动作配置
|
||||
ActionConfig actions = parseActionConfig(content, fileName);
|
||||
|
||||
// ★ 125 续15i:展示正文剥离内嵌 JSON 动作配置块(元数据不进玩家视野)
|
||||
String displayContent = stripJsonBlock(content);
|
||||
|
||||
// 基岩版走 GUI(书与笔),Java 版也走 GUI(统一逻辑,死循环弹窗)
|
||||
if (isBedrock(p)) {
|
||||
showBedrockSign(p, pendingFile, ackFileName, content, actions);
|
||||
showBedrockSign(p, pendingFile, ackFileName, displayContent, actions);
|
||||
} else {
|
||||
showCustomScreen(p, pendingFile, ackFileName, content, actions);
|
||||
showCustomScreen(p, pendingFile, ackFileName, displayContent, actions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,6 +256,21 @@ public class CustomScreenManager implements Listener {
|
||||
if (!dir.exists()) dir.mkdirs();
|
||||
}
|
||||
|
||||
/**
|
||||
* ★ 125 续15i:剥离 markdown 内嵌 ```json ... ``` 块(动作配置),只留正文。
|
||||
* 根因:JSON 块(accept/deny 动作配置)是服务端元数据,不该出现在玩家看到的 GUI 正文/书里。
|
||||
* 截图1 铁证:2111.测试1 的 JSON 块「```json {"accept":"","deny":"kick"}```」直接渲染在 GUI 正文里。
|
||||
* 解析配置用原文(parseActionConfig 在剥离前调用),展示用剥离后正文,二者解耦。
|
||||
*/
|
||||
private String stripJsonBlock(String raw) {
|
||||
if (raw == null) return null;
|
||||
// 删除 ```json ... ``` 块(含围栏行),保留其余正文
|
||||
String stripped = raw.replaceAll("(?s)```\\s*json\\s*\\n[\\s\\S]*?```", "");
|
||||
// 清理剥离后多余的空行(连续 3 个以上换行压成 2 个)
|
||||
stripped = stripped.replaceAll("\\n{3,}", "\n\n");
|
||||
return stripped.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为基岩版玩家(Geyser 代理)。
|
||||
*/
|
||||
|
||||
@@ -84,22 +84,20 @@ public class RulesCLIManager implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 玩家通知:玩家名.标题.md
|
||||
// 玩家通知:玩家名.标题.md(隐私隔离:只列该玩家自己的通知,不能看别人签的)
|
||||
File notiDir = new File(plugin.getDataFolder(), ACK_DIR_NOTIFICATION);
|
||||
if (notiDir.exists()) {
|
||||
File[] files = notiDir.listFiles((d, n) -> n.endsWith(".md") && n.indexOf('.') != n.lastIndexOf('.'));
|
||||
// ★ 125 续15i 隐私隔离:按"玩家名."前缀筛选回执,只看自己签过的;
|
||||
// 旧逻辑遍历目录下所有 .md 回执(含他人),导致 /rules 列出别人签过的协议。
|
||||
File[] files = notiDir.listFiles((d, n) -> n.endsWith(".md") && n.startsWith(playerName + "."));
|
||||
if (files != null) {
|
||||
for (File f : files) {
|
||||
String base = f.getName();
|
||||
int dot = base.indexOf('.');
|
||||
if (dot < 0) continue;
|
||||
String title = base.substring(dot + 1);
|
||||
if (title.equalsIgnoreCase(playerName)) continue; // 跳过全局协议回执
|
||||
String content = readFile(f);
|
||||
String source = parseSource(content);
|
||||
File sourceFile = new File(notiDir.getParentFile(), source != null ? source : title);
|
||||
File sourceFile = new File(notiDir.getParentFile(), source != null ? source : base);
|
||||
if (sourceFile.exists()) {
|
||||
result.put("公告:" + source, sourceFile.getAbsolutePath());
|
||||
result.put("公告:" + sourceFile.getName(), sourceFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,7 +203,10 @@ public class RulesCLIManager implements Listener {
|
||||
int i = 0;
|
||||
for (String key : signed.keySet()) {
|
||||
i++;
|
||||
p.sendMessage(Component.text(" §e" + i + "§f " + Component.text(key)));
|
||||
// ★ 125 续15i 修 CLI 组件泄露:Component.text(key) 嵌套在 Component.text 字符串拼接里,
|
||||
// 外层 "+" 触发内层 Component.toString() → 打印 ComponentImpl{content=..., style=..., decorations=...}(截图3 铁证)。
|
||||
// 改正:key 是纯字符串,直接拼接,不再包一层 Component。
|
||||
p.sendMessage(Component.text(" §e" + i + "§f " + key));
|
||||
}
|
||||
p.sendMessage(Component.text("§7输入 1~" + i + " 调出原文 | /rules prev|next 翻页 | back 返回 | quit 退出 | /rules gui 开 GUI"));
|
||||
}
|
||||
@@ -329,15 +330,31 @@ public class RulesCLIManager implements Listener {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// 数字 1~N → 跳协议
|
||||
// 数字 1~N → 跳协议(拦截)
|
||||
if (msg.matches("\\d+")) {
|
||||
openAgreement(p, msg, 1);
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// 协议名(含「公告:xxx」或纯 xxx.md)→ 跳协议
|
||||
// ★ 125 续15i 修 CLI 卡死:只拦截"已签协议名精确匹配"的聊天,其它聊天放行。
|
||||
// 旧逻辑把任意聊天("come on baby"、"?"、"不是保护吗?")都当协议名吞掉(截图铁证)。
|
||||
// 现在:消息精确等于某已签协议 key,或匹配 "公告:xxx"/"xxx.md" → 拦截跳协议;否则放行。
|
||||
LinkedHashMap<String, String> signed = listSignedAgreements(p.getName());
|
||||
boolean isKnown = false;
|
||||
for (String k : signed.keySet()) {
|
||||
if (msg.equalsIgnoreCase(k) || msg.equalsIgnoreCase(k.replaceAll("^公告:", ""))
|
||||
|| msg.equals(k) || msg.equals(k + ".md") || msg.equals("公告:" + k)) {
|
||||
isKnown = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isKnown) {
|
||||
openAgreement(p, msg, 1);
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// 未知聊天 → 放行(不拦截),提示可输入协议名/数字调出原文
|
||||
p.sendMessage(Component.text("§7(/rules 提示:输入 1~" + signed.size() + " 或协议名调出原文,quit 退出查看模式,普通聊天不受影响)"));
|
||||
}
|
||||
|
||||
/** 分页:每页最多 pageSize 字,按行切分(一行不跨页) */
|
||||
@@ -449,58 +466,25 @@ public class RulesCLIManager implements Listener {
|
||||
p.sendMessage(Component.text("§c协议原文「" + key + "」读取失败。"));
|
||||
return;
|
||||
}
|
||||
// 创建 BOOK 物品(含协议内容分页,每页最多 387 字符,vanilla 书页容量)
|
||||
ItemStack book = createBookItem(content, key);
|
||||
if (book == null) {
|
||||
p.sendMessage(Component.text("§c书与笔创建失败。"));
|
||||
return;
|
||||
}
|
||||
ItemMeta meta = book.getItemMeta();
|
||||
if (meta instanceof BookMeta) {
|
||||
BookMeta bm = (BookMeta) meta;
|
||||
// ★ 125 续15i:new ItemStack(BOOK).getItemMeta() 在新版 Paper 里返回 BookMeta(Material.BOOK 专属 meta 类型)。
|
||||
// 若拿不到 BookMeta → 走聊天全文兜底(不卡)。
|
||||
ItemStack bookItem = new ItemStack(Material.BOOK, 1);
|
||||
ItemMeta rawMeta = bookItem.getItemMeta();
|
||||
if (rawMeta instanceof BookMeta) {
|
||||
BookMeta bm = (BookMeta) rawMeta;
|
||||
bm.setTitle("§6" + key);
|
||||
bm.setAuthor("Sdf1_login");
|
||||
List<String> pages = paginate(content, 380);
|
||||
bm.setPages(pages);
|
||||
p.openBook(bm);
|
||||
p.sendMessage(Component.text("§a已打开书与笔「" + key + "」。右键翻页,合上后再次右键可继续。"));
|
||||
p.sendMessage(Component.text("§a已打开书与笔「" + key + "」(共 " + pages.size() + " 页),右键翻页,合上后再次右键可继续。"));
|
||||
} else {
|
||||
p.sendMessage(Component.text("§c书与笔元数据创建失败。"));
|
||||
// 终极兜底:聊天贴全文(不卡)
|
||||
p.sendMessage(Component.text("§c书与笔元数据创建失败(Material.BOOK 的 ItemMeta 不是 BookMeta),改用聊天展示:"));
|
||||
for (String pg : paginate(content, 150)) {
|
||||
p.sendMessage(Component.text("§7" + pg));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 创建书与笔(Material.BOOK 可读版,含完整协议内容分页)。复用 CustomScreenManager 范式。 */
|
||||
private ItemStack createBookItem(String content, String fileName) {
|
||||
ItemStack book = new ItemStack(Material.BOOK, 1);
|
||||
ItemMeta meta = book.getItemMeta();
|
||||
if (meta instanceof BookMeta) {
|
||||
BookMeta bm = (BookMeta) meta;
|
||||
bm.setTitle("§6" + fileName);
|
||||
bm.setAuthor("Sdf1_login");
|
||||
// 协议内容分块写入(每页最多 387 字符,vanilla 书页容量)
|
||||
List<String> pages = new ArrayList<>();
|
||||
String[] lines = content.split("\\n");
|
||||
StringBuilder page = new StringBuilder();
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String line = lines[i];
|
||||
if (page.length() + line.length() > 387) {
|
||||
if (page.length() > 0) {
|
||||
pages.add(page.toString());
|
||||
page.setLength(0);
|
||||
}
|
||||
if (line.length() > 387) {
|
||||
// 超长行拆分
|
||||
for (int j = 0; j < line.length(); j += 387) {
|
||||
int end = Math.min(j + 387, line.length());
|
||||
pages.add(line.substring(j, end));
|
||||
}
|
||||
} else {
|
||||
page.append(line).append('\n');
|
||||
}
|
||||
} else {
|
||||
page.append(line).append('\n');
|
||||
}
|
||||
}
|
||||
if (page.length() > 0) pages.add(page.toString());
|
||||
bm.setPages(pages);
|
||||
book.setItemMeta(meta);
|
||||
}
|
||||
return book;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user