From eeb0f1adc77f1132026910335d4dd1d4bebc1b64 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Sat, 24 Aug 2024 20:53:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BA=86=E9=87=87=E7=94=A8wo?= =?UTF-8?q?rld=20uid=E5=AD=98=E5=82=A8=E4=B8=96=E7=95=8C=E8=80=8C=E4=B8=8D?= =?UTF-8?q?=E6=98=AFname=EF=BC=88=E5=A6=82=E6=9E=9C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=AD=A4=E7=89=88=E6=9C=AC=E5=87=BA=E7=8E=B0=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E8=AF=B7=E4=B8=8D=E8=A6=81=E5=9B=9E=E9=80=80=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=81=E8=AF=B7=E7=AB=8B=E5=8D=B3=E5=92=8C=E4=BD=9C=E8=80=85?= =?UTF-8?q?=E5=8F=96=E5=BE=97=E8=81=94=E7=B3=BB=EF=BC=81=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../main/java/cn/lunadeer/dominion/Cache.java | 83 ++++++++++--------- .../cn/lunadeer/dominion/DominionNode.java | 10 +-- .../dominion/commands/DominionOperate.java | 8 +- .../lunadeer/dominion/commands/Operator.java | 11 ++- .../controllers/DominionController.java | 32 +++---- .../lunadeer/dominion/dtos/DominionDTO.java | 16 ++-- .../dominion/managers/DatabaseTables.java | 17 ++++ .../dominion/utils/BlueMapConnect.java | 9 +- .../dominion/utils/DynmapConnect.java | 5 +- .../events_v1_20_1/SelectPointEvents.java | 2 +- .../events_v1_21/SelectPointEvents.java | 2 +- 12 files changed, 115 insertions(+), 82 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7481e78..3cda1da 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "cn.lunadeer" -version = "2.2.4-beta" +version = "2.3.0-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) diff --git a/core/src/main/java/cn/lunadeer/dominion/Cache.java b/core/src/main/java/cn/lunadeer/dominion/Cache.java index 0074585..655f1c8 100644 --- a/core/src/main/java/cn/lunadeer/dominion/Cache.java +++ b/core/src/main/java/cn/lunadeer/dominion/Cache.java @@ -10,6 +10,7 @@ import cn.lunadeer.minecraftpluginutils.Scheduler; import cn.lunadeer.minecraftpluginutils.XLogger; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -463,10 +464,10 @@ public class Cache { B | A */ - private ConcurrentHashMap> world_dominion_tree_sector_a; // x >= 0, z >= 0 - private ConcurrentHashMap> world_dominion_tree_sector_b; // x <= 0, z >= 0 - private ConcurrentHashMap> world_dominion_tree_sector_c; // x >= 0, z <= 0 - private ConcurrentHashMap> world_dominion_tree_sector_d; // x <= 0, z <= 0 + private ConcurrentHashMap> world_dominion_tree_sector_a; // x >= 0, z >= 0 + private ConcurrentHashMap> world_dominion_tree_sector_b; // x <= 0, z >= 0 + private ConcurrentHashMap> world_dominion_tree_sector_c; // x >= 0, z <= 0 + private ConcurrentHashMap> world_dominion_tree_sector_d; // x <= 0, z <= 0 public DominionDTO getLocInDominionDTO(@NotNull Location loc) { try (AutoTimer ignored = new AutoTimer(Dominion.config.TimerEnabled())) { @@ -479,11 +480,15 @@ public class Cache { } - public List getNodes(Location loc) { - return getNodes(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ()); + public List getNodes(@NotNull Location loc) { + return getNodes(loc.getWorld().getUID(), loc.getBlockX(), loc.getBlockZ()); } - public List getNodes(String world, int x, int z) { + public List getNodes(World world, int x, int z) { + return getNodes(world.getUID(), x, z); + } + + public List getNodes(UUID world, int x, int z) { if (x >= 0 && z >= 0) { return world_dominion_tree_sector_a.get(world); } @@ -507,64 +512,64 @@ public class Cache { world_dominion_tree_sector_c = new ConcurrentHashMap<>(); world_dominion_tree_sector_d = new ConcurrentHashMap<>(); - Map> world_dominions_sector_a = new HashMap<>(); - Map> world_dominions_sector_b = new HashMap<>(); - Map> world_dominions_sector_c = new HashMap<>(); - Map> world_dominions_sector_d = new HashMap<>(); + Map> world_dominions_sector_a = new HashMap<>(); + Map> world_dominions_sector_b = new HashMap<>(); + Map> world_dominions_sector_c = new HashMap<>(); + Map> world_dominions_sector_d = new HashMap<>(); for (DominionDTO d : dominions) { // 对每个世界的领地进行四个象限的划分 - if (!world_dominions_sector_a.containsKey(d.getWorld()) || - !world_dominions_sector_b.containsKey(d.getWorld()) || - !world_dominions_sector_c.containsKey(d.getWorld()) || - !world_dominions_sector_d.containsKey(d.getWorld())) { - world_dominions_sector_a.put(d.getWorld(), new ArrayList<>()); - world_dominions_sector_b.put(d.getWorld(), new ArrayList<>()); - world_dominions_sector_c.put(d.getWorld(), new ArrayList<>()); - world_dominions_sector_d.put(d.getWorld(), new ArrayList<>()); + if (!world_dominions_sector_a.containsKey(d.getWorldUid()) || + !world_dominions_sector_b.containsKey(d.getWorldUid()) || + !world_dominions_sector_c.containsKey(d.getWorldUid()) || + !world_dominions_sector_d.containsKey(d.getWorldUid())) { + world_dominions_sector_a.put(d.getWorldUid(), new ArrayList<>()); + world_dominions_sector_b.put(d.getWorldUid(), new ArrayList<>()); + world_dominions_sector_c.put(d.getWorldUid(), new ArrayList<>()); + world_dominions_sector_d.put(d.getWorldUid(), new ArrayList<>()); } if (d.getX1() >= 0 && d.getZ1() >= 0) { - world_dominions_sector_a.get(d.getWorld()).add(d); + world_dominions_sector_a.get(d.getWorldUid()).add(d); } else if (d.getX1() <= 0 && d.getZ1() >= 0) { if (d.getX2() >= 0) { - world_dominions_sector_a.get(d.getWorld()).add(d); - world_dominions_sector_b.get(d.getWorld()).add(d); + world_dominions_sector_a.get(d.getWorldUid()).add(d); + world_dominions_sector_b.get(d.getWorldUid()).add(d); } else { - world_dominions_sector_b.get(d.getWorld()).add(d); + world_dominions_sector_b.get(d.getWorldUid()).add(d); } } else if (d.getX1() >= 0 && d.getZ1() <= 0) { if (d.getZ2() >= 0) { - world_dominions_sector_a.get(d.getWorld()).add(d); - world_dominions_sector_c.get(d.getWorld()).add(d); + world_dominions_sector_a.get(d.getWorldUid()).add(d); + world_dominions_sector_c.get(d.getWorldUid()).add(d); } else { - world_dominions_sector_c.get(d.getWorld()).add(d); + world_dominions_sector_c.get(d.getWorldUid()).add(d); } } else { if (d.getX2() >= 0 && d.getZ2() >= 0) { - world_dominions_sector_a.get(d.getWorld()).add(d); - world_dominions_sector_b.get(d.getWorld()).add(d); - world_dominions_sector_c.get(d.getWorld()).add(d); - world_dominions_sector_d.get(d.getWorld()).add(d); + world_dominions_sector_a.get(d.getWorldUid()).add(d); + world_dominions_sector_b.get(d.getWorldUid()).add(d); + world_dominions_sector_c.get(d.getWorldUid()).add(d); + world_dominions_sector_d.get(d.getWorldUid()).add(d); } else if (d.getX2() >= 0 && d.getZ2() <= 0) { - world_dominions_sector_c.get(d.getWorld()).add(d); - world_dominions_sector_d.get(d.getWorld()).add(d); + world_dominions_sector_c.get(d.getWorldUid()).add(d); + world_dominions_sector_d.get(d.getWorldUid()).add(d); } else if (d.getZ2() >= 0 && d.getX2() <= 0) { - world_dominions_sector_b.get(d.getWorld()).add(d); - world_dominions_sector_d.get(d.getWorld()).add(d); + world_dominions_sector_b.get(d.getWorldUid()).add(d); + world_dominions_sector_d.get(d.getWorldUid()).add(d); } else { - world_dominions_sector_d.get(d.getWorld()).add(d); + world_dominions_sector_d.get(d.getWorldUid()).add(d); } } } - for (Map.Entry> entry : world_dominions_sector_a.entrySet()) { + for (Map.Entry> entry : world_dominions_sector_a.entrySet()) { world_dominion_tree_sector_a.put(entry.getKey(), DominionNode.BuildNodeTree(-1, entry.getValue())); } - for (Map.Entry> entry : world_dominions_sector_b.entrySet()) { + for (Map.Entry> entry : world_dominions_sector_b.entrySet()) { world_dominion_tree_sector_b.put(entry.getKey(), DominionNode.BuildNodeTree(-1, entry.getValue())); } - for (Map.Entry> entry : world_dominions_sector_c.entrySet()) { + for (Map.Entry> entry : world_dominions_sector_c.entrySet()) { world_dominion_tree_sector_c.put(entry.getKey(), DominionNode.BuildNodeTree(-1, entry.getValue())); } - for (Map.Entry> entry : world_dominions_sector_d.entrySet()) { + for (Map.Entry> entry : world_dominions_sector_d.entrySet()) { world_dominion_tree_sector_d.put(entry.getKey(), DominionNode.BuildNodeTree(-1, entry.getValue())); } } diff --git a/core/src/main/java/cn/lunadeer/dominion/DominionNode.java b/core/src/main/java/cn/lunadeer/dominion/DominionNode.java index 987a519..0cde4bf 100644 --- a/core/src/main/java/cn/lunadeer/dominion/DominionNode.java +++ b/core/src/main/java/cn/lunadeer/dominion/DominionNode.java @@ -55,20 +55,16 @@ public class DominionNode { return node; } else { DominionNode childDominion = getLocInDominionNode(node.children, loc); - if (childDominion == null) { - return node; - } else { - return childDominion; - } + return Objects.requireNonNullElse(childDominion, node); } } } return null; } - public static boolean isInDominion(@Nullable DominionDTO dominion, Location location) { + public static boolean isInDominion(@Nullable DominionDTO dominion, @NotNull Location location) { if (dominion == null) return false; - if (!Objects.equals(dominion.getWorld(), location.getWorld().getName())) return false; + if (!Objects.equals(dominion.getWorldUid(), location.getWorld().getUID())) return false; double x = location.getX(); double y = location.getY(); double z = location.getZ(); diff --git a/core/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java b/core/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java index cc4b042..9cd39b1 100644 --- a/core/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java +++ b/core/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java @@ -391,9 +391,9 @@ public class DominionOperate { if (location == null) { int x = (dominionDTO.getX1() + dominionDTO.getX2()) / 2; int z = (dominionDTO.getZ1() + dominionDTO.getZ2()) / 2; - World world = Dominion.instance.getServer().getWorld(dominionDTO.getWorld()); + World world = dominionDTO.getWorld(); if (world == null) { - Notification.error(sender, "领地所在世界 %s 不存在", dominionDTO.getWorld()); + Notification.error(sender, "领地所在世界不存在"); return; } location = new Location(world, x, player.getLocation().getY(), z); @@ -463,9 +463,9 @@ public class DominionOperate { Location location = dominionDTO.getTpLocation(); int center_x = (dominionDTO.getX1() + dominionDTO.getX2()) / 2; int center_z = (dominionDTO.getZ1() + dominionDTO.getZ2()) / 2; - World world = Dominion.instance.getServer().getWorld(dominionDTO.getWorld()); + World world = dominionDTO.getWorld(); if (world == null) { - Notification.error(player, "领地所在世界 %s 不存在", dominionDTO.getWorld()); + Notification.error(player, "领地所在世界不存在"); return; } if (location == null) { diff --git a/core/src/main/java/cn/lunadeer/dominion/commands/Operator.java b/core/src/main/java/cn/lunadeer/dominion/commands/Operator.java index a9fba2c..961a877 100644 --- a/core/src/main/java/cn/lunadeer/dominion/commands/Operator.java +++ b/core/src/main/java/cn/lunadeer/dominion/commands/Operator.java @@ -52,8 +52,11 @@ public class Operator { Map> mca_cords = new HashMap<>(); List doms = Cache.instance.getDominions(); for (DominionDTO dom : doms) { - if (!mca_cords.containsKey(dom.getWorld())) { - mca_cords.put(dom.getWorld(), new ArrayList<>()); + if (dom.getWorld() == null) { + continue; + } + if (!mca_cords.containsKey(dom.getWorld().getName())) { + mca_cords.put(dom.getWorld().getName(), new ArrayList<>()); } Integer world_x1 = dom.getX1(); Integer world_x2 = dom.getX2(); @@ -66,10 +69,10 @@ public class Operator { for (int x = mca_x1; x <= mca_x2; x++) { for (int z = mca_z1; z <= mca_z2; z++) { String file_name = "r." + x + "." + z + ".mca"; - if (mca_cords.get(dom.getWorld()).contains(file_name)) { + if (mca_cords.get(dom.getWorld().getName()).contains(file_name)) { continue; } - mca_cords.get(dom.getWorld()).add(file_name); + mca_cords.get(dom.getWorld().getName()).add(file_name); } } } diff --git a/core/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java b/core/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java index 39dd99d..d8744df 100644 --- a/core/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java +++ b/core/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java @@ -92,7 +92,7 @@ public class DominionController { operator.setResponse(FAIL.addMessage("已经存在名称为 %s 的领地", name)); return; } - if (!loc1.getWorld().equals(loc2.getWorld())) { + if (!loc1.getWorld().getUID().equals(loc2.getWorld().getUID())) { operator.setResponse(FAIL.addMessage("选点世界不一致")); return; } @@ -137,10 +137,10 @@ public class DominionController { } } // 创建 dominion (此步骤不会写入数据) - DominionDTO dominion = DominionDTO.create(parent_dominion.getId() == -1 ? operator.getUniqueId() : parent_dominion.getOwner(), name, loc1.getWorld().getName(), + DominionDTO dominion = DominionDTO.create(parent_dominion.getId() == -1 ? operator.getUniqueId() : parent_dominion.getOwner(), name, loc1.getWorld(), minX, minY, minZ, maxX, maxY, maxZ, parent_dominion); // 如果parent_dominion不为-1 检查是否在同一世界 - if (parent_dominion.getId() != -1 && !parent_dominion.getWorld().equals(dominion.getWorld())) { + if (parent_dominion.getId() != -1 && !parent_dominion.getWorldUid().equals(dominion.getWorldUid())) { operator.setResponse(FAIL.addMessage("父领地与子领地不在同一世界。")); return; } @@ -154,7 +154,7 @@ public class DominionController { return; } // 获取此领地的所有同级领地 - List sub_dominions = DominionDTO.selectByParentId(dominion.getWorld(), parent_dominion.getId()); + List sub_dominions = DominionDTO.selectByParentId(dominion.getWorldUid(), parent_dominion.getId()); // 检查是否与出生点保护冲突 if (isIntersectSpawn(operator, dominion)) { operator.setResponse(FAIL.addMessage("与出生点保护冲突")); @@ -191,7 +191,7 @@ public class DominionController { if (radius == -1) { return false; } - World world = Dominion.instance.getServer().getWorld(dominion.getWorld()); + World world = dominion.getWorld(); if (world == null) { return false; } @@ -200,7 +200,7 @@ public class DominionController { , spawn.getBlockX() + radius, spawn.getBlockY() + radius, spawn.getBlockZ() + radius); } - private static boolean isIntersectSpawn(AbstractOperator operator, String world, int[] cords) { + private static boolean isIntersectSpawn(AbstractOperator operator, @NotNull World world, int[] cords) { if (operator.isOp() && Dominion.config.getLimitOpBypass()) { return false; } @@ -208,7 +208,7 @@ public class DominionController { if (radius == -1) { return false; } - Location spawn = Objects.requireNonNull(Dominion.instance.getServer().getWorld(world)).getSpawnLocation(); + Location spawn = world.getSpawnLocation(); return isIntersect(cords, spawn.getBlockX() - radius, spawn.getBlockY() - radius, spawn.getBlockZ() - radius , spawn.getBlockX() + radius, spawn.getBlockY() + radius, spawn.getBlockZ() + radius); } @@ -263,7 +263,7 @@ public class DominionController { return; } // 获取同世界下的所有同级领地 - List exist_dominions = DominionDTO.selectByParentId(dominion.getWorld(), dominion.getParentDomId()); + List exist_dominions = DominionDTO.selectByParentId(dominion.getWorldUid(), dominion.getParentDomId()); for (DominionDTO exist_dominion : exist_dominions) { if (isIntersect(exist_dominion, newCords)) { // 如果是自己,跳过 @@ -317,7 +317,7 @@ public class DominionController { return; } // 获取所有的子领地 - List sub_dominions = DominionDTO.selectByParentId(dominion.getWorld(), dominion.getId()); + List sub_dominions = DominionDTO.selectByParentId(dominion.getWorldUid(), dominion.getId()); for (DominionDTO sub_dominion : sub_dominions) { if (!isContained(sub_dominion, newCords)) { operator.setResponse(FAIL.addMessage("缩小后的领地无法包含子领地 %s", sub_dominion.getName())); @@ -478,9 +478,9 @@ public class DominionController { operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "领地 %s 不存在", dominion_name)); return; } - World world = Dominion.instance.getServer().getWorld(dominion.getWorld()); + World world = dominion.getWorld(); if (world == null) { - operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "世界 %s 不存在", dominion.getWorld())); + operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "领地所在世界不存在")); return; } Location loc = new Location(world, x, y, z); @@ -679,7 +679,7 @@ public class DominionController { } private static List getSubDominionsRecursive(DominionDTO dominion) { - List sub_dominions = DominionDTO.selectByParentId(dominion.getWorld(), dominion.getId()); + List sub_dominions = DominionDTO.selectByParentId(dominion.getWorldUid(), dominion.getId()); List sub_sub_dominions = new ArrayList<>(); for (DominionDTO sub_dominion : sub_dominions) { sub_sub_dominions.addAll(getSubDominionsRecursive(sub_dominion)); @@ -777,11 +777,11 @@ public class DominionController { return Cache.instance.getPlayerDominionCount(operator.getUniqueId()) >= Dominion.config.getLimitAmount(operator.getPlayer()) && Dominion.config.getLimitAmount(operator.getPlayer()) != -1; } - private static boolean worldNotValid(AbstractOperator operator, String world) { + private static boolean worldNotValid(AbstractOperator operator, String worldName) { if (operator.isOp() && Dominion.config.getLimitOpBypass()) { return false; } - return Dominion.config.getWorldBlackList(operator.getPlayer()).contains(world); + return Dominion.config.getWorldBlackList(operator.getPlayer()).contains(worldName); } private static DominionDTO getExistDomAndIsOwner(AbstractOperator operator, String dominion_name) { @@ -854,7 +854,7 @@ public class DominionController { operator.setResponse(FAIL.addMessage("无法获取你的位置")); return null; } - if (!operator.getLocation().getWorld().getName().equals(dominion.getWorld())) { + if (!operator.getLocation().getWorld().getUID().equals(dominion.getWorldUid())) { operator.setResponse(FAIL.addMessage("禁止跨世界操作")); return null; } @@ -929,7 +929,7 @@ public class DominionController { for (DominionDTO sub_dominion : sub_dominions) { sub_names = sub_dominion.getName() + ", "; } - if (sub_dominions.size() > 0) { + if (!sub_dominions.isEmpty()) { sub_names = sub_names.substring(0, sub_names.length() - 2); WARNING.addMessage("(子领地:%s)", sub_names); } diff --git a/core/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java b/core/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java index b768698..c44d732 100644 --- a/core/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java +++ b/core/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java @@ -10,6 +10,8 @@ import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow; import cn.lunadeer.minecraftpluginutils.databse.syntax.UpdateRow; import org.bukkit.Location; import org.bukkit.World; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.sql.ResultSet; import java.sql.SQLException; @@ -89,6 +91,10 @@ public class DominionDTO { return dominions.getFirst(); } + public static List selectByParentId(World world, Integer parentId){ + return selectByParentId(world.getUID(), parentId); + } + public static List selectByParentId(UUID world_uid, Integer parentId) { String sql = "SELECT * FROM dominion WHERE world_uid = ? AND parent_dom_id = ? AND id > 0;"; return query(sql, world_uid.toString(), parentId); @@ -181,14 +187,14 @@ public class DominionDTO { this.parentDomId.value = parentDomId; } - public DominionDTO(UUID owner, String name, UUID world_uid, + public DominionDTO(UUID owner, String name, @NotNull World world, Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2) { - this(null, owner, name, world_uid, x1, y1, z1, x2, y2, z2, -1); + this(null, owner, name, world.getUID(), x1, y1, z1, x2, y2, z2, -1); } - public static DominionDTO create(UUID owner, String name, UUID world_uid, + public static DominionDTO create(UUID owner, String name, @NotNull World world, Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2, DominionDTO parent) { - return new DominionDTO(null, owner, name, world_uid, x1, y1, z1, x2, y2, z2, parent == null ? -1 : parent.getId()); + return new DominionDTO(null, owner, name, world.getUID(), x1, y1, z1, x2, y2, z2, parent == null ? -1 : parent.getId()); } private final Field id = new Field("id", FieldType.INT); @@ -247,7 +253,7 @@ public class DominionDTO { return doUpdate(new UpdateRow().field(this.name)); } - public World getWorld() { + public @Nullable World getWorld() { return Dominion.instance.getServer().getWorld(getWorldUid()); } diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/DatabaseTables.java b/core/src/main/java/cn/lunadeer/dominion/managers/DatabaseTables.java index bc5f1fb..fceb427 100644 --- a/core/src/main/java/cn/lunadeer/dominion/managers/DatabaseTables.java +++ b/core/src/main/java/cn/lunadeer/dominion/managers/DatabaseTables.java @@ -1,12 +1,16 @@ package cn.lunadeer.dominion.managers; +import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.dtos.Flag; import cn.lunadeer.minecraftpluginutils.databse.*; import cn.lunadeer.minecraftpluginutils.databse.syntax.AddColumn; import cn.lunadeer.minecraftpluginutils.databse.syntax.CreateTable; import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow; +import cn.lunadeer.minecraftpluginutils.databse.syntax.RemoveColumn; +import org.bukkit.World; import java.sql.ResultSet; +import java.util.List; public class DatabaseTables { public static void migrate() { @@ -242,5 +246,18 @@ public class DatabaseTables { TableColumn player_name_using_group_title_id = new TableColumn("using_group_title_id", FieldType.INT, false, false, true, false, -1); new AddColumn(player_name_using_group_title_id).table("player_name").ifNotExists().execute(); } + + // 2.3.0 change world name to world uid + if (!Common.IsFieldExist("dominion", "world_uid")) { + TableColumn dominion_world_uid = new TableColumn("world_uid", FieldType.STRING, false, false, true, false, "'00000000-0000-0000-0000-000000000000'"); + new AddColumn(dominion_world_uid).table("dominion").ifNotExists().execute(); + List worlds = Dominion.instance.getServer().getWorlds(); + for (World world : worlds) { + String sql = String.format("UPDATE dominion SET world_uid = '%s' WHERE world = '%s';", world.getUID().toString(), world.getName()); + DatabaseManager.instance.query(sql); + } + DatabaseManager.instance.query("UPDATE dominion SET world_uid = '00000000-0000-0000-0000-000000000000' WHERE world = 'all';"); + new RemoveColumn("world").table("dominion").IfExists().execute(); + } } } diff --git a/core/src/main/java/cn/lunadeer/dominion/utils/BlueMapConnect.java b/core/src/main/java/cn/lunadeer/dominion/utils/BlueMapConnect.java index f75eee1..453a829 100644 --- a/core/src/main/java/cn/lunadeer/dominion/utils/BlueMapConnect.java +++ b/core/src/main/java/cn/lunadeer/dominion/utils/BlueMapConnect.java @@ -21,10 +21,13 @@ public class BlueMapConnect { BlueMapAPI.getInstance().ifPresent(api -> { Map> world_dominions = new HashMap<>(); for (DominionDTO dominion : Cache.instance.getDominions()) { - if (!world_dominions.containsKey(dominion.getWorld())) { - world_dominions.put(dominion.getWorld(), new ArrayList<>()); + if (dominion.getWorld() == null) { + continue; } - world_dominions.get(dominion.getWorld()).add(dominion); + if (!world_dominions.containsKey(dominion.getWorld().getName())) { + world_dominions.put(dominion.getWorld().getName(), new ArrayList<>()); + } + world_dominions.get(dominion.getWorld().getName()).add(dominion); } for (Map.Entry> d : world_dominions.entrySet()) { api.getWorld(d.getKey()).ifPresent(world -> { diff --git a/core/src/main/java/cn/lunadeer/dominion/utils/DynmapConnect.java b/core/src/main/java/cn/lunadeer/dominion/utils/DynmapConnect.java index 9d3f0c3..b272ce4 100644 --- a/core/src/main/java/cn/lunadeer/dominion/utils/DynmapConnect.java +++ b/core/src/main/java/cn/lunadeer/dominion/utils/DynmapConnect.java @@ -42,11 +42,14 @@ public class DynmapConnect extends DynmapCommonAPIListener { String nameLabel = "
" + dominion.getName() + "
"; double[] xx = {dominion.getX1(), dominion.getX2()}; double[] zz = {dominion.getZ1(), dominion.getZ2()}; + if (dominion.getWorld() == null) { + return; + } AreaMarker marker = this.markerSet_dominion.createAreaMarker( dominion.getId().toString(), nameLabel, true, - dominion.getWorld(), + dominion.getWorld().getName(), xx, zz, false diff --git a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/SelectPointEvents.java b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/SelectPointEvents.java index 09e4d85..67d771f 100644 --- a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/SelectPointEvents.java +++ b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/SelectPointEvents.java @@ -78,7 +78,7 @@ public class SelectPointEvents implements Listener { int maxX = Math.max(loc1.getBlockX(), loc2.getBlockX()) + 1; int maxY = Math.max(loc1.getBlockY(), loc2.getBlockY()) + 1; int maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ()) + 1; - DominionDTO dominion = new DominionDTO(player.getUniqueId(), "", loc1.getWorld().getName(), + DominionDTO dominion = new DominionDTO(player.getUniqueId(), "", loc1.getWorld(), minX, minY, minZ, maxX, maxY, maxZ); if (Dominion.config.getEconomyEnable()) { if (!VaultConnect.instance.economyAvailable()) { diff --git a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/SelectPointEvents.java b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/SelectPointEvents.java index 287d602..5ad5278 100644 --- a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/SelectPointEvents.java +++ b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/SelectPointEvents.java @@ -78,7 +78,7 @@ public class SelectPointEvents implements Listener { int maxX = Math.max(loc1.getBlockX(), loc2.getBlockX()) + 1; int maxY = Math.max(loc1.getBlockY(), loc2.getBlockY()) + 1; int maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ()) + 1; - DominionDTO dominion = new DominionDTO(player.getUniqueId(), "", loc1.getWorld().getName(), + DominionDTO dominion = new DominionDTO(player.getUniqueId(), "", loc1.getWorld(), minX, minY, minZ, maxX, maxY, maxZ); if (Dominion.config.getEconomyEnable()) { if (!VaultConnect.instance.economyAvailable()) {