From b3934b9fe2cead1528825582e70aa1505b43fda9 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Wed, 17 Jul 2024 18:06:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E9=A2=86=E5=9C=B0=E6=90=9C=E7=B4=A2=E7=AE=97=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E9=80=9F300%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 - pom.xml | 2 +- src/main/java/cn/lunadeer/dominion/Cache.java | 160 ++++++++++++++---- .../cn/lunadeer/dominion/DominionNode.java | 7 - .../lunadeer/dominion/controllers/Apis.java | 2 +- .../controllers/DominionController.java | 2 +- .../lunadeer/dominion/dtos/DominionDTO.java | 9 +- .../cn/lunadeer/dominion/events/Apis.java | 2 +- .../dominion/events/EnvironmentEvents.java | 28 +-- .../dominion/events/PlayerEvents.java | 54 +++--- .../lunadeer/dominion/tuis/AllDominion.java | 3 +- .../dominion/tuis/dominion/DominionList.java | 3 +- 12 files changed, 175 insertions(+), 99 deletions(-) diff --git a/README.md b/README.md index 55ee011..bf438bc 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,6 @@ ### [统计页面](https://bstats.org/plugin/bukkit/Dominion/21445) | [Hangar](https://hangar.papermc.io/zhangyuheng/Dominion) -[![CodeFactor](https://www.codefactor.io/repository/github/deergiteamirror/dominion/badge/master)](https://www.codefactor.io/repository/github/deergiteamirror/dominion/overview/master) - ## 简介 diff --git a/pom.xml b/pom.xml index bcc2c0e..6b93e0c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.lunadeer Dominion - 1.36.1-beta + 1.37.0-beta jar Dominion diff --git a/src/main/java/cn/lunadeer/dominion/Cache.java b/src/main/java/cn/lunadeer/dominion/Cache.java index d108027..6a9b4e2 100644 --- a/src/main/java/cn/lunadeer/dominion/Cache.java +++ b/src/main/java/cn/lunadeer/dominion/Cache.java @@ -9,15 +9,17 @@ import cn.lunadeer.minecraftpluginutils.XLogger; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import java.time.LocalDateTime; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; -import static cn.lunadeer.dominion.DominionNode.getLocInDominionDTO; +import static cn.lunadeer.dominion.DominionNode.getLocInDominionNode; public class Cache { @@ -62,25 +64,21 @@ public class Cache { int count = 0; if (idToLoad == null) { id_dominions = new ConcurrentHashMap<>(); - world_dominion_tree = new ConcurrentHashMap<>(); dominion_children = new ConcurrentHashMap<>(); + List dominions = DominionDTO.selectAll(); + CompletableFuture res = dominion_trees.initAsync(dominions); count = dominions.size(); - Map> world_dominions = new HashMap<>(); + for (DominionDTO d : dominions) { - if (!world_dominions.containsKey(d.getWorld())) { - world_dominions.put(d.getWorld(), new ArrayList<>()); - } - world_dominions.get(d.getWorld()).add(d); id_dominions.put(d.getId(), d); if (!dominion_children.containsKey(d.getParentDomId())) { dominion_children.put(d.getParentDomId(), new ArrayList<>()); } dominion_children.get(d.getParentDomId()).add(d.getId()); } - for (Map.Entry> entry : world_dominions.entrySet()) { - world_dominion_tree.put(entry.getKey(), DominionNode.BuildNodeTree(-1, entry.getValue())); - } + + res.join(); // 等待树的构建完成 } else { DominionDTO dominion = DominionDTO.select(idToLoad); if (dominion == null && id_dominions.containsKey(idToLoad)) { @@ -225,7 +223,7 @@ public class Cache { return last_dominion; } } - DominionDTO current_dominion = getLocInDominionDTO(world_dominion_tree.get(player.getWorld().getName()), player.getLocation()); + DominionDTO current_dominion = dominion_trees.getLocInDominionDTO(player.getLocation()); int last_dom_id = last_dominion == null ? -1 : last_dominion.getId(); int current_dom_id = current_dominion == null ? -1 : current_dominion.getId(); if (last_dom_id == current_dom_id) { @@ -337,30 +335,8 @@ public class Cache { } } - public DominionDTO getDominion(Location loc) { - return getLocInDominionDTO(world_dominion_tree.get(loc.getWorld().getName()), loc); - } - - public List getDominionTreeByPlayer(String player_name) { - List dominionTree = new ArrayList<>(); - PlayerDTO player = PlayerDTO.select(player_name); - if (player == null) return dominionTree; - for (List tree : world_dominion_tree.values()) { - for (DominionNode node : tree) { - if (node.getDominion().getOwner().equals(player.getUuid())) { - dominionTree.add(node); - } - } - } - return dominionTree; - } - - public List getAllDominionTree() { - List dominionTree = new ArrayList<>(); - for (List tree : world_dominion_tree.values()) { - dominionTree.addAll(tree); - } - return dominionTree; + public DominionDTO getDominionByLoc(Location loc) { + return dominion_trees.getLocInDominionDTO(loc); } public GroupDTO getGroup(Integer id) { @@ -451,8 +427,8 @@ public class Cache { public static Cache instance; private ConcurrentHashMap id_dominions; - private ConcurrentHashMap> world_dominion_tree; private ConcurrentHashMap id_groups; + private final WorldDominionTreeSectored dominion_trees = new WorldDominionTreeSectored(); private ConcurrentHashMap> player_uuid_to_member; // 玩家所有的特权 private final Map player_current_dominion_id; // 玩家当前所在领地 private ConcurrentHashMap> dominion_children; @@ -467,4 +443,116 @@ public class Cache { public final Map NextTimeAllowTeleport = new java.util.HashMap<>(); private Map> residence_data = null; + + private static class WorldDominionTreeSectored { + /* + D | C + --+-- + 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 + + public DominionDTO getLocInDominionDTO(@NotNull Location loc) { + List nodes = getNodes(loc); + if (nodes == null) return null; + if (nodes.isEmpty()) return null; + DominionNode dominionNode = getLocInDominionNode(nodes, loc); + return dominionNode == null ? null : dominionNode.getDominion(); + } + + + public List getNodes(Location loc) { + return getNodes(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ()); + } + + public List getNodes(String world, int x, int z) { + if (x >= 0 && z >= 0) { + return world_dominion_tree_sector_a.get(world); + } + if (x <= 0 && z >= 0) { + return world_dominion_tree_sector_b.get(world); + } + if (x >= 0) { + return world_dominion_tree_sector_c.get(world); + } + return world_dominion_tree_sector_d.get(world); + } + + public CompletableFuture initAsync(List dominions) { + return CompletableFuture.runAsync(() -> init(dominions)); + } + + + private void init(List dominions) { + world_dominion_tree_sector_a = new ConcurrentHashMap<>(); + world_dominion_tree_sector_b = new ConcurrentHashMap<>(); + 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<>(); + 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 (d.getX1() >= 0 && d.getZ1() >= 0) { + world_dominions_sector_a.get(d.getWorld()).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); + } else { + world_dominions_sector_b.get(d.getWorld()).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); + } else { + world_dominions_sector_c.get(d.getWorld()).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); + } 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); + } 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); + } else { + world_dominions_sector_d.get(d.getWorld()).add(d); + } + } + } + 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()) { + world_dominion_tree_sector_b.put(entry.getKey(), DominionNode.BuildNodeTree(-1, entry.getValue())); + } + 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()) { + world_dominion_tree_sector_d.put(entry.getKey(), DominionNode.BuildNodeTree(-1, entry.getValue())); + } + } + } } diff --git a/src/main/java/cn/lunadeer/dominion/DominionNode.java b/src/main/java/cn/lunadeer/dominion/DominionNode.java index 83eeab4..4158dde 100644 --- a/src/main/java/cn/lunadeer/dominion/DominionNode.java +++ b/src/main/java/cn/lunadeer/dominion/DominionNode.java @@ -66,13 +66,6 @@ public class DominionNode { return null; } - public static DominionDTO getLocInDominionDTO(@Nullable List nodes, @NotNull Location loc) { - if (nodes == null) return null; - if (nodes.isEmpty()) return null; - DominionNode dominionNode = getLocInDominionNode(nodes, loc); - return dominionNode == null ? null : dominionNode.getDominion(); - } - public static boolean isInDominion(@Nullable DominionDTO dominion, Location location) { if (dominion == null) return false; if (!Objects.equals(dominion.getWorld(), location.getWorld().getName())) return false; diff --git a/src/main/java/cn/lunadeer/dominion/controllers/Apis.java b/src/main/java/cn/lunadeer/dominion/controllers/Apis.java index 0fa63eb..082f700 100644 --- a/src/main/java/cn/lunadeer/dominion/controllers/Apis.java +++ b/src/main/java/cn/lunadeer/dominion/controllers/Apis.java @@ -37,7 +37,7 @@ public class Apis { player.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "无法获取你的位置信息")); return null; } - DominionDTO dominion = Cache.instance.getDominion(location); + DominionDTO dominion = Cache.instance.getDominionByLoc(location); if (dominion == null) { return null; } diff --git a/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java b/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java index 8d54463..1e98c76 100644 --- a/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java +++ b/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java @@ -26,7 +26,7 @@ import static cn.lunadeer.dominion.controllers.Apis.notOwner; public class DominionController { public static List all(Player owner) { - return DominionDTO.selectAll(owner.getUniqueId()); + return DominionDTO.selectByOwner(owner.getUniqueId()); } public static List all() { diff --git a/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java b/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java index 1ecb31b..d8ab40b 100644 --- a/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java +++ b/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java @@ -65,18 +65,13 @@ public class DominionDTO { return query(sql); } - public static List selectAll(String world) { - String sql = "SELECT * FROM dominion WHERE world = ? AND id > 0;"; - return query(sql, world); - } - public static List search(String name) { String sql = "SELECT * FROM dominion WHERE name LIKE ? AND id > 0;"; return query(sql, "%" + name + "%"); } - public static List selectAll(UUID owner) { - String sql = "SELECT * FROM dominion WHERE owner = ? AND id > 0;"; + public static List selectByOwner(UUID owner) { + String sql = "SELECT * FROM dominion WHERE owner = ? AND id > 0 ORDER BY id DESC;"; return query(sql, owner.toString()); } diff --git a/src/main/java/cn/lunadeer/dominion/events/Apis.java b/src/main/java/cn/lunadeer/dominion/events/Apis.java index 35bbcc9..0b6f0f2 100644 --- a/src/main/java/cn/lunadeer/dominion/events/Apis.java +++ b/src/main/java/cn/lunadeer/dominion/events/Apis.java @@ -37,7 +37,7 @@ public class Apis { if (inv.getLocation() == null) { return null; } else { - return Cache.instance.getDominion(inv.getLocation()); + return Cache.instance.getDominionByLoc(inv.getLocation()); } } diff --git a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java index ba73faa..48818b8 100644 --- a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java @@ -34,7 +34,7 @@ public class EnvironmentEvents implements Listener { ) { return; } - DominionDTO dom = Cache.instance.getDominion(event.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getLocation()); checkFlag(dom, Flag.CREEPER_EXPLODE, event); } @@ -44,7 +44,7 @@ public class EnvironmentEvents implements Listener { if (entity.getType() != EntityType.ENDER_DRAGON) { return; } - DominionDTO dom = Cache.instance.getDominion(event.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getLocation()); checkFlag(dom, Flag.DRAGON_BREAK_BLOCK, event); } @@ -55,7 +55,7 @@ public class EnvironmentEvents implements Listener { // 如果点燃事件没有玩家触发,那么就是火焰蔓延 return; } - DominionDTO dom = Cache.instance.getDominion(event.getBlock().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getBlock().getLocation()); checkFlag(dom, Flag.FIRE_SPREAD, event); } @@ -63,11 +63,11 @@ public class EnvironmentEvents implements Listener { public void onLiquidFlowIn(BlockFromToEvent event) { Location from = event.getBlock().getLocation(); Location to = event.getToBlock().getLocation(); - DominionDTO dom_to = Cache.instance.getDominion(to); + DominionDTO dom_to = Cache.instance.getDominionByLoc(to); if (dom_to == null) { return; } - DominionDTO dom_from = Cache.instance.getDominion(from); + DominionDTO dom_from = Cache.instance.getDominionByLoc(from); if (dom_from != null) { if (Objects.equals(dom_from.getId(), dom_to.getId())) { return; @@ -82,7 +82,7 @@ public class EnvironmentEvents implements Listener { if (entity instanceof Player) { return; } - DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); if (dom == null) { return; } @@ -101,7 +101,7 @@ public class EnvironmentEvents implements Listener { if (entity.getType() != EntityType.MINECART_TNT && entity.getType() != EntityType.PRIMED_TNT) { return; } - DominionDTO dom = Cache.instance.getDominion(event.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getLocation()); checkFlag(dom, Flag.TNT_EXPLODE, event); } @@ -117,7 +117,7 @@ public class EnvironmentEvents implements Listener { if (block.getType() != FARMLAND) { return; } - DominionDTO dom = Cache.instance.getDominion(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.TRAMPLE, event); } @@ -127,7 +127,7 @@ public class EnvironmentEvents implements Listener { if (entity.getType() != EntityType.WITHER) { return; } - DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.WITHER_SPAWN, event); } @@ -137,7 +137,7 @@ public class EnvironmentEvents implements Listener { if (entity.getType() != EntityType.ENDERMAN) { return; } - DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.ENDER_MAN, event); } @@ -147,7 +147,7 @@ public class EnvironmentEvents implements Listener { if (entity.getType() != EntityType.ENDERMAN) { return; } - DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.ENDER_MAN, event); } @@ -157,7 +157,7 @@ public class EnvironmentEvents implements Listener { if (!(entity instanceof Monster)) { return; } - DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.MONSTER_SPAWN, event); } @@ -167,7 +167,7 @@ public class EnvironmentEvents implements Listener { if (!(entity instanceof Animals)) { return; } - DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.ANIMAL_SPAWN, event); } @@ -177,7 +177,7 @@ public class EnvironmentEvents implements Listener { if (entity.getType() != EntityType.VILLAGER) { return; } - DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.VILLAGER_SPAWN, event); } } diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java index 9e64d40..e7577be 100644 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java @@ -71,7 +71,7 @@ public class PlayerEvents implements Listener { return; } Player bukkitPlayer = (Player) event.getDamager(); - DominionDTO dom = Cache.instance.getDominion(event.getEntity().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.ANIMAL_KILLING, bukkitPlayer, event); } @@ -114,7 +114,7 @@ public class PlayerEvents implements Listener { if (!(Tag.BEDS.isTagged(block.getType()))) { return; } - DominionDTO dom = Cache.instance.getDominion(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.BED, bukkitPlayer, event); } @@ -159,7 +159,7 @@ public class PlayerEvents implements Listener { } public static boolean onBreak(Player player, Location location) { - DominionDTO dom = Cache.instance.getDominion(location); + DominionDTO dom = Cache.instance.getDominionByLoc(location); return checkFlag(dom, Flag.BREAK_BLOCK, player, null); } @@ -176,7 +176,7 @@ public class PlayerEvents implements Listener { if (!Tag.BUTTONS.isTagged(block.getType())) { return; } - DominionDTO dom = Cache.instance.getDominion(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.BUTTON, player, event); } @@ -194,7 +194,7 @@ public class PlayerEvents implements Listener { return; } Player player = event.getPlayer(); - DominionDTO dom = Cache.instance.getDominion(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.CAKE, player, event); } @@ -204,7 +204,7 @@ public class PlayerEvents implements Listener { if (loc == null) { dom = null; } else { - dom = Cache.instance.getDominion(loc); + dom = Cache.instance.getDominionByLoc(loc); } return checkFlag(dom, Flag.CONTAINER, player, null); } @@ -292,7 +292,7 @@ public class PlayerEvents implements Listener { return; } Player player = event.getPlayer(); - DominionDTO dom = Cache.instance.getDominion(event.getClickedBlock().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getClickedBlock().getLocation()); checkFlag(dom, Flag.COMPARER, player, event); } @@ -309,7 +309,7 @@ public class PlayerEvents implements Listener { return; } Player player = event.getPlayer(); - DominionDTO dom = Cache.instance.getDominion(event.getClickedBlock().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getClickedBlock().getLocation()); checkFlag(dom, Flag.DOOR, player, event); } @@ -323,7 +323,7 @@ public class PlayerEvents implements Listener { return; } Player player = event.getPlayer(); - DominionDTO dom = Cache.instance.getDominion(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.DRAGON_EGG, player, event); } @@ -334,7 +334,7 @@ public class PlayerEvents implements Listener { if (!(entity instanceof Colorable)) { return; } - DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.DYE, player, event); } @@ -351,7 +351,7 @@ public class PlayerEvents implements Listener { if (!(Tag.SIGNS.isTagged(block.getType()))) { return; } - DominionDTO dom = Cache.instance.getDominion(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.EDIT_SIGN, player, event); } @@ -359,7 +359,7 @@ public class PlayerEvents implements Listener { public void onSignEdit(SignChangeEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); - DominionDTO dom = Cache.instance.getDominion(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.EDIT_SIGN, player, event); } @@ -412,7 +412,7 @@ public class PlayerEvents implements Listener { return; } Player player = event.getPlayer(); - DominionDTO dom = Cache.instance.getDominion(event.getRightClicked().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getRightClicked().getLocation()); checkFlag(dom, Flag.FEED, player, event); } @@ -438,7 +438,7 @@ public class PlayerEvents implements Listener { return; } Player player = event.getPlayer(); - DominionDTO dom = Cache.instance.getDominion(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.HARVEST, player, event); } @@ -456,7 +456,7 @@ public class PlayerEvents implements Listener { return; } Player player = event.getPlayer(); - DominionDTO dom = Cache.instance.getDominion(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.HONEY, player, event); } @@ -467,7 +467,7 @@ public class PlayerEvents implements Listener { return; } Player player = event.getPlayer(); - DominionDTO dom = Cache.instance.getDominion(caught.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(caught.getLocation()); checkFlag(dom, Flag.HOOK, player, event); } @@ -496,7 +496,7 @@ public class PlayerEvents implements Listener { if (player == null) { return; } - DominionDTO dom = Cache.instance.getDominion(event.getBlock().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getBlock().getLocation()); checkFlag(dom, Flag.IGNITE, player, event); } @@ -514,7 +514,7 @@ public class PlayerEvents implements Listener { return; } Player player = event.getPlayer(); - DominionDTO dom = Cache.instance.getDominion(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.LEVER, player, event); } @@ -529,7 +529,7 @@ public class PlayerEvents implements Listener { return; } Player bukkitPlayer = (Player) event.getDamager(); - DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.MONSTER_KILLING, bukkitPlayer, event); } @@ -601,7 +601,7 @@ public class PlayerEvents implements Listener { } public static boolean onPlace(Player player, Location location) { - DominionDTO dom = Cache.instance.getDominion(location); + DominionDTO dom = Cache.instance.getDominionByLoc(location); return checkFlag(dom, Flag.PLACE, player, null); } @@ -618,7 +618,7 @@ public class PlayerEvents implements Listener { return; } Player player = event.getPlayer(); - DominionDTO dom = Cache.instance.getDominion(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.PRESSURE, player, event); } @@ -628,7 +628,7 @@ public class PlayerEvents implements Listener { return; } Player player = (Player) event.getEntity(); - DominionDTO dom = Cache.instance.getDominion(event.getMount().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getMount().getLocation()); checkFlag(dom, Flag.RIDING, player, event); } @@ -643,14 +643,14 @@ public class PlayerEvents implements Listener { return; } Player player = event.getPlayer(); - DominionDTO dom = Cache.instance.getDominion(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.REPEATER, player, event); } @EventHandler(priority = EventPriority.HIGHEST) // shear public void onShear(PlayerShearEntityEvent event) { Player player = event.getPlayer(); - DominionDTO dom = Cache.instance.getDominion(event.getEntity().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.SHEAR, player, event); } @@ -688,7 +688,7 @@ public class PlayerEvents implements Listener { return; } Player player = (Player) event.getAttacker(); - DominionDTO dom = Cache.instance.getDominion(event.getVehicle().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getVehicle().getLocation()); checkFlag(dom, Flag.VEHICLE_DESTROY, player, event); } @@ -702,7 +702,7 @@ public class PlayerEvents implements Listener { if (!(entity instanceof Vehicle)) { return; } - DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.VEHICLE_SPAWN, player, event); } @@ -715,7 +715,7 @@ public class PlayerEvents implements Listener { return; } Player player = (Player) event.getDamager(); - DominionDTO dom = Cache.instance.getDominion(event.getEntity().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.VILLAGER_KILLING, player, event); } } diff --git a/src/main/java/cn/lunadeer/dominion/tuis/AllDominion.java b/src/main/java/cn/lunadeer/dominion/tuis/AllDominion.java index 137cf9f..602a2cb 100644 --- a/src/main/java/cn/lunadeer/dominion/tuis/AllDominion.java +++ b/src/main/java/cn/lunadeer/dominion/tuis/AllDominion.java @@ -2,6 +2,7 @@ package cn.lunadeer.dominion.tuis; import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.DominionNode; +import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.minecraftpluginutils.stui.ListView; import cn.lunadeer.minecraftpluginutils.stui.components.Button; import cn.lunadeer.minecraftpluginutils.stui.components.Line; @@ -23,7 +24,7 @@ public class AllDominion { if (notOp(player)) return; int page = getPage(args, 1); - List allDominions = Cache.instance.getAllDominionTree(); + List allDominions = DominionNode.BuildNodeTree(-1, DominionDTO.selectAll()); ListView view = ListView.create(10, "/dominion all_dominion"); diff --git a/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java b/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java index f666452..24d0cda 100644 --- a/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java +++ b/src/main/java/cn/lunadeer/dominion/tuis/dominion/DominionList.java @@ -2,6 +2,7 @@ package cn.lunadeer.dominion.tuis.dominion; import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.DominionNode; +import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.minecraftpluginutils.stui.ListView; import cn.lunadeer.minecraftpluginutils.stui.ViewStyles; import cn.lunadeer.minecraftpluginutils.stui.components.Button; @@ -27,7 +28,7 @@ public class DominionList { view.title("我的领地列表"); view.navigator(Line.create().append(Button.create("主菜单").setExecuteCommand("/dominion menu").build()).append("我的领地")); - view.addLines(BuildTreeLines(Cache.instance.getDominionTreeByPlayer(player.getName()), 0)); + view.addLines(BuildTreeLines(DominionNode.BuildNodeTree(-1, DominionDTO.selectByOwner(player.getUniqueId())), 0)); List admin_dominions = playerAdminDominions(sender); if (admin_dominions.size() != 0) { view.add(Line.create().append("")); From 9c2d18cc3e2dfff3e01e90375f681b41cc2da394 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Wed, 17 Jul 2024 23:44:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf438bc..ffcafe3 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ 鉴于 Residence 插件的作者项目较多,维护压力大,无法及时跟进新版本以及适配Folia核心。故开发此插件,旨在平替纯净版生存服Residence的使用。 -请注意,本插件仍然处于测试阶段,因此可能存在一定的行为控制漏洞。如果遇到此类遗漏的行为控制欢迎即使发送邮件或添加QQ告知,感激不尽。 +**请注意,本插件目前处于中期测试稳定阶段,绝大多数bug或漏洞已被修复,目前已具备完全可用性。但不排除仍然存在某些问题,如果遇到任何 BUG 欢迎及时发送邮件或添加QQ群告知,感激不尽。** ## 说明