diff --git a/src/main/java/Sdf1_login/AIChatManager.java b/src/main/java/Sdf1_login/AIChatManager.java index 4d2e4c5..41ec535 100644 --- a/src/main/java/Sdf1_login/AIChatManager.java +++ b/src/main/java/Sdf1_login/AIChatManager.java @@ -902,6 +902,29 @@ public class AIChatManager { // final 副本:lambda 需要 effectively final final String finalModelFull = modelFull; + // ★ 第93批-问题3:出网前第二道闸(三闸体系第2道)。 + // 第1道=sendToModel 开头的黑名单/admin/话题域预拦;第2道=真的要把请求体 + // 发出去之前再检查一遍——handleloadConfig 期间面板可能热更新黑名单/词表, + // 动态变更期间发送链路可能夹着旧名单,出网前再查一遍保证拦得住。 + String preNetAdminHit = matchAdminKeywords(prompt); + if (preNetAdminHit != null) { + plugin.getLogger().info("[AI聊天] 出网前管理员词第二轮拦截[" + preNetAdminHit + "]: " + + prompt.substring(0, Math.min(50, prompt.length()))); + if (player != null) { + player.sendMessage("§d§l[AI] §f" + fallbackDodge()); + } + return; + } + String preNetBlacklistHit = matchBlacklistKeyword(prompt); + if (preNetBlacklistHit != null) { + plugin.getLogger().info("[AI聊天] 出网前黑名单第二轮拦截[" + preNetBlacklistHit + "]: " + + prompt.substring(0, Math.min(50, prompt.length()))); + if (player != null) { + player.sendMessage("§c[AI聊天] §f我无法就此问题,展开讨论和回答"); + } + return; + } + // 异步发送请求 CompletableFuture.supplyAsync(() -> { try { @@ -1430,6 +1453,17 @@ public class AIChatManager { plugin.getLogger().warning("[AI聊天] 输出守卫:回复命中敏感话题[" + hit + "],改发婉拒"); return fallbackDodge(); } + + // ★ 第93批-问题4:管理员向内容输出侧检查(第3道闸) + // 玩家问「命令方块怎么获得」时提示词能婉拒,但输出侧仍需兜底: + // 若模型依然输出了管理员物品(命令方块/调试棒等)名字,改发角色化婉拒, + // 绝不让管理员内容到达玩家端。 + String adminOutHit = matchAdminKeywords(r); + if (adminOutHit != null) { + plugin.getLogger().warning("[AI聊天] 输出守卫:回复命中管理员向关键词[" + adminOutHit + "],拦截"); + return fallbackDodge(); + } + return reply; } @@ -1508,12 +1542,12 @@ public class AIChatManager { * 英文词只收录原型(commandblock/barrier/bedrock),变体由 matchAdminKeywords 归一化比较兜住。 */ private static final String[] ADMIN_CONTENT_KEYWORDS = { - // 中文 - "命令方块", "基岩", "屏障", "提权", "权限插件", "调试棒", + // 中文:管理向的方块/物品/权限/运维词 + "命令方块", "命令矿车", "结构方块", "基岩", "屏障", "提权", "权限插件", "调试棒", "op权限", "op 权限", "管理员权限", "后台", "运维", "部署", "stop指令", "停止服务器", "服务器停止", "管理玩法", // 英文(归一化后覆盖 command_block / command block / COMMAND_BLOCK / B_A_R_R_I_E_R 等变体) - "commandblock", "barrier", "bedrock", + "commandblock", "commandminecart", "structureblock", "barrier", "bedrock", "debugstick", }; /** @@ -2065,7 +2099,12 @@ public class AIChatManager { for (String kw : blacklist) { if (kw == null || kw.isEmpty()) continue; if (isAscii(kw)) { - if (lower.contains(kw.toLowerCase(java.util.Locale.ROOT))) return kw; + // ★ 第93批:ASCII 词归一化匹配(去空格/下划线/连字符/点号)—— + // 覆盖 command_block / command block / COMMAND_BLOCK / B_A_R_R_I_E_R 等变体, + // 防止玩家用点号变体绕过英文词黑名单。 + String normContent = lower.replaceAll("[\\s_\\-.]+", ""); + String normKw = kw.toLowerCase(java.util.Locale.ROOT).replaceAll("[\\s_\\-.]+", ""); + if (normContent.contains(normKw)) return kw; } else { if (content.contains(kw)) return kw; if (kw.length() >= 2 && content.contains(kw.substring(0, 2))) return kw; diff --git a/src/main/java/Sdf1_login/Main.java b/src/main/java/Sdf1_login/Main.java index 6383b09..4d903ff 100644 --- a/src/main/java/Sdf1_login/Main.java +++ b/src/main/java/Sdf1_login/Main.java @@ -207,6 +207,8 @@ public class Main extends JavaPlugin /** ★ 第30批:群控黑名单(软折磨) */ public BlacklistManager blacklist; private TeleportManager teleportMgr; + /** ★ 第93批:地狱门传送接管(记录门A/门B,从记录门出境时取消原版128搜索、指定坐标交原版传送) */ + private NetherPortalManager netherPortalMgr; private HomeManager homeMgr; private DeathReport deathReport; private QuickBack quickBack; @@ -874,6 +876,10 @@ public class Main extends JavaPlugin teleportMgr.initDatabase(); teleportMgr.startExpirationTimer(); // 启动请求过期定时器 + // ★ 第93批:地狱门传送接管(监听 PortalEnter/Exit,双向记录门A/门B) + netherPortalMgr = new NetherPortalManager(this); + getServer().getPluginManager().registerEvents(netherPortalMgr, this); + // 注册传送命令执行器和Tab补全 getCommand("tpa").setExecutor(this); getCommand("tpaccept").setExecutor(this); diff --git a/src/main/java/Sdf1_login/NetherPortalManager.java b/src/main/java/Sdf1_login/NetherPortalManager.java new file mode 100644 index 0000000..2fdac7c --- /dev/null +++ b/src/main/java/Sdf1_login/NetherPortalManager.java @@ -0,0 +1,322 @@ +package Sdf1_login; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerPortalEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * ★ 第93批:地狱门(下界传送门)传送接管。 + * + * ★ 用户最终定案(第4轮沟通): + * 「逻辑完全尊重原版逻辑。记录玩家。从主世界进来的地狱门和进来之后到达的第1个地狱门。 + * 从哪个门进就从哪个门出。如果没有从记录的地狱门出境,就交还原版逻辑。 + * 如果是从记录的地狱门出境,插件自动接管,不要直接传送。就走原版的逻辑。 + * 原版怎么传送,咱就怎么传送。只是把原版的128格之内的搜索取消, + * 咱们指定一个坐标。让原版逻辑把用户传到咱们指定的这个传送门坐标就行」 + * + * 实现要点(Paper 26.2 API 适配): + * - Paper 26.2 没有 PlayerPortalEnter/ExitEvent,统一使用 PlayerPortalEvent(继承 PlayerTeleportEvent, + * 带 setTo/setSearchRadius/setCanCreatePortal)。事件触发时 vanilla 已算好 to,监听器把 to 覆盖为 + * 记录的「主世界门A前站位」,不 cancel——vanilla 随后按事件 to 执行原版传送(与原版 portal 传送同一个入口)。 + * - 方向判定: + * ① 主世界→下界(from=NORMAL, to=NETHER):记录主世界站位 mainStamp,什么都不改 → vanilla 完成128搜索穿越 + * ② 下界→主世界(from=NETHER, to=NORMAL): + * · 无记录/非首次出境 → 交还原版(原样不碰事件) + * · 首次出境:玩家穿越瞬间的位置就是「第1个下界门B」→ 记录基准后立即接管 + * · 后续出境:玩家所在门与 netherStamp 水平距离≤5 才接管,否则交还原版 + * - 门A存活:取 mainStamp 玩家脚部位置为基础,向门体外侧探测站位(避开 portal 平面,防循环穿越) + * - 门A被毁(3料无 portal 方块):按原版重建 obsidian 门框 + fire(vanilla 会在玩家靠近时生成门板) + */ +public class NetherPortalManager implements Listener { + + private final Main plugin; + + /** 玩家 UUID → 该次下界往返记录。 */ + private final Map records = new HashMap<>(); + + /** 上一次插件回程接管刚完成的玩家(1 tick 缓冲,落点触发的 portal 事件应被忽略)。 */ + private final Map recentBack = new HashMap(); + + public NetherPortalManager(Main plugin) { + this.plugin = plugin; + } + + private static final class PortalRecord { + Location mainStamp; // 主世界门A:进入瞬间的站位(回程目标基准) + Location netherStamp; // 下界门B:第1次出境事件时玩家所在位置(门B认同基准) + } + + // ================= 主入口:portal 穿越事件 ================= + + /** + * 玩家被 portal 传送的瞬间触发(vanilla 已算好 to,尚未执行传送)。 + */ + @EventHandler(priority = EventPriority.MONITOR) + public void onPortalCross(PlayerPortalEvent e) { + Player p = e.getPlayer(); + Location from = e.getFrom(), to = e.getTo(); + if (from == null || to == null || from.getWorld() == null || to.getWorld() == null) { + return; + } + World.Environment fEnv = from.getWorld().getEnvironment(); + World.Environment tEnv = to.getWorld().getEnvironment(); + UUID pid = p.getUniqueId(); + + // ===== ① 主世界 → 下界:记录门A,vanilla 正常完成 128 搜索穿越 ===== + if (fEnv == World.Environment.NORMAL && tEnv == World.Environment.NETHER) { + if (Boolean.TRUE.equals(recentBack.remove(pid))) { + plugin.getLogger().info("[地狱门接管] 玩家 " + p.getName() + " 传送后落点误触发,已打消"); + return; + } + PortalRecord rec = records.computeIfAbsent(pid, k -> new PortalRecord()); + rec.netherStamp = null; // 新一轮往返开始:清掉旧基准 + rec.mainStamp = p.getLocation().clone(); + plugin.getLogger().info("[地狱门接管] 玩家 " + p.getName() + " 从主世界门A出发,站位记录: " + + rec.mainStamp.toVector()); + return; + } + + // ===== ② 下界 → 主世界:记录门B + 接管判别 ===== + if (fEnv == World.Environment.NETHER && tEnv == World.Environment.NORMAL) { + PortalRecord rec = records.get(pid); + if (rec == null || rec.mainStamp == null) { + return; // 无记录:交还原版(不碰事件) + } + Location here = p.getLocation(); + if (rec.netherStamp == null) { + // 第1次出境:玩家此刻所在位置 = 「第1个下界门B」→ 记录基准后接管 + rec.netherStamp = here.clone(); + plugin.getLogger().info("[地狱门接管] 玩家 " + p.getName() + " 记为第1个下界门B,出场瞬间位移: " + + here.toVector()); + } else if (!near(here, rec.netherStamp)) { + // 后续出境:所在门与记录门B不一致 → 交还原版 + plugin.getLogger().info("[地狱门接管] 玩家 " + p.getName() + + " 从非记录门出境,交还原版逻辑(截图日志可查)"); + return; + } + + // ===== 接管:定位主世界门A前安全站位,覆盖事件 to,交给 vanilla 传送 ===== + World over = rec.mainStamp.getWorld(); + if (over == null || over.getEnvironment() != World.Environment.NORMAL) { + plugin.getLogger().info("[地狱门接管] 主世界门所在世界失效,交还原版逻辑"); + return; + } + Location stand = findStandAtOverworld(over, rec.mainStamp); + if (stand == null) { + plugin.getLogger().info("[地狱门接管] 主世界门A不可用且无法重建,交还原版逻辑"); + return; + } + e.setTo(stand); // 不 cancel:vanilla 用事件的 to 执行原版传送(同一个传送入口) + recentBack.put(pid, Boolean.TRUE); + records.remove(pid); // 本次往返完成,等下次出发时重置 + plugin.getLogger().info("[地狱门接管] 玩家 " + p.getName() + + " 从记录门B出境 → 接管:取消原版128搜索结果,指定主世界门A前站位交由原版传送: " + + stand.toVector()); + } + // 其余方向(主世界↔主世界等异常组合):不动 + } + + /** 玩家离线清理记录。 */ + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerQuit(PlayerQuitEvent e) { + records.remove(e.getPlayer().getUniqueId()); + recentBack.remove(e.getPlayer().getUniqueId()); + } + + // ============ 工具 ============ + + /** 同世界、水平距离 ≤ 5 格视为同一门附近。 */ + private static boolean near(Location a, Location b) { + if (a == null || b == null) return false; + World w1 = a.getWorld(), w2 = b.getWorld(); + if (w1 == null || w2 == null || !w1.equals(w2)) return false; + double dx = a.getX() - b.getX(); + double dz = a.getZ() - b.getZ(); + return dx * dx + dz * dz <= 25.0D; + } + + /** + * 定位主世界门A的安全回程站位: + * 1) 门A仍存活(附近 3 格有 portal 方块):从 base 向门体外侧探测安全站位(不在 portal 平面 → 防循环穿越) + * 2) 门板不在(被毁)→ 按原版结构在站位附近重建 obsidian 门框 + fire,返回门前站位 + */ + private Location findStandAtOverworld(World w, Location base) { + if (hasPortalNear(w, base, 3)) { + Location stand = probeStandOutside(w, base); + plugin.getLogger().info("[地狱门接管] 主世界门A仍存活,门前安全站位: " + stand.toVector()); + return stand; + } + return rebuildPortalNear(w, base); + } + + /** + * 从 base 向 4 方向(±X/±Z)探测 1..4 格,取第一个「不在 portal 平面内、非 lava、脚部可站立」的位置。 + * 这是玩家从下界回来时落点的防线——站门板平面外 1~2。 + */ + private Location probeStandOutside(World w, Location base) { + int bx = base.getBlockX(), by = base.getBlockY(), bz = base.getBlockZ(); + for (int d = 4; d >= 1; d--) { + int[][] dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; + for (int[] dir : dirs) { + int fx = bx + dir[0] * d; + int fz = bz + dir[1] * d; + Location cand = new Location(w, fx + 0.5D, by + 0.5D, fz + 0.5D); + if (canStandAt(w, fx, by, fz)) { + return cand; + } + } + } + // 探测失败的兜底:base 原位置 + 1 格(避开门板平面),靠 recentBack 缓冲兜底 + return new Location(w, bx + 0.5D, by + 1.5D, bz + 0.5D); + } + + /** 站位探测判定:脚部不在 portal 平面内、非 lava/fire,身体不穿过门体。 */ + private static boolean canStandAt(World w, int x, int y, int z) { + Block foot = w.getBlockAt(x, y, z); + Material fm = foot.getType(); + if (fm.isSolid() || fm == Material.LAVA || fm == Material.NETHER_PORTAL || fm == Material.FIRE) { + return false; + } + // 身体(0~3 格高)不能穿过门板平面 + for (int dy = 1; dy <= 3; dy++) { + Material t = w.getBlockAt(x, y + dy, z).getType(); + if (t == Material.NETHER_PORTAL || t == Material.LAVA || t == Material.FIRE) { + return false; + } + } + // 脚下要有承接(solid 或 AIR——AIR 允许落体到下方地面,不算不安全) + Block under = w.getBlockAt(x, y - 1, z); + Material um = under.getType(); + return um.isSolid() || um == Material.AIR || um == Material.LAVA; + } + + /** 主世界地点附近(radius 格)是否有 NETHER_PORTAL 方块。 */ + private static boolean hasPortalNear(World w, Location loc, int radius) { + int x = loc.getBlockX(), y = loc.getBlockY(), z = loc.getBlockZ(); + for (int dx = -radius; dx <= radius; dx++) { + for (int dy = -2; dy <= radius + 1; dy++) { + for (int dz = -radius; dz <= radius; dz++) { + if (w.getBlockAt(x + dx, y + dy, z + dz).getType() == Material.NETHER_PORTAL) { + return true; + } + } + } + } + return false; + } + + /** + * 在 loc 附近(半径 1..6)按原版结构重建地狱门(obsidian 门框 内部 3宽×4高)。 + * 返回玩家在门前的站位(距离触发区,防循环);条件不满足返回 null。 + */ + private Location rebuildPortalNear(World w, Location loc) { + int ex = loc.getBlockX(), ey = loc.getBlockY(), ez = loc.getBlockZ(); + for (int r = 1; r <= 6; r++) { + int[][] deltas = { + {0, 0}, {r, 0}, {-r, 0}, {0, r}, {0, -r}, + {r, r}, {r, -r}, {-r, r}, {-r, -r} + }; + for (int[] d : deltas) { + int cx = ex + d[0]; + int cz = ez + d[1]; + for (boolean widthIsX : new boolean[]{true, false}) { + Location stand = buildFrame(w, cx, cz, ey, widthIsX); + if (stand != null) { + plugin.getLogger().info("[地狱门接管] 主世界门A被毁,在(" + cx + ", " + cz + ")重建原版门框,站位: " + + stand.toVector()); + return stand; + } + } + } + } + return null; + } + + /** + * 在 (cx, cz) 上方搭原版 obsidian 門框(内部 3宽×4高,厚度 1 格)。 + * widthIsX=true:门沿 x 轴展开;false:沿 z 轴展开。 + * 返回玩家站立位置;条件不满足返回 null。 + */ + private Location buildFrame(World w, int cx, int cz, int ey, boolean widthIsX) { + // 找地板:从记录位置往下找第一个可站立实体方块 + int floorY = ey; + for (int dy = 0; dy <= 12; dy++) { + int fy = ey - dy; + if (fy < w.getMinHeight()) return null; + Block b = w.getBlockAt(cx, fy, cz); + Material m = b.getType(); + if (m != Material.AIR && m != Material.LAVA) { + floorY = fy + 1; + break; + } + } + // 门框总高 6 格(底行 + 内部4 + 顶行),高度校验 + if (floorY < w.getMinHeight() + 1 || floorY + 5 > w.getMaxHeight() - 1) { + return null; + } + + // 门洞检查:内部区不能有 lava + for (int i = -1; i <= 1; i++) { + for (int dy = 0; dy <= 4; dy++) { + Block b = widthIsX + ? w.getBlockAt(cx + i, floorY + dy, cz) + : w.getBlockAt(cx, floorY + dy, cz + i); + if (b.getType() == Material.LAVA) { + return null; + } + } + } + + // 摆门框 obsidian:底行 + 顶行,各宽轴 -2..+2;左右列在宽轴 ±1、y 1..4 + for (int i = -2; i <= 2; i++) { + placeW(w, widthIsX, cx, cz, i, floorY, Material.OBSIDIAN); + placeW(w, widthIsX, cx, cz, i, floorY + 5, Material.OBSIDIAN); + } + for (int i : new int[]{-1, 1}) { + for (int dy = 1; dy <= 4; dy++) { + placeW(w, widthIsX, cx, cz, i, floorY + dy, Material.OBSIDIAN); + } + } + + // 顶部 fire(原版生成门框时的顶部布置) + placeW(w, widthIsX, cx, cz, -1, floorY + 5, Material.FIRE); + placeW(w, widthIsX, cx, cz, 1, floorY + 5, Material.FIRE); + placeW(w, widthIsX, cx, cz, 0, floorY + 5, Material.FIRE); + placeW(w, widthIsX, cx, cz, -2, floorY + 5, Material.FIRE); + placeW(w, widthIsX, cx, cz, 2, floorY + 5, Material.FIRE); + + // 站立位置:门前第 2 格地面中央(不在 portal 平面内,防循环触发) + int standX = widthIsX ? cx : cx; + int standZ = widthIsX ? cz - 2 : cz; + if (!widthIsX) standX = cx - 2; + return new Location(w, standX + 0.5D, floorY + 0.5D, standZ + 0.5D); + } + + /** 放置到门户宽轴第 i 列(相对中心)、y 行;widthIsX 决定宽轴是 X 还是 Z。 */ + private static void placeW(World w, boolean widthIsX, int cx, int cz, int i, int y, Material m) { + if (widthIsX) { + setBlock(w, cx + i, y, cz, m); + } else { + setBlock(w, cx, y, cz + i, m); + } + } + + /** 写方块(静默,不做物理反馈)。 */ + private static void setBlock(World w, int x, int y, int z, Material m) { + Block b = w.getBlockAt(x, y, z); + if (b.getType() != m) { + b.setType(m, false); + } + } +} diff --git a/src/main/resources/openai/黑名单/languages.json b/src/main/resources/openai/黑名单/languages.json index 7079877..10217b4 100644 --- a/src/main/resources/openai/黑名单/languages.json +++ b/src/main/resources/openai/黑名单/languages.json @@ -41,4 +41,5 @@ "数据结构", "正则表达式", "正则" + ] diff --git a/src/main/resources/openai/黑名单/中文词组.json b/src/main/resources/openai/黑名单/中文词组.json index bb32369..17985e6 100644 --- a/src/main/resources/openai/黑名单/中文词组.json +++ b/src/main/resources/openai/黑名单/中文词组.json @@ -1,8 +1,14 @@ [ "提权", "命令方块", + "命令矿车", + "结构方块", "基岩", "屏障", - "命令矿车" - -] \ No newline at end of file + "调试棒", + "调试器", + "结构控制方块", + "数据方块", + "复制方块", + "命令方块矿车" +] diff --git a/src/main/resources/openai/黑名单/英文词组.json b/src/main/resources/openai/黑名单/英文词组.json index fad0a88..54eefe8 100644 --- a/src/main/resources/openai/黑名单/英文词组.json +++ b/src/main/resources/openai/黑名单/英文词组.json @@ -1,5 +1,13 @@ [ "command_block", + "command_minecart", + "structure_block", + "structureblock", + "bedrock", "barrier", - "debug_stick" -] \ No newline at end of file + "debug_stick", + "debugger", + "commandblock", + "data_block", + "copy_block" +]