优化缓存领地搜索算法,提速300%

This commit is contained in:
zhangyuheng 2024-07-17 18:06:58 +08:00
parent 0fe7f28c64
commit b3934b9fe2
12 changed files with 175 additions and 99 deletions

View File

@ -8,8 +8,6 @@
### [统计页面](https://bstats.org/plugin/bukkit/Dominion/21445) | [Hangar](https://hangar.papermc.io/zhangyuheng/Dominion) ### [统计页面](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)
</div> </div>
## 简介 ## 简介

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId> <groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId> <artifactId>Dominion</artifactId>
<version>1.36.1-beta</version> <version>1.37.0-beta</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Dominion</name> <name>Dominion</name>

View File

@ -9,15 +9,17 @@ import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import static cn.lunadeer.dominion.DominionNode.getLocInDominionDTO; import static cn.lunadeer.dominion.DominionNode.getLocInDominionNode;
public class Cache { public class Cache {
@ -62,25 +64,21 @@ public class Cache {
int count = 0; int count = 0;
if (idToLoad == null) { if (idToLoad == null) {
id_dominions = new ConcurrentHashMap<>(); id_dominions = new ConcurrentHashMap<>();
world_dominion_tree = new ConcurrentHashMap<>();
dominion_children = new ConcurrentHashMap<>(); dominion_children = new ConcurrentHashMap<>();
List<DominionDTO> dominions = DominionDTO.selectAll(); List<DominionDTO> dominions = DominionDTO.selectAll();
CompletableFuture<Void> res = dominion_trees.initAsync(dominions);
count = dominions.size(); count = dominions.size();
Map<String, List<DominionDTO>> world_dominions = new HashMap<>();
for (DominionDTO d : dominions) { 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); id_dominions.put(d.getId(), d);
if (!dominion_children.containsKey(d.getParentDomId())) { if (!dominion_children.containsKey(d.getParentDomId())) {
dominion_children.put(d.getParentDomId(), new ArrayList<>()); dominion_children.put(d.getParentDomId(), new ArrayList<>());
} }
dominion_children.get(d.getParentDomId()).add(d.getId()); dominion_children.get(d.getParentDomId()).add(d.getId());
} }
for (Map.Entry<String, List<DominionDTO>> entry : world_dominions.entrySet()) {
world_dominion_tree.put(entry.getKey(), DominionNode.BuildNodeTree(-1, entry.getValue())); res.join(); // 等待树的构建完成
}
} else { } else {
DominionDTO dominion = DominionDTO.select(idToLoad); DominionDTO dominion = DominionDTO.select(idToLoad);
if (dominion == null && id_dominions.containsKey(idToLoad)) { if (dominion == null && id_dominions.containsKey(idToLoad)) {
@ -225,7 +223,7 @@ public class Cache {
return last_dominion; 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 last_dom_id = last_dominion == null ? -1 : last_dominion.getId();
int current_dom_id = current_dominion == null ? -1 : current_dominion.getId(); int current_dom_id = current_dominion == null ? -1 : current_dominion.getId();
if (last_dom_id == current_dom_id) { if (last_dom_id == current_dom_id) {
@ -337,30 +335,8 @@ public class Cache {
} }
} }
public DominionDTO getDominion(Location loc) { public DominionDTO getDominionByLoc(Location loc) {
return getLocInDominionDTO(world_dominion_tree.get(loc.getWorld().getName()), loc); return dominion_trees.getLocInDominionDTO(loc);
}
public List<DominionNode> getDominionTreeByPlayer(String player_name) {
List<DominionNode> dominionTree = new ArrayList<>();
PlayerDTO player = PlayerDTO.select(player_name);
if (player == null) return dominionTree;
for (List<DominionNode> tree : world_dominion_tree.values()) {
for (DominionNode node : tree) {
if (node.getDominion().getOwner().equals(player.getUuid())) {
dominionTree.add(node);
}
}
}
return dominionTree;
}
public List<DominionNode> getAllDominionTree() {
List<DominionNode> dominionTree = new ArrayList<>();
for (List<DominionNode> tree : world_dominion_tree.values()) {
dominionTree.addAll(tree);
}
return dominionTree;
} }
public GroupDTO getGroup(Integer id) { public GroupDTO getGroup(Integer id) {
@ -451,8 +427,8 @@ public class Cache {
public static Cache instance; public static Cache instance;
private ConcurrentHashMap<Integer, DominionDTO> id_dominions; private ConcurrentHashMap<Integer, DominionDTO> id_dominions;
private ConcurrentHashMap<String, List<DominionNode>> world_dominion_tree;
private ConcurrentHashMap<Integer, GroupDTO> id_groups; private ConcurrentHashMap<Integer, GroupDTO> id_groups;
private final WorldDominionTreeSectored dominion_trees = new WorldDominionTreeSectored();
private ConcurrentHashMap<UUID, ConcurrentHashMap<Integer, MemberDTO>> player_uuid_to_member; // 玩家所有的特权 private ConcurrentHashMap<UUID, ConcurrentHashMap<Integer, MemberDTO>> player_uuid_to_member; // 玩家所有的特权
private final Map<UUID, Integer> player_current_dominion_id; // 玩家当前所在领地 private final Map<UUID, Integer> player_current_dominion_id; // 玩家当前所在领地
private ConcurrentHashMap<Integer, List<Integer>> dominion_children; private ConcurrentHashMap<Integer, List<Integer>> dominion_children;
@ -467,4 +443,116 @@ public class Cache {
public final Map<UUID, LocalDateTime> NextTimeAllowTeleport = new java.util.HashMap<>(); public final Map<UUID, LocalDateTime> NextTimeAllowTeleport = new java.util.HashMap<>();
private Map<UUID, List<ResMigration.ResidenceNode>> residence_data = null; private Map<UUID, List<ResMigration.ResidenceNode>> residence_data = null;
private static class WorldDominionTreeSectored {
/*
D | C
--+--
B | A
*/
private ConcurrentHashMap<String, List<DominionNode>> world_dominion_tree_sector_a; // x >= 0, z >= 0
private ConcurrentHashMap<String, List<DominionNode>> world_dominion_tree_sector_b; // x <= 0, z >= 0
private ConcurrentHashMap<String, List<DominionNode>> world_dominion_tree_sector_c; // x >= 0, z <= 0
private ConcurrentHashMap<String, List<DominionNode>> world_dominion_tree_sector_d; // x <= 0, z <= 0
public DominionDTO getLocInDominionDTO(@NotNull Location loc) {
List<DominionNode> 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<DominionNode> getNodes(Location loc) {
return getNodes(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ());
}
public List<DominionNode> 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<Void> initAsync(List<DominionDTO> dominions) {
return CompletableFuture.runAsync(() -> init(dominions));
}
private void init(List<DominionDTO> 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<String, List<DominionDTO>> world_dominions_sector_a = new HashMap<>();
Map<String, List<DominionDTO>> world_dominions_sector_b = new HashMap<>();
Map<String, List<DominionDTO>> world_dominions_sector_c = new HashMap<>();
Map<String, List<DominionDTO>> 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<String, List<DominionDTO>> entry : world_dominions_sector_a.entrySet()) {
world_dominion_tree_sector_a.put(entry.getKey(), DominionNode.BuildNodeTree(-1, entry.getValue()));
}
for (Map.Entry<String, List<DominionDTO>> entry : world_dominions_sector_b.entrySet()) {
world_dominion_tree_sector_b.put(entry.getKey(), DominionNode.BuildNodeTree(-1, entry.getValue()));
}
for (Map.Entry<String, List<DominionDTO>> entry : world_dominions_sector_c.entrySet()) {
world_dominion_tree_sector_c.put(entry.getKey(), DominionNode.BuildNodeTree(-1, entry.getValue()));
}
for (Map.Entry<String, List<DominionDTO>> entry : world_dominions_sector_d.entrySet()) {
world_dominion_tree_sector_d.put(entry.getKey(), DominionNode.BuildNodeTree(-1, entry.getValue()));
}
}
}
} }

View File

@ -66,13 +66,6 @@ public class DominionNode {
return null; return null;
} }
public static DominionDTO getLocInDominionDTO(@Nullable List<DominionNode> 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) { public static boolean isInDominion(@Nullable DominionDTO dominion, Location location) {
if (dominion == null) return false; if (dominion == null) return false;
if (!Objects.equals(dominion.getWorld(), location.getWorld().getName())) return false; if (!Objects.equals(dominion.getWorld(), location.getWorld().getName())) return false;

View File

@ -37,7 +37,7 @@ public class Apis {
player.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "无法获取你的位置信息")); player.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "无法获取你的位置信息"));
return null; return null;
} }
DominionDTO dominion = Cache.instance.getDominion(location); DominionDTO dominion = Cache.instance.getDominionByLoc(location);
if (dominion == null) { if (dominion == null) {
return null; return null;
} }

View File

@ -26,7 +26,7 @@ import static cn.lunadeer.dominion.controllers.Apis.notOwner;
public class DominionController { public class DominionController {
public static List<DominionDTO> all(Player owner) { public static List<DominionDTO> all(Player owner) {
return DominionDTO.selectAll(owner.getUniqueId()); return DominionDTO.selectByOwner(owner.getUniqueId());
} }
public static List<DominionDTO> all() { public static List<DominionDTO> all() {

View File

@ -65,18 +65,13 @@ public class DominionDTO {
return query(sql); return query(sql);
} }
public static List<DominionDTO> selectAll(String world) {
String sql = "SELECT * FROM dominion WHERE world = ? AND id > 0;";
return query(sql, world);
}
public static List<DominionDTO> search(String name) { public static List<DominionDTO> search(String name) {
String sql = "SELECT * FROM dominion WHERE name LIKE ? AND id > 0;"; String sql = "SELECT * FROM dominion WHERE name LIKE ? AND id > 0;";
return query(sql, "%" + name + "%"); return query(sql, "%" + name + "%");
} }
public static List<DominionDTO> selectAll(UUID owner) { public static List<DominionDTO> selectByOwner(UUID owner) {
String sql = "SELECT * FROM dominion WHERE owner = ? AND id > 0;"; String sql = "SELECT * FROM dominion WHERE owner = ? AND id > 0 ORDER BY id DESC;";
return query(sql, owner.toString()); return query(sql, owner.toString());
} }

View File

@ -37,7 +37,7 @@ public class Apis {
if (inv.getLocation() == null) { if (inv.getLocation() == null) {
return null; return null;
} else { } else {
return Cache.instance.getDominion(inv.getLocation()); return Cache.instance.getDominionByLoc(inv.getLocation());
} }
} }

View File

@ -34,7 +34,7 @@ public class EnvironmentEvents implements Listener {
) { ) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(event.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(event.getLocation());
checkFlag(dom, Flag.CREEPER_EXPLODE, event); checkFlag(dom, Flag.CREEPER_EXPLODE, event);
} }
@ -44,7 +44,7 @@ public class EnvironmentEvents implements Listener {
if (entity.getType() != EntityType.ENDER_DRAGON) { if (entity.getType() != EntityType.ENDER_DRAGON) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(event.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(event.getLocation());
checkFlag(dom, Flag.DRAGON_BREAK_BLOCK, event); checkFlag(dom, Flag.DRAGON_BREAK_BLOCK, event);
} }
@ -55,7 +55,7 @@ public class EnvironmentEvents implements Listener {
// 如果点燃事件没有玩家触发那么就是火焰蔓延 // 如果点燃事件没有玩家触发那么就是火焰蔓延
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(event.getBlock().getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(event.getBlock().getLocation());
checkFlag(dom, Flag.FIRE_SPREAD, event); checkFlag(dom, Flag.FIRE_SPREAD, event);
} }
@ -63,11 +63,11 @@ public class EnvironmentEvents implements Listener {
public void onLiquidFlowIn(BlockFromToEvent event) { public void onLiquidFlowIn(BlockFromToEvent event) {
Location from = event.getBlock().getLocation(); Location from = event.getBlock().getLocation();
Location to = event.getToBlock().getLocation(); Location to = event.getToBlock().getLocation();
DominionDTO dom_to = Cache.instance.getDominion(to); DominionDTO dom_to = Cache.instance.getDominionByLoc(to);
if (dom_to == null) { if (dom_to == null) {
return; return;
} }
DominionDTO dom_from = Cache.instance.getDominion(from); DominionDTO dom_from = Cache.instance.getDominionByLoc(from);
if (dom_from != null) { if (dom_from != null) {
if (Objects.equals(dom_from.getId(), dom_to.getId())) { if (Objects.equals(dom_from.getId(), dom_to.getId())) {
return; return;
@ -82,7 +82,7 @@ public class EnvironmentEvents implements Listener {
if (entity instanceof Player) { if (entity instanceof Player) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
if (dom == null) { if (dom == null) {
return; return;
} }
@ -101,7 +101,7 @@ public class EnvironmentEvents implements Listener {
if (entity.getType() != EntityType.MINECART_TNT && entity.getType() != EntityType.PRIMED_TNT) { if (entity.getType() != EntityType.MINECART_TNT && entity.getType() != EntityType.PRIMED_TNT) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(event.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(event.getLocation());
checkFlag(dom, Flag.TNT_EXPLODE, event); checkFlag(dom, Flag.TNT_EXPLODE, event);
} }
@ -117,7 +117,7 @@ public class EnvironmentEvents implements Listener {
if (block.getType() != FARMLAND) { if (block.getType() != FARMLAND) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(block.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.TRAMPLE, event); checkFlag(dom, Flag.TRAMPLE, event);
} }
@ -127,7 +127,7 @@ public class EnvironmentEvents implements Listener {
if (entity.getType() != EntityType.WITHER) { if (entity.getType() != EntityType.WITHER) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.WITHER_SPAWN, event); checkFlag(dom, Flag.WITHER_SPAWN, event);
} }
@ -137,7 +137,7 @@ public class EnvironmentEvents implements Listener {
if (entity.getType() != EntityType.ENDERMAN) { if (entity.getType() != EntityType.ENDERMAN) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.ENDER_MAN, event); checkFlag(dom, Flag.ENDER_MAN, event);
} }
@ -147,7 +147,7 @@ public class EnvironmentEvents implements Listener {
if (entity.getType() != EntityType.ENDERMAN) { if (entity.getType() != EntityType.ENDERMAN) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.ENDER_MAN, event); checkFlag(dom, Flag.ENDER_MAN, event);
} }
@ -157,7 +157,7 @@ public class EnvironmentEvents implements Listener {
if (!(entity instanceof Monster)) { if (!(entity instanceof Monster)) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.MONSTER_SPAWN, event); checkFlag(dom, Flag.MONSTER_SPAWN, event);
} }
@ -167,7 +167,7 @@ public class EnvironmentEvents implements Listener {
if (!(entity instanceof Animals)) { if (!(entity instanceof Animals)) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.ANIMAL_SPAWN, event); checkFlag(dom, Flag.ANIMAL_SPAWN, event);
} }
@ -177,7 +177,7 @@ public class EnvironmentEvents implements Listener {
if (entity.getType() != EntityType.VILLAGER) { if (entity.getType() != EntityType.VILLAGER) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.VILLAGER_SPAWN, event); checkFlag(dom, Flag.VILLAGER_SPAWN, event);
} }
} }

View File

@ -71,7 +71,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player bukkitPlayer = (Player) event.getDamager(); 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); checkFlag(dom, Flag.ANIMAL_KILLING, bukkitPlayer, event);
} }
@ -114,7 +114,7 @@ public class PlayerEvents implements Listener {
if (!(Tag.BEDS.isTagged(block.getType()))) { if (!(Tag.BEDS.isTagged(block.getType()))) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(block.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.BED, bukkitPlayer, event); checkFlag(dom, Flag.BED, bukkitPlayer, event);
} }
@ -159,7 +159,7 @@ public class PlayerEvents implements Listener {
} }
public static boolean onBreak(Player player, Location location) { 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); return checkFlag(dom, Flag.BREAK_BLOCK, player, null);
} }
@ -176,7 +176,7 @@ public class PlayerEvents implements Listener {
if (!Tag.BUTTONS.isTagged(block.getType())) { if (!Tag.BUTTONS.isTagged(block.getType())) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(block.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.BUTTON, player, event); checkFlag(dom, Flag.BUTTON, player, event);
} }
@ -194,7 +194,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
DominionDTO dom = Cache.instance.getDominion(block.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.CAKE, player, event); checkFlag(dom, Flag.CAKE, player, event);
} }
@ -204,7 +204,7 @@ public class PlayerEvents implements Listener {
if (loc == null) { if (loc == null) {
dom = null; dom = null;
} else { } else {
dom = Cache.instance.getDominion(loc); dom = Cache.instance.getDominionByLoc(loc);
} }
return checkFlag(dom, Flag.CONTAINER, player, null); return checkFlag(dom, Flag.CONTAINER, player, null);
} }
@ -292,7 +292,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = event.getPlayer(); 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); checkFlag(dom, Flag.COMPARER, player, event);
} }
@ -309,7 +309,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = event.getPlayer(); 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); checkFlag(dom, Flag.DOOR, player, event);
} }
@ -323,7 +323,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = event.getPlayer(); 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); checkFlag(dom, Flag.DRAGON_EGG, player, event);
} }
@ -334,7 +334,7 @@ public class PlayerEvents implements Listener {
if (!(entity instanceof Colorable)) { if (!(entity instanceof Colorable)) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.DYE, player, event); checkFlag(dom, Flag.DYE, player, event);
} }
@ -351,7 +351,7 @@ public class PlayerEvents implements Listener {
if (!(Tag.SIGNS.isTagged(block.getType()))) { if (!(Tag.SIGNS.isTagged(block.getType()))) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(block.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.EDIT_SIGN, player, event); checkFlag(dom, Flag.EDIT_SIGN, player, event);
} }
@ -359,7 +359,7 @@ public class PlayerEvents implements Listener {
public void onSignEdit(SignChangeEvent event) { public void onSignEdit(SignChangeEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getBlock(); 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); checkFlag(dom, Flag.EDIT_SIGN, player, event);
} }
@ -412,7 +412,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = event.getPlayer(); 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); checkFlag(dom, Flag.FEED, player, event);
} }
@ -438,7 +438,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
DominionDTO dom = Cache.instance.getDominion(block.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.HARVEST, player, event); checkFlag(dom, Flag.HARVEST, player, event);
} }
@ -456,7 +456,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
DominionDTO dom = Cache.instance.getDominion(block.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.HONEY, player, event); checkFlag(dom, Flag.HONEY, player, event);
} }
@ -467,7 +467,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
DominionDTO dom = Cache.instance.getDominion(caught.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(caught.getLocation());
checkFlag(dom, Flag.HOOK, player, event); checkFlag(dom, Flag.HOOK, player, event);
} }
@ -496,7 +496,7 @@ public class PlayerEvents implements Listener {
if (player == null) { if (player == null) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(event.getBlock().getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(event.getBlock().getLocation());
checkFlag(dom, Flag.IGNITE, player, event); checkFlag(dom, Flag.IGNITE, player, event);
} }
@ -514,7 +514,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
DominionDTO dom = Cache.instance.getDominion(block.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.LEVER, player, event); checkFlag(dom, Flag.LEVER, player, event);
} }
@ -529,7 +529,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player bukkitPlayer = (Player) event.getDamager(); 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); checkFlag(dom, Flag.MONSTER_KILLING, bukkitPlayer, event);
} }
@ -601,7 +601,7 @@ public class PlayerEvents implements Listener {
} }
public static boolean onPlace(Player player, Location location) { 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); return checkFlag(dom, Flag.PLACE, player, null);
} }
@ -618,7 +618,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
DominionDTO dom = Cache.instance.getDominion(block.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.PRESSURE, player, event); checkFlag(dom, Flag.PRESSURE, player, event);
} }
@ -628,7 +628,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = (Player) event.getEntity(); 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); checkFlag(dom, Flag.RIDING, player, event);
} }
@ -643,14 +643,14 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
DominionDTO dom = Cache.instance.getDominion(block.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.REPEATER, player, event); checkFlag(dom, Flag.REPEATER, player, event);
} }
@EventHandler(priority = EventPriority.HIGHEST) // shear @EventHandler(priority = EventPriority.HIGHEST) // shear
public void onShear(PlayerShearEntityEvent event) { public void onShear(PlayerShearEntityEvent event) {
Player player = event.getPlayer(); 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); checkFlag(dom, Flag.SHEAR, player, event);
} }
@ -688,7 +688,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = (Player) event.getAttacker(); 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); checkFlag(dom, Flag.VEHICLE_DESTROY, player, event);
} }
@ -702,7 +702,7 @@ public class PlayerEvents implements Listener {
if (!(entity instanceof Vehicle)) { if (!(entity instanceof Vehicle)) {
return; return;
} }
DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.VEHICLE_SPAWN, player, event); checkFlag(dom, Flag.VEHICLE_SPAWN, player, event);
} }
@ -715,7 +715,7 @@ public class PlayerEvents implements Listener {
return; return;
} }
Player player = (Player) event.getDamager(); 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); checkFlag(dom, Flag.VILLAGER_KILLING, player, event);
} }
} }

View File

@ -2,6 +2,7 @@ package cn.lunadeer.dominion.tuis;
import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.DominionNode; import cn.lunadeer.dominion.DominionNode;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.minecraftpluginutils.stui.ListView; import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button; import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line; import cn.lunadeer.minecraftpluginutils.stui.components.Line;
@ -23,7 +24,7 @@ public class AllDominion {
if (notOp(player)) return; if (notOp(player)) return;
int page = getPage(args, 1); int page = getPage(args, 1);
List<DominionNode> allDominions = Cache.instance.getAllDominionTree(); List<DominionNode> allDominions = DominionNode.BuildNodeTree(-1, DominionDTO.selectAll());
ListView view = ListView.create(10, "/dominion all_dominion"); ListView view = ListView.create(10, "/dominion all_dominion");

View File

@ -2,6 +2,7 @@ package cn.lunadeer.dominion.tuis.dominion;
import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.DominionNode; import cn.lunadeer.dominion.DominionNode;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.minecraftpluginutils.stui.ListView; import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.ViewStyles; import cn.lunadeer.minecraftpluginutils.stui.ViewStyles;
import cn.lunadeer.minecraftpluginutils.stui.components.Button; import cn.lunadeer.minecraftpluginutils.stui.components.Button;
@ -27,7 +28,7 @@ public class DominionList {
view.title("我的领地列表"); view.title("我的领地列表");
view.navigator(Line.create().append(Button.create("主菜单").setExecuteCommand("/dominion menu").build()).append("我的领地")); 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<String> admin_dominions = playerAdminDominions(sender); List<String> admin_dominions = playerAdminDominions(sender);
if (admin_dominions.size() != 0) { if (admin_dominions.size() != 0) {
view.add(Line.create().append("")); view.add(Line.create().append(""));