From 24e5248cec643f3d638f314f6cf6dfe19c87388f Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Mon, 6 Jul 2026 18:10:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Emaxhome=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E4=BC=A0=E9=80=81=E7=82=B9=E4=B8=8A=E9=99=90=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E8=81=94=E5=8A=A8=E7=94=A8=E6=88=B7=E7=BB=84?= =?UTF-8?q?home=5Flimit(#726)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AreaProtection新增max_home_per_player全局配置,复用现有area_config/web_area_config通路 - updateAreaConfig同步刷新内存字段,Web后台修改后立即生效 - HomeManager.getGlobalHomeLimit改为读取area_config,解析失败或<=0回退默认5 - 用户组home_limit(>0覆盖/0跟随/-1无限)逻辑不变,形成完整联动 --- src/main/java/Sdf1_login/AreaProtection.java | 19 +++++++++++++++++++ src/main/java/Sdf1_login/HomeManager.java | 12 +++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/Sdf1_login/AreaProtection.java b/src/main/java/Sdf1_login/AreaProtection.java index ff26df1..c59386c 100644 --- a/src/main/java/Sdf1_login/AreaProtection.java +++ b/src/main/java/Sdf1_login/AreaProtection.java @@ -110,6 +110,7 @@ public class AreaProtection implements Listener { // ★ 全局配置默认值 private int globalCreatePricePerSqm = 10; // 每㎡创建价格 private int globalMaxLandsPerPlayer = 5; // 每人最多领地数 + private int globalMaxHomePerPlayer = 5; // 每人最多传送点(home)数量 private int globalDefaultHeight = 255; // 默认高度 // 选地 @@ -1211,6 +1212,7 @@ public class AreaProtection implements Listener { if (configCount == 0) { stmt.executeUpdate("INSERT OR IGNORE INTO area_config VALUES ('create_price_per_sqm', '10')"); stmt.executeUpdate("INSERT OR IGNORE INTO area_config VALUES ('max_lands_per_player', '5')"); + stmt.executeUpdate("INSERT OR IGNORE INTO area_config VALUES ('max_home_per_player', '5')"); stmt.executeUpdate("INSERT OR IGNORE INTO area_config VALUES ('default_height', '255')"); stmt.executeUpdate("INSERT OR IGNORE INTO area_config VALUES ('peace_mode_max_duration', '3600')"); } @@ -1223,6 +1225,7 @@ public class AreaProtection implements Listener { switch (k) { case "create_price_per_sqm": globalCreatePricePerSqm = Integer.parseInt(v); break; case "max_lands_per_player": globalMaxLandsPerPlayer = Integer.parseInt(v); break; + case "max_home_per_player": globalMaxHomePerPlayer = Integer.parseInt(v); break; case "default_height": globalDefaultHeight = Integer.parseInt(v); break; } } catch (NumberFormatException ignored) {} @@ -8200,11 +8203,27 @@ public class AreaProtection implements Listener { ps.setString(3, value); ps.executeUpdate(); ps.close(); + // ★ 同步更新内存字段,使Web配置变更立即生效(无需等待下次轮询reload) + try { + switch (key) { + case "create_price_per_sqm": globalCreatePricePerSqm = Integer.parseInt(value); break; + case "max_lands_per_player": globalMaxLandsPerPlayer = Integer.parseInt(value); break; + case "max_home_per_player": globalMaxHomePerPlayer = Integer.parseInt(value); break; + case "default_height": globalDefaultHeight = Integer.parseInt(value); break; + } + } catch (NumberFormatException ignored) {} } catch (Exception e) { plugin.getLogger().warning("[防护] 更新配置失败: " + e.getMessage()); } } + /** + * ★ 获取全局家(home)数量上限 + */ + public int getGlobalMaxHomePerPlayer() { + return globalMaxHomePerPlayer; + } + /** * ★ 获取area_config表中的配置值 */ diff --git a/src/main/java/Sdf1_login/HomeManager.java b/src/main/java/Sdf1_login/HomeManager.java index fe0a3a2..3d28a4a 100644 --- a/src/main/java/Sdf1_login/HomeManager.java +++ b/src/main/java/Sdf1_login/HomeManager.java @@ -285,9 +285,19 @@ public class HomeManager implements Listener { /** * 获取全局家数量限制 + * 读取area_config中的max_home_per_player配置(管理员可在Web后台调整) + * 解析失败或值<=0时回退到默认5 */ private int getGlobalHomeLimit() { - // 默认5个家,可从配置文件读取 + try { + if (plugin.areaProtection != null) { + int limit = plugin.areaProtection.getGlobalMaxHomePerPlayer(); + if (limit > 0) { + return limit; + } + } + } catch (Exception ignored) {} + // 默认5个家 return 5; }