diff --git a/README.md b/README.md
index 55ee011d..bf438bc9 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 bcc2c0e0..6b93e0c6 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 d1080272..6a9b4e27 100644
--- a/src/main/java/cn/lunadeer/dominion/Cache.java
+++ b/src/main/java/cn/lunadeer/dominion/Cache.java
@@ -9,15 +9,17 @@
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 @@ private void loadDominionsExecution(Integer idToLoad) {
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 DominionDTO getPlayerCurrentDominion(Player player) {
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 @@ private void flyOrNot(Player player, DominionDTO dominion) {
}
}
- 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 int getGroupCounts() {
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 int getGroupCounts() {
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 83eeab4d..4158ddeb 100644
--- a/src/main/java/cn/lunadeer/dominion/DominionNode.java
+++ b/src/main/java/cn/lunadeer/dominion/DominionNode.java
@@ -66,13 +66,6 @@ public static DominionNode getLocInDominionNode(@NotNull List node
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 0fa63ebb..082f7003 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 static DominionDTO getPlayerCurrentDominion(AbstractOperator player) {
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 8d54463c..1e98c766 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 @@
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 1ecb31bb..d8ab40bc 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 static List selectAll() {
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 35bbcc96..0b6f0f28 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 static DominionDTO getInvDominion(Player bukkitPlayer, Inventory inv) {
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 ba73faa3..48818b81 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 void onEntityExplode(EntityExplodeEvent event) {
) {
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 void onDragonBreakBlock(EntityExplodeEvent event) {
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 void onFireSpread(BlockIgniteEvent event) {
// 如果点燃事件没有玩家触发,那么就是火焰蔓延
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 void onFireSpread(BlockIgniteEvent event) {
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 void onMobDropItem(EntityDeathEvent event) {
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 void onTntExplode(EntityExplodeEvent event) {
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 void onFarmlandTrample(PlayerInteractEvent event) {
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 void onWitherSpawn(CreatureSpawnEvent event) {
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 void onEnderManSpawn(CreatureSpawnEvent event) {
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 void onEnderManEscape(EntityTeleportEvent event) {
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 void onMonsterSpawn(CreatureSpawnEvent event) {
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 void onAnimalSpawn(CreatureSpawnEvent event) {
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 void onVillagerSpawn(CreatureSpawnEvent event) {
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 9e64d40f..e7577beb 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 void onAnimalKilling(EntityDamageByEntityEvent event) {
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 void onBedUse(PlayerInteractEvent event) {
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 void onItemFrameBreak(HangingBreakByEntityEvent event) {
}
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 void onButton(PlayerInteractEvent event) {
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 void eatCake(PlayerInteractEvent event) {
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 @@ private static boolean hasContainerPermission(Player player, Location loc) {
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 void comparerChange(PlayerInteractEvent event) {
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 void doorUse(PlayerInteractEvent event) {
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 void touchDragonEdd(PlayerInteractEvent event) {
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 void dyeEvent(PlayerInteractEntityEvent event) {
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 void onSignOpen(PlayerInteractEvent event) {
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 void onSignOpen(PlayerInteractEvent event) {
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 void onFeedAnimal(PlayerInteractEntityEvent event) {
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 void onHarvest(BlockBreakEvent event) {
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 void honeyInteractive(PlayerInteractEvent event) {
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 void onHook(PlayerFishEvent event) {
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 void onPlayerIgnite(BlockIgniteEvent event) {
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 void onLever(PlayerInteractEvent event) {
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 void onMonsterKilling(EntityDamageByEntityEvent event) {
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 void placeItemFrame(HangingPlaceEvent event) {
}
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 void onPressure(PlayerInteractEvent event) {
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 void onRiding(EntityMountEvent event) {
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 void onRepeaterChange(PlayerInteractEvent event) {
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 void onVehicleDestroy(VehicleDestroyEvent event) {
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 void onVehicleSpawn(EntityPlaceEvent event) {
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 void onVillagerKilling(EntityDamageByEntityEvent event) {
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 137cf9fa..602a2cb9 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 @@
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 static void show(CommandSender sender, String[] args) {
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 f666452a..24d0cda2 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 @@
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 static void show(CommandSender sender, String[] args) {
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(""));