From cd2d94c9d06dacb0d2b44a4f0c9338c4fbbdb588 Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Tue, 23 Jun 2026 01:10:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dprotect=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=97=AE=E9=A2=98=E3=80=81=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E9=93=BE=E6=8E=A5=E3=80=81=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=94=A8=E6=88=B7UI=E5=81=8F=E5=A5=BD=E5=88=97(ui=5Fmode)?= =?UTF-8?q?=E3=80=81txt=E8=BF=81=E7=A7=BB=E9=A2=86=E5=9C=B0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=86=E9=85=8D=E7=BB=99=E7=AE=A1=E7=90=86=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Sdf1_login/AreaGUIManager.java | 2 +- src/main/java/Sdf1_login/AreaProtection.java | 42 ++++++++++++++++-- src/main/java/Sdf1_login/DatabaseManager.java | 44 +++++++++++++++++++ 3 files changed, 84 insertions(+), 4 deletions(-) diff --git a/src/main/java/Sdf1_login/AreaGUIManager.java b/src/main/java/Sdf1_login/AreaGUIManager.java index 78ca1d7..32f2d9d 100644 --- a/src/main/java/Sdf1_login/AreaGUIManager.java +++ b/src/main/java/Sdf1_login/AreaGUIManager.java @@ -420,7 +420,7 @@ public class AreaGUIManager implements Listener { p.sendMessage("§7权限模板功能开发中..."); } else if (raw == 40) { p.closeInventory(); - p.sendMessage("§a文档链接: https://docs.sdf1.com/area-protection"); + p.sendMessage("§a文档链接: https://wiki.ypshidifu.cn"); } else if (raw == 49) { plugin.getGui().openMain(p); } diff --git a/src/main/java/Sdf1_login/AreaProtection.java b/src/main/java/Sdf1_login/AreaProtection.java index e939826..37e4ff5 100644 --- a/src/main/java/Sdf1_login/AreaProtection.java +++ b/src/main/java/Sdf1_login/AreaProtection.java @@ -1151,6 +1151,9 @@ public class AreaProtection implements Listener { // 创建迁移完成标记文件,防止重复迁移 File marker = new File(rootDir, ".db_migrated"); marker.createNewFile(); + // 创建owner待分配标记文件 + File ownerMarker = new File(rootDir, ".need_owner_assign"); + ownerMarker.createNewFile(); } } catch (Exception e) { plugin.getLogger().warning("[防护] 迁移过程异常: " + e.getMessage()); @@ -2105,6 +2108,33 @@ public class AreaProtection implements Listener { return true; } + /** + * 自动将无owner的txt迁移领地分配给第一个操作的管理员 + */ + private void assignUnownedLandsToAdmin(Player admin) { + File ownerMarker = new File(rootDir, ".need_owner_assign"); + if (!ownerMarker.exists()) return; + + String adminName = admin.getName(); + int assigned = 0; + + for (AreaConfig ac : areas.values()) { + if (ac.owner == null || ac.owner.isEmpty()) { + ac.owner = adminName; + saveAreaToDb(ac); + assigned++; + } + } + + // 删除标记文件 + ownerMarker.delete(); + + if (assigned > 0) { + admin.sendMessage("§a§l[防护] 已将 " + assigned + " 个无主领地分配给你"); + plugin.getLogger().info("[防护] txt迁移领地已分配给管理员: " + adminName + " 共" + assigned + "个"); + } + } + private boolean isItemBlacklisted(String itemId, AreaConfig ac) { if (globalItemBlacklist.contains( @@ -3951,11 +3981,12 @@ public class AreaProtection implements Listener { "add", "remove", "additem", "removeitem", "addname", "removename", "listname", "addwhite", "removewhite", "listwhite", - "list", "listitem", "创建", "删除", "重载", - "工具", "expand", "contraction", + "list", "listitem", "创建", "create", "删除", "delete", "重载", "reload", + "工具", "wand", "expand", "contraction", "on", "off", "tempon", "modeexempt", "info", "setowner", "addvisitor", "removevisitor", - "listvisitors", "transfer", "shop" + "listvisitors", "transfer", "shop", + "menu", "菜单", "sdf1debug", "testclear" )); String first = original[0].toLowerCase(); @@ -3996,6 +4027,11 @@ public class AreaProtection implements Listener { return true; } String sub = args[0].toLowerCase(); + + // ★ 管理员操作时,自动分配无owner的领地 + if (sender instanceof Player && isAreaAdmin(sender)) { + assignUnownedLandsToAdmin((Player) sender); + } // ===== 诊断命令 ===== if (sub.equals("sdf1debug")) { if (!(sender instanceof Player)) { diff --git a/src/main/java/Sdf1_login/DatabaseManager.java b/src/main/java/Sdf1_login/DatabaseManager.java index 6b73348..e3d774d 100644 --- a/src/main/java/Sdf1_login/DatabaseManager.java +++ b/src/main/java/Sdf1_login/DatabaseManager.java @@ -88,6 +88,9 @@ public class DatabaseManager { "TEXT DEFAULT ''"); safeAdd(st, "last_login_ip", "TEXT DEFAULT ''"); + // UI偏好:1=CLI(默认), 0=GUI + safeAdd(st, "ui_mode", + "INTEGER DEFAULT 1"); // ===== 背包备份表:安全迁移 ===== // 检查旧表是否存在(用 inventory_data 列判断) @@ -281,6 +284,47 @@ public class DatabaseManager { } catch (Exception ignored) { } } + + // ==================== UI偏好 ==================== + + /** + * 获取玩家UI偏好 + * @return 1=CLI(默认), 0=GUI + */ + public int getUiMode(String playerName) { + try { + PreparedStatement ps = db.prepareStatement( + "SELECT ui_mode FROM users WHERE player_name=?"); + ps.setString(1, playerName); + ResultSet rs = ps.executeQuery(); + int mode = 1; // 默认CLI + if (rs.next()) { + mode = rs.getInt("ui_mode"); + } + rs.close(); + ps.close(); + return mode; + } catch (SQLException e) { + return 1; // 默认CLI + } + } + + /** + * 设置玩家UI偏好 + * @param mode 1=CLI, 0=GUI + */ + public void setUiMode(String playerName, int mode) { + try { + PreparedStatement ps = db.prepareStatement( + "UPDATE users SET ui_mode=? WHERE player_name=?"); + ps.setInt(1, mode); + ps.setString(2, playerName); + ps.executeUpdate(); + ps.close(); + } catch (SQLException e) { + // 静默 + } + } // ==================== 菜单图标 ==================== public void saveMenuIcon(String name,