From de94df139109659af9d750706c83a72dc70d3387 Mon Sep 17 00:00:00 2001 From: youpaishidifu <1@ypshidifu.cn> Date: Thu, 19 Nov 2026 11:24:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC125=E6=89=B9=E7=BB=AD1:=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E7=AD=BE=E6=94=B6=E5=9B=9E=E6=89=A7=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E5=90=8D+=E5=85=A8=E5=B1=80=E5=8D=8F=E8=AE=AE=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ACK_DIR 统一为「签收回执」(去掉多出的「回」字),与资源文件/生产服对齐 - findPendingFiles 拆分为 findGlobalPendingFiles(用户协议:所有.md对全服生效) 和 findPlayerPendingFiles(公告:按玩家名.标题.md匹配) - 全局协议签收回执 = 玩家名.md(一个玩家一个文件) - 玩家通知签收回执 = 原文件名 - PendingSign 增加 pendingFile(绝对路径)+ ackFileName(回执文件名) - 新增日志:无待签收/已签收/待签收/签收成功 全链路可追踪 --- .../java/Sdf1_login/CustomScreenManager.java | 149 +++++++++++------- 1 file changed, 96 insertions(+), 53 deletions(-) diff --git a/src/main/java/Sdf1_login/CustomScreenManager.java b/src/main/java/Sdf1_login/CustomScreenManager.java index 7cde451..ed2f3cf 100644 --- a/src/main/java/Sdf1_login/CustomScreenManager.java +++ b/src/main/java/Sdf1_login/CustomScreenManager.java @@ -31,11 +31,12 @@ import java.util.regex.Pattern; * 用户协议 & 公告送达(第125批) * * 核心功能: - * - 玩家上线时扫描「用户协议/签收回回执/」和「公告/自定义屏幕/签收回回执/」目录 - * - 若存在未签收的通知(玩家.标题.md 存在 且 签收回回执下没有同名文件),弹出自定义屏幕 - * - 自定义屏幕:2 按钮(签收/拒签)+ 1 输入框(签名 = 玩家ID) + * - 玩家上线时扫描「用户协议/签收回执/」和「公告/自定义屏幕/签收回执/」目录 + * - 用户协议:所有 .md 对全服玩家生效(全局协议),签收回执 = 玩家名.md + * - 公告:按 玩家名.标题.md 匹配,签收回执 = 原文件名 + * - GUI:2 按钮(签收/拒签)+ 书与笔(完整协议塞入书页),死循环弹窗强制表态 * - 签收 → 落盘回执单;拒签 → 二次弹窗确认 → 执行拒签动作(del/rm/kick/ban/banip) - * - Geyser 基岩版玩家 → GUI 确认(简易聊天命令);Java 版 → 自定义屏幕 + * - Geyser 基岩版玩家 → GUI(书与笔);Java 版 → GUI(统一逻辑) */ public class CustomScreenManager implements Listener { @@ -46,8 +47,8 @@ public class CustomScreenManager implements Listener { // 目录常量 private static final String AGREEMENT_DIR = "用户协议"; private static final String NOTIFICATION_DIR = "公告/自定义屏幕"; - private static final String ACK_DIR_AGREEMENT = AGREEMENT_DIR + "/签收回回执"; - private static final String ACK_DIR_NOTIFICATION = NOTIFICATION_DIR + "/签收回回执"; + private static final String ACK_DIR_AGREEMENT = AGREEMENT_DIR + "/签收回执"; + private static final String ACK_DIR_NOTIFICATION = NOTIFICATION_DIR + "/签收回执"; // 正则:玩家.标题.md private static final Pattern FILENAME_PATTERN = Pattern.compile("^(.+)\\.(.+\\.md)$"); @@ -77,41 +78,55 @@ public class CustomScreenManager implements Listener { /** * 检查玩家是否有未签收的通知/协议,有则弹出自定义屏幕。 - * 基岩版(Geyser)→ 聊天命令确认;Java 版 → 自定义屏幕。 + * 基岩版(Geyser)→ GUI 确认;Java 版 → GUI 确认(统一逻辑,死循环弹窗)。 + * + * 用户协议目录:所有 .md 文件对全服玩家生效(全局协议),签收回执 = 玩家名.md。 + * 公告/自定义屏幕目录:按 玩家名.标题.md 匹配,签收回执 = 玩家名.标题.md。 */ private void checkAndShowPending(Player p) { String name = p.getName(); - // 1. 扫描用户协议目录 + // 1. 扫描用户协议目录(全局协议:所有 .md 对所有玩家生效) File agrDir = new File(plugin.getDataFolder(), AGREEMENT_DIR); File ackDirAgr = new File(plugin.getDataFolder(), ACK_DIR_AGREEMENT); ensureDir(ackDirAgr); - // 2. 扫描公告/自定义屏幕目录 + // 2. 扫描公告/自定义屏幕目录(按玩家名匹配) File notiDir = new File(plugin.getDataFolder(), NOTIFICATION_DIR); File ackDirNoti = new File(plugin.getDataFolder(), ACK_DIR_NOTIFICATION); ensureDir(ackDirNoti); - // 找该玩家所有待签收文件(协议 + 通知) - String[] agrFiles = findPendingFiles(agrDir, name); - String[] notiFiles = findPendingFiles(notiDir, name); + // 找该玩家所有待签收文件 + String[] agrFiles = findGlobalPendingFiles(agrDir, name); + String[] notiFiles = findPlayerPendingFiles(notiDir, name); - if (agrFiles.length == 0 && notiFiles.length == 0) return; // 无待签收 + if (agrFiles.length == 0 && notiFiles.length == 0) { + plugin.getLogger().info("[自定义屏幕] " + name + " 无待签收(全局协议=" + agrFiles.length + " 玩家通知=" + notiFiles.length + ")"); + return; // 无待签收 + } // 合并所有待签收文件 String[] all = new String[agrFiles.length + notiFiles.length]; System.arraycopy(agrFiles, 0, all, 0, agrFiles.length); System.arraycopy(notiFiles, 0, all, agrFiles.length, notiFiles.length); - all[all.length - 1] = all[all.length - 1]; // 保持引用 // 取第一个未签收的作为主弹窗(一次只弹一个) String pendingFile = all[0]; - String ackDir = pendingFile.startsWith(AGREEMENT_DIR) ? ACK_DIR_AGREEMENT : ACK_DIR_NOTIFICATION; + boolean isGlobal = pendingFile.contains(AGREEMENT_DIR); + String ackDir = isGlobal ? ACK_DIR_AGREEMENT : ACK_DIR_NOTIFICATION; - // 检查签收回执是否已存在(文件名匹配) + // 检查签收回执是否已存在 + // 全局协议:签收回执文件名 = 玩家名.md + // 玩家通知:签收回执文件名 = 原文件名(玩家名.标题.md) String fileName = new File(pendingFile).getName(); - File ackFile = new File(new File(plugin.getDataFolder(), ackDir), fileName); - if (ackFile.exists() && ackFile.length() > 0) return; // 已签收 + String ackFileName = isGlobal ? name + ".md" : fileName; + File ackFile = new File(new File(plugin.getDataFolder(), ackDir), ackFileName); + if (ackFile.exists() && ackFile.length() > 0) { + plugin.getLogger().info("[自定义屏幕] " + name + " 已签收 " + ackFileName + ",跳过弹窗"); + return; // 已签收 + } + + plugin.getLogger().info("[自定义屏幕] " + name + " 待签收: " + pendingFile + " (ack=" + ackFileName + ")"); // 读取通知内容 String content; @@ -127,23 +142,45 @@ public class CustomScreenManager implements Listener { // 基岩版走 GUI(书与笔),Java 版也走 GUI(统一逻辑,死循环弹窗) if (isBedrock(p)) { - showBedrockSign(p, fileName, content, actions); + showBedrockSign(p, pendingFile, ackFileName, content, actions); } else { - showCustomScreen(p, fileName, content, actions); + showCustomScreen(p, pendingFile, ackFileName, content, actions); } } /** - * 在目录下找玩家的所有待签收文件({name}.*.md 且签收回执下没有同名文件)。 + * 全局协议:目录下所有 .md 文件对所有玩家生效。 + * 签收回执 = 玩家名.md(一个玩家一个文件)。 */ - private String[] findPendingFiles(File dir, String playerName) { + private String[] findGlobalPendingFiles(File dir, String playerName) { + if (!dir.exists() || !dir.isDirectory()) return new String[0]; + File[] files = dir.listFiles((d, n) -> n.endsWith(".md")); + if (files == null || files.length == 0) return new String[0]; + + File ackDir = new File(plugin.getDataFolder(), ACK_DIR_AGREEMENT); + if (!ackDir.exists()) ensureDir(ackDir); + + java.util.List pending = new java.util.ArrayList<>(); + for (File f : files) { + String ackName = playerName + ".md"; // 全局协议:回执文件名 = 玩家名.md + File ackFile = new File(ackDir, ackName); + if (!ackFile.exists() || ackFile.length() == 0) { + pending.add(f.getAbsolutePath()); + break; // 一个全局协议足够,不叠加 + } + } + return pending.toArray(new String[0]); + } + + /** + * 玩家通知:按 {玩家名}.*.md 匹配,签收回执 = 原文件名。 + */ + private String[] findPlayerPendingFiles(File dir, String playerName) { if (!dir.exists() || !dir.isDirectory()) return new String[0]; File[] files = dir.listFiles((d, n) -> n.startsWith(playerName + ".") && n.endsWith(".md")); if (files == null || files.length == 0) return new String[0]; - // 签收回执目录 - String ackDirPath = (dir.getPath().contains(AGREEMENT_DIR)) ? ACK_DIR_AGREEMENT : ACK_DIR_NOTIFICATION; - File ackDir = new File(plugin.getDataFolder(), ackDirPath); + File ackDir = new File(plugin.getDataFolder(), ACK_DIR_NOTIFICATION); if (!ackDir.exists()) ensureDir(ackDir); java.util.List pending = new java.util.ArrayList<>(); @@ -185,15 +222,15 @@ public class CustomScreenManager implements Listener { * 基岩版玩家:自定义 GUI 确认(书与笔完整协议 + 签收/拒签按钮)。 * 死循环弹窗:关闭即重弹,必须表态(签收或拒签)。 */ - private void showBedrockSign(Player p, String fileName, String content, ActionConfig actions) { - PendingSign ps = new PendingSign(fileName, content, actions); + private void showBedrockSign(Player p, String pendingFile, String ackFileName, String content, ActionConfig actions) { + PendingSign ps = new PendingSign(pendingFile, ackFileName, content, actions); pendingSigs.put(p.getUniqueId(), ps); // 创建一个 3 槽 GUI:slot0=书(完整协议)、slot1=签收、slot2=拒签 - org.bukkit.inventory.Inventory gui = Bukkit.createInventory(null, 3, "§6【待签收】" + new File(fileName).getName()); + org.bukkit.inventory.Inventory gui = Bukkit.createInventory(null, 3, "§6【待签收】" + new File(pendingFile).getName()); // slot 0: 书与笔(完整协议内容) - ItemStack book = createBookItem(content, fileName); + ItemStack book = createBookItem(content, new File(pendingFile).getName()); gui.setItem(0, book); // slot 1: 签收(绿) @@ -270,9 +307,9 @@ public class CustomScreenManager implements Listener { if (!p.isOnline()) return; if (pendingSigs.containsKey(p.getUniqueId())) { if (isBedrock(p)) { - showBedrockSign(p, ps.fileName, ps.content, ps.actions); + showBedrockSign(p, ps.pendingFile, ps.ackFileName, ps.content, ps.actions); } else { - showCustomScreen(p, ps.fileName, ps.content, ps.actions); + showCustomScreen(p, ps.pendingFile, ps.ackFileName, ps.content, ps.actions); } } }, 1L); @@ -374,7 +411,7 @@ public class CustomScreenManager implements Listener { if (slot == 1 && clicked != null && clicked.getType() == Material.RED_STAINED_GLASS_PANE) { // 确认拒签 - confirmDeny(p, new File(ps.fileName).getName(), draftSignatures.get(p.getUniqueId())); + confirmDeny(p, new File(ps.pendingFile).getName(), draftSignatures.get(p.getUniqueId())); p.closeInventory(); } else if (slot == 2 && clicked != null && clicked.getType() == Material.LIME_STAINED_GLASS_PANE) { // 取消 → 恢复草稿 @@ -388,15 +425,15 @@ public class CustomScreenManager implements Listener { * 注:Paper 1.21+ 的 Dialog API 底层仍用数据包实现,为保持灵活性(动态内容), * 改用 Inventory GUI + 书与笔(完整协议塞入书页),死循环弹窗强制表态。 */ - private void showCustomScreen(Player p, String fileName, String content, ActionConfig actions) { - PendingSign ps = new PendingSign(fileName, content, actions); + private void showCustomScreen(Player p, String pendingFile, String ackFileName, String content, ActionConfig actions) { + PendingSign ps = new PendingSign(pendingFile, ackFileName, content, actions); pendingSigs.put(p.getUniqueId(), ps); // 创建一个 3 槽 GUI:slot0=书(完整协议)、slot1=签收、slot2=拒签 - org.bukkit.inventory.Inventory gui = Bukkit.createInventory(null, 3, "§6【待签收】" + new File(fileName).getName()); + org.bukkit.inventory.Inventory gui = Bukkit.createInventory(null, 3, "§6【待签收】" + new File(pendingFile).getName()); // slot 0: 书与笔(完整协议内容) - ItemStack book = createBookItem(content, fileName); + ItemStack book = createBookItem(content, new File(pendingFile).getName()); gui.setItem(0, book); // slot 1: 签收(绿) @@ -471,7 +508,7 @@ public class CustomScreenManager implements Listener { } else if (title.contains("【拒签确认】")) { if (slot == 1 && clicked != null && clicked.getType() == Material.RED_STAINED_GLASS_PANE) { // 确认拒签 - confirmDeny(p, new File(ps.fileName).getName(), draftSignatures.get(p.getUniqueId())); + confirmDeny(p, new File(ps.pendingFile).getName(), draftSignatures.get(p.getUniqueId())); p.closeInventory(); } else if (slot == 2 && clicked != null && clicked.getType() == Material.LIME_STAINED_GLASS_PANE) { // 取消 → 恢复草稿 @@ -486,27 +523,31 @@ public class CustomScreenManager implements Listener { */ private void handleAccept(Player p, PendingSign ps, String signature) { if (signature == null || signature.isEmpty()) { - p.sendMessage(Component.text("§c请先点书(slot 3)输入您的签名(游戏ID)再签收")); + p.sendMessage(Component.text("§c请先点书(slot 0)输入您的签名(游戏ID)再签收")); return; } if (!signature.equalsIgnoreCase(p.getName())) { p.sendMessage(Component.text("§c签名与您的游戏ID不匹配,请重新输入")); return; } - // 落盘回执单 - File ackDir = new File(plugin.getDataFolder(), ps.fileName.startsWith(AGREEMENT_DIR) ? ACK_DIR_AGREEMENT : ACK_DIR_NOTIFICATION); + // 落盘回执单(全局协议:回执文件名 = 玩家名.md;玩家通知:回执文件名 = 原文件名) + boolean isGlobal = ps.pendingFile.contains(AGREEMENT_DIR); + File ackDir = new File(plugin.getDataFolder(), isGlobal ? ACK_DIR_AGREEMENT : ACK_DIR_NOTIFICATION); ensureDir(ackDir); - File ackFile = new File(ackDir, ps.fileName.substring(ps.fileName.lastIndexOf('/') + 1)); + String ackName = isGlobal ? p.getName() + ".md" : new File(ps.pendingFile).getName(); + File ackFile = new File(ackDir, ackName); try { String content = "accept " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH点mm分")) + "\n"; content += "签名:" + signature + "\n"; + content += "来源:" + new File(ps.pendingFile).getName() + "\n"; Files.write(ackFile.toPath(), content.getBytes(java.nio.charset.StandardCharsets.UTF_8)); } catch (IOException ex) { plugin.getLogger().warning("[自定义屏幕] 写入回执单失败: " + ex.getMessage()); p.sendMessage(Component.text("§c回执单写入失败,请联系管理员")); return; } - p.sendMessage(Component.text("§a已签收:" + new File(ps.fileName).getName())); + plugin.getLogger().info("[自定义屏幕] " + p.getName() + " 签收成功: " + ackName + "(来源 " + new File(ps.pendingFile).getName() + ")"); + p.sendMessage(Component.text("§a已签收:" + new File(ps.pendingFile).getName())); cleanupUI(p); pendingSigs.remove(p.getUniqueId()); draftSignatures.remove(p.getUniqueId()); @@ -518,9 +559,9 @@ public class CustomScreenManager implements Listener { private void handleDeny(Player p, PendingSign ps) { // 二次确认:用聊天命令 p.sendMessage(Component.text("§c§l【拒签确认】")); - p.sendMessage(Component.text("§7您即将拒签「" + new File(ps.fileName).getName() + "」")); + p.sendMessage(Component.text("§7您即将拒签「" + new File(ps.pendingFile).getName() + "」")); p.sendMessage(Component.text("§e拒签后果:" + ps.actions.denyAction)); - p.sendMessage(Component.text("§7输入 /sdf1_login confirm deny " + new File(ps.fileName).getName() + " 确认拒签,或 /sdf1_login cancel 取消")); + p.sendMessage(Component.text("§7输入 /sdf1_login confirm deny " + new File(ps.pendingFile).getName() + " 确认拒签,或 /sdf1_login cancel 取消")); pendingSigs.put(p.getUniqueId(), ps); // 保持待处理状态 } @@ -536,8 +577,8 @@ public class CustomScreenManager implements Listener { player.sendMessage(Component.text("§c未找到待签收通知")); return; } - if (!ps.fileName.contains(title)) { - player.sendMessage(Component.text("§c标题不匹配,当前待签收:" + new File(ps.fileName).getName())); + if (!new File(ps.pendingFile).getName().contains(title)) { + player.sendMessage(Component.text("§c标题不匹配,当前待签收:" + new File(ps.pendingFile).getName())); return; } // 执行拒签动作 @@ -697,8 +738,8 @@ public class CustomScreenManager implements Listener { p.sendMessage(Component.text("§c未找到待签收通知,请重新上线")); return true; } - if (!ps.fileName.contains(title)) { - p.sendMessage(Component.text("§c标题不匹配,当前待签收:" + new File(ps.fileName).getName())); + if (!new File(ps.pendingFile).getName().contains(title)) { + p.sendMessage(Component.text("§c标题不匹配,当前待签收:" + new File(ps.pendingFile).getName())); return true; } handleAccept(p, ps, signature); @@ -717,7 +758,7 @@ public class CustomScreenManager implements Listener { p.sendMessage(Component.text("§c未找到待签收通知")); return true; } - if (!ps.fileName.contains(title)) { + if (!new File(ps.pendingFile).getName().contains(title)) { p.sendMessage(Component.text("§c标题不匹配")); return true; } @@ -755,7 +796,7 @@ public class CustomScreenManager implements Listener { p.sendMessage(Component.text("§c未找到待签收通知")); return true; } - if (!ps.fileName.contains(title)) { + if (!new File(ps.pendingFile).getName().contains(title)) { p.sendMessage(Component.text("§c标题不匹配")); return true; } @@ -766,11 +807,13 @@ public class CustomScreenManager implements Listener { // ==================== 内部类 ==================== private static class PendingSign { - final String fileName; + final String pendingFile; // 绝对路径(用户协议/player.md 或 公告/自定义屏幕/玩家.标题.md) + final String ackFileName; // 回执文件名(全局协议=玩家名.md,玩家通知=原文件名) final String content; final ActionConfig actions; - PendingSign(String fileName, String content, ActionConfig actions) { - this.fileName = fileName; + PendingSign(String pendingFile, String ackFileName, String content, ActionConfig actions) { + this.pendingFile = pendingFile; + this.ackFileName = ackFileName; this.content = content; this.actions = actions; }