From d348ee76f91c912acd2afbd2b1621f918607d37d Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Wed, 24 Jul 2024 16:25:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=87=BA=E7=94=9F=E7=82=B9?= =?UTF-8?q?=E5=8D=8A=E5=BE=84=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../lunadeer/dominion/commands/SetConfig.java | 15 +++++++ .../controllers/DominionController.java | 40 +++++++++++++++++++ .../dominion/managers/ConfigManager.java | 13 ++++++ .../cn/lunadeer/dominion/tuis/SysConfig.java | 11 +++++ src/main/resources/config.yml | 1 + 6 files changed, 81 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4202f15e..8a0777c5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.lunadeer Dominion - 1.40.0-beta + 1.41.0-beta jar Dominion diff --git a/src/main/java/cn/lunadeer/dominion/commands/SetConfig.java b/src/main/java/cn/lunadeer/dominion/commands/SetConfig.java index 08d26196..127736d2 100644 --- a/src/main/java/cn/lunadeer/dominion/commands/SetConfig.java +++ b/src/main/java/cn/lunadeer/dominion/commands/SetConfig.java @@ -70,6 +70,9 @@ public static void handler(CommandSender sender, String[] args) { case "residence_migration": setResidenceMigration(sender, args); break; + case "spawn_protection": + setSpawnProtection(sender, args); + break; default: Notification.error(sender, "未知参数"); } @@ -252,6 +255,7 @@ private static void setEconomyRefund(CommandSender sender, String[] args) { } else { Dominion.config.setEconomyRefund(economyRefund); } + refreshPageOrNot(sender, args); } private static void setResidenceMigration(CommandSender sender, String[] args) { @@ -259,4 +263,15 @@ private static void setResidenceMigration(CommandSender sender, String[] args) { Dominion.config.setResidenceMigration(residenceMigration); refreshPageOrNot(sender, args); } + + private static void setSpawnProtection(CommandSender sender, String[] args) { + int spawnProtection = Integer.parseInt(args[2]); + if (spawnProtection != -1 && spawnProtection <= 0) { + Dominion.config.setSpawnProtection(1); + Notification.error(sender, "出生点保护半径不能小于或等于0"); + } else { + Dominion.config.setSpawnProtection(spawnProtection); + } + refreshPageOrNot(sender, args); + } } diff --git a/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java b/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java index e21fc84a..4de60331 100644 --- a/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java +++ b/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java @@ -155,6 +155,11 @@ public static void create(AbstractOperator operator, String name, } // 获取此领地的所有同级领地 List sub_dominions = DominionDTO.selectByParentId(dominion.getWorld(), parent_dominion.getId()); + // 检查是否与出生点保护冲突 + if (isIntersectSpawn(dominion)) { + operator.setResponse(FAIL.addMessage("与出生点保护冲突")); + return; + } // 检查是否与其他子领地冲突 for (DominionDTO sub_dominion : sub_dominions) { if (isIntersect(sub_dominion, dominion)) { @@ -178,6 +183,30 @@ public static void create(AbstractOperator operator, String name, operator.setResponse(SUCCESS); } + private static boolean isIntersectSpawn(DominionDTO dominion) { + int radius = Dominion.config.getSpawnProtection(); + if (radius == -1) { + return false; + } + World world = Dominion.instance.getServer().getWorld(dominion.getWorld()); + if (world == null) { + return false; + } + Location spawn = world.getSpawnLocation(); + return isIntersect(dominion, spawn.getBlockX() - radius, spawn.getBlockY() - radius, spawn.getBlockZ() - radius + , spawn.getBlockX() + radius, spawn.getBlockY() + radius, spawn.getBlockZ() + radius); + } + + private static boolean isIntersectSpawn(String world, int[] cords) { + int radius = Dominion.config.getSpawnProtection(); + if (radius == -1) { + return false; + } + Location spawn = Objects.requireNonNull(Dominion.instance.getServer().getWorld(world)).getSpawnLocation(); + return isIntersect(cords, spawn.getBlockX() - radius, spawn.getBlockY() - radius, spawn.getBlockZ() - radius + , spawn.getBlockX() + radius, spawn.getBlockY() + radius, spawn.getBlockZ() + radius); + } + /** * 向一个方向扩展领地 * 会尝试对操作者当前所在的领地进行操作,当操作者不在一个领地内或者在子领地内时 @@ -212,6 +241,11 @@ public static void expand(AbstractOperator operator, Integer size, String domini if (newCords == null) { return; } + // 检查是否与出生点保护冲突 + if (isIntersectSpawn(dominion.getWorld(), newCords)) { + operator.setResponse(FAIL.addMessage("与出生点保护冲突")); + return; + } // 校验是否超出父领地范围 DominionDTO parent_dominion = DominionDTO.select(dominion.getParentDomId()); if (parent_dominion == null) { @@ -595,6 +629,12 @@ private static boolean isIntersect(DominionDTO a, int[] cord) { return isIntersect(a, cord[0], cord[1], cord[2], cord[3], cord[4], cord[5]); } + private static boolean isIntersect(int[] cord, Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2) { + return cord[0] < x2 && cord[3] > x1 && + cord[1] < y2 && cord[4] > y1 && + cord[2] < z2 && cord[5] > z1; + } + /** * 判断 sub 是否完全被 parent 包裹 */ diff --git a/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java b/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java index f2e34d2c..1a312da1 100644 --- a/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java +++ b/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java @@ -33,6 +33,7 @@ public void reload() { XLogger.err("AutoCreateRadius 不能等于 0,已重置为 10"); setAutoCreateRadius(10); } + _spawn_protection = _file.getInt("Limit.SpawnProtection", 10); _limit_size_x = _file.getInt("Limit.SizeX", 128); if (_limit_size_x <= 4 && _limit_size_x != -1) { XLogger.err("Limit.SizeX 尺寸不能小于 4,已重置为 128"); @@ -95,6 +96,7 @@ public void reload() { public void saveAll() { _file.set("AutoCreateRadius", _auto_create_radius); + _file.set("Limit.SpawnProtection", _spawn_protection); _file.set("Limit.SizeX", _limit_size_x); _file.set("Limit.SizeY", _limit_size_y); _file.set("Limit.SizeZ", _limit_size_z); @@ -404,6 +406,16 @@ public void setResidenceMigration(Boolean residence_migration) { _plugin.saveConfig(); } + public Integer getSpawnProtection() { + return _spawn_protection; + } + + public void setSpawnProtection(Integer spawn_protection) { + _spawn_protection = spawn_protection; + _file.set("Limit.SpawnProtection", spawn_protection); + _plugin.saveConfig(); + } + private final Dominion _plugin; private FileConfiguration _file; private Boolean _debug; @@ -444,4 +456,5 @@ public void setResidenceMigration(Boolean residence_migration) { private Float _economy_refund; private List _fly_permission_nodes; private Boolean _residence_migration; + private Integer _spawn_protection; } diff --git a/src/main/java/cn/lunadeer/dominion/tuis/SysConfig.java b/src/main/java/cn/lunadeer/dominion/tuis/SysConfig.java index 0059fc89..c1ef96b2 100644 --- a/src/main/java/cn/lunadeer/dominion/tuis/SysConfig.java +++ b/src/main/java/cn/lunadeer/dominion/tuis/SysConfig.java @@ -28,6 +28,17 @@ public static void show(CommandSender sender, String[] args) { Line limitSize = Line.create() .append(Component.text("领地尺寸限制")); view.add(limitSize); + + Line spawnProtect = Line.create() + .append(Component.text(" 出生点保护范围")); + if (Dominion.config.getLimitSizeX() == -1) { + spawnProtect.append(Component.text("无限制")).append(Button.create("设置数值").setExecuteCommand("/dominion set_config spawn_protection 10 " + page).build()); + } else { + spawnProtect.append(NumChanger.create(Dominion.config.getLimitSizeX(), "/dominion set_config spawn_protection").setPageNumber(page).build()); + spawnProtect.append(Button.create("设置无限制").setExecuteCommand("/dominion set_config spawn_protection -1 " + page).build()); + } + view.add(spawnProtect); + Line limitSizeX = Line.create() .append(Component.text(" X轴(东西)")); if (Dominion.config.getLimitSizeX() == -1) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index aa6d2581..4fe3f3f5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -10,6 +10,7 @@ Database: AutoCreateRadius: 10 #-1 表示不开启 Limit: + SpawnProtection: 10 # 出生点保护半径 MinY: -64 # 最小Y坐标 MaxY: 320 # 最大Y坐标 SizeX: 128 # X方向最大长度 -1:表示不限制