diff --git a/api/build.gradle.kts b/api/build.gradle.kts new file mode 100644 index 00000000..0f4ac39d --- /dev/null +++ b/api/build.gradle.kts @@ -0,0 +1,16 @@ +plugins { + id("java") +} + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) +} + +// utf-8 +tasks.withType { + options.encoding = "UTF-8" +} + +dependencies { + compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") +} diff --git a/api/src/main/java/cn/lunadeer/dominion/api/Cache.java b/api/src/main/java/cn/lunadeer/dominion/api/Cache.java new file mode 100644 index 00000000..3fc526a2 --- /dev/null +++ b/api/src/main/java/cn/lunadeer/dominion/api/Cache.java @@ -0,0 +1,71 @@ +package cn.lunadeer.dominion.api; + +import cn.lunadeer.dominion.api.dtos.DominionDTO; +import cn.lunadeer.dominion.api.dtos.GroupDTO; +import cn.lunadeer.dominion.api.dtos.MemberDTO; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; + +public interface Cache { + /** + * 获取玩家当前所在领地 + * + * @param player 玩家 + * @return 玩家当前所在领地 如果玩家不在任何领地内,则返回null + */ + @Nullable DominionDTO getPlayerCurrentDominion(@NotNull Player player); + + /** + * 获取指定位置的领地信息 + * + * @param loc 位置 + * @return 领地信息 如果位置不在任何领地内,则返回null + */ + @Nullable DominionDTO getDominionByLoc(@NotNull Location loc); + + /** + * 根据 ID 获取权限组对象 + * + * @param id 权限组 ID + * @return 权限组对象 如果权限组不存在,则返回null + */ + @Nullable GroupDTO getGroup(@NotNull Integer id); + + /** + * 获取玩家在指定领地的成员信息 + * + * @param player 玩家 + * @param dominion 领地 + * @return 玩家在指定领地的成员信息 如果玩家不属于领地成员,则返回null + */ + @Nullable MemberDTO getMember(@NotNull Player player, @NotNull DominionDTO dominion); + + /** + * 获取玩家在指定领地的成员信息 + * + * @param player_uuid 玩家 UUID + * @param dominion 领地 + * @return 玩家在指定领地的成员信息 如果玩家不属于领地成员,则返回null + */ + @Nullable MemberDTO getMember(@NotNull UUID player_uuid, @NotNull DominionDTO dominion); + + /** + * 获取指定 ID 的领地信息 + * + * @param id 领地 ID + * @return 领地信息 如果领地不存在,则返回null + */ + @Nullable DominionDTO getDominion(@NotNull Integer id); + + /** + * 获取玩家当前正在使用的权限组称号 + * + * @param uuid 玩家 UUID + * @return 权限组对象 如果玩家没有使用任何权限组,则返回null + */ + @Nullable GroupDTO getPlayerUsingGroupTitle(@NotNull UUID uuid); +} diff --git a/api/src/main/java/cn/lunadeer/dominion/api/Dominion.java b/api/src/main/java/cn/lunadeer/dominion/api/Dominion.java new file mode 100644 index 00000000..2417981b --- /dev/null +++ b/api/src/main/java/cn/lunadeer/dominion/api/Dominion.java @@ -0,0 +1,9 @@ +package cn.lunadeer.dominion.api; + +public interface Dominion { + + static Cache getInstance() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { + // Cache.instance is a static field in the Cache class + return (Cache) Class.forName("cn.lunadeer.dominion.Cache").getDeclaredField("instance").get(null); + } +} diff --git a/api/src/main/java/cn/lunadeer/dominion/api/dtos/DominionDTO.java b/api/src/main/java/cn/lunadeer/dominion/api/dtos/DominionDTO.java new file mode 100644 index 00000000..972c4c23 --- /dev/null +++ b/api/src/main/java/cn/lunadeer/dominion/api/dtos/DominionDTO.java @@ -0,0 +1,66 @@ +package cn.lunadeer.dominion.api.dtos; + +import org.bukkit.Location; +import org.bukkit.World; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; + +public interface DominionDTO { + // getters and setters + Integer getId(); + + UUID getOwner(); + + String getName(); + + @Nullable World getWorld(); + + UUID getWorldUid(); + + Integer getX1(); + + Integer getY1(); + + Integer getZ1(); + + Integer getX2(); + + Integer getY2(); + + Integer getZ2(); + + Integer getSquare(); + + Integer getVolume(); + + Integer getWidthX(); + + Integer getHeight(); + + Integer getWidthZ(); + + Integer getParentDomId(); + + String getJoinMessage(); + + String getLeaveMessage(); + + Boolean getFlagValue(Flag flag); + + Location getTpLocation(); + + Location getLocation1(); + + Location getLocation2(); + + int getColorR(); + + int getColorG(); + + int getColorB(); + + String getColor(); + + int getColorHex(); +} diff --git a/api/src/main/java/cn/lunadeer/dominion/api/dtos/Flag.java b/api/src/main/java/cn/lunadeer/dominion/api/dtos/Flag.java new file mode 100644 index 00000000..21ef8436 --- /dev/null +++ b/api/src/main/java/cn/lunadeer/dominion/api/dtos/Flag.java @@ -0,0 +1,13 @@ +package cn.lunadeer.dominion.api.dtos; + +public interface Flag { + String getFlagName(); + + String getDisplayName(); + + String getDescription(); + + Boolean getDefaultValue(); + + Boolean getEnable(); +} diff --git a/api/src/main/java/cn/lunadeer/dominion/api/dtos/GroupDTO.java b/api/src/main/java/cn/lunadeer/dominion/api/dtos/GroupDTO.java new file mode 100644 index 00000000..8038f2cc --- /dev/null +++ b/api/src/main/java/cn/lunadeer/dominion/api/dtos/GroupDTO.java @@ -0,0 +1,19 @@ +package cn.lunadeer.dominion.api.dtos; + +import net.kyori.adventure.text.Component; + +public interface GroupDTO { + Integer getId(); + + Integer getDomID(); + + String getName(); + + Component getNameColoredComponent(); + + String getNameColoredBukkit(); + + Boolean getAdmin(); + + Boolean getFlagValue(Flag flag); +} diff --git a/api/src/main/java/cn/lunadeer/dominion/api/dtos/MemberDTO.java b/api/src/main/java/cn/lunadeer/dominion/api/dtos/MemberDTO.java new file mode 100644 index 00000000..9b9ce8b8 --- /dev/null +++ b/api/src/main/java/cn/lunadeer/dominion/api/dtos/MemberDTO.java @@ -0,0 +1,17 @@ +package cn.lunadeer.dominion.api.dtos; + +import java.util.UUID; + +public interface MemberDTO { + Integer getId(); + + UUID getPlayerUUID(); + + Boolean getAdmin(); + + Integer getDomID(); + + Integer getGroupId(); + + Boolean getFlagValue(Flag flag); +} diff --git a/api/src/main/java/cn/lunadeer/dominion/api/dtos/PrivilegeTemplateDTO.java b/api/src/main/java/cn/lunadeer/dominion/api/dtos/PrivilegeTemplateDTO.java new file mode 100644 index 00000000..d75cf926 --- /dev/null +++ b/api/src/main/java/cn/lunadeer/dominion/api/dtos/PrivilegeTemplateDTO.java @@ -0,0 +1,15 @@ +package cn.lunadeer.dominion.api.dtos; + +import java.util.UUID; + +public interface PrivilegeTemplateDTO { + Integer getId(); + + UUID getCreator(); + + String getName(); + + Boolean getAdmin(); + + Boolean getFlagValue(Flag flag); +} diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 0f4ac39d..b00e2f2d 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -12,5 +12,6 @@ tasks.withType { } dependencies { + implementation(project(":api")) compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") } diff --git a/core/src/main/java/cn/lunadeer/dominion/Cache.java b/core/src/main/java/cn/lunadeer/dominion/Cache.java index dc17ca17..dcc2438f 100644 --- a/core/src/main/java/cn/lunadeer/dominion/Cache.java +++ b/core/src/main/java/cn/lunadeer/dominion/Cache.java @@ -1,50 +1,597 @@ package cn.lunadeer.dominion; -import cn.lunadeer.dominion.dtos.DominionDTO; -import cn.lunadeer.dominion.dtos.GroupDTO; -import cn.lunadeer.dominion.dtos.MemberDTO; +import cn.lunadeer.dominion.dtos.*; +import cn.lunadeer.dominion.utils.MessageDisplay; +import cn.lunadeer.dominion.utils.Particle; +import cn.lunadeer.dominion.utils.ResMigration; +import cn.lunadeer.dominion.utils.map.MapRender; +import cn.lunadeer.minecraftpluginutils.AutoTimer; +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; -import java.util.UUID; +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.getLocInDominionNode; +import static cn.lunadeer.dominion.DominionNode.isInDominion; + +public class Cache implements cn.lunadeer.dominion.api.Cache { + + public Cache() { + player_current_dominion_id = new HashMap<>(); + loadDominions(); + loadMembers(); + loadGroups(); + } -public interface Cache { /** - * 获取玩家当前所在领地 - * 此方法会先判断缓存中是否有玩家当前所在领地,如果没有则遍历所有领地判断玩家所在位置 - * 如果玩家不在任何领地内,则返回null - * 如果玩家在领地内,则返回领地信息 + * 从数据库加载所有领地 + * 如果idToLoad为null,则加载所有领地 * - * @param player 玩家 - * @return 玩家当前所在领地 + * @param idToLoad 领地ID */ - DominionDTO getPlayerCurrentDominion(Player player); + public void loadDominions(Integer idToLoad) { + if (_last_update_dominion.get() + UPDATE_INTERVAL < System.currentTimeMillis()) { + XLogger.debug("run loadDominionsExecution directly"); + loadDominionsExecution(idToLoad); + } else { + if (_update_dominion_is_scheduled.get()) return; + XLogger.debug("schedule loadDominionsExecution"); + _update_dominion_is_scheduled.set(true); + long delay_tick = (UPDATE_INTERVAL - (System.currentTimeMillis() - _last_update_dominion.get())) / 1000 * 20L; + Scheduler.runTaskLaterAsync(() -> { + XLogger.debug("run loadDominionsExecution scheduled"); + loadDominionsExecution(idToLoad); + _update_dominion_is_scheduled.set(false); + }, + delay_tick); + } + } + + public void loadDominions() { + loadDominions(null); + } + + private void loadDominionsExecution(Integer idToLoad) { + Scheduler.runTaskAsync(() -> { + long start = System.currentTimeMillis(); + int count = 0; + if (idToLoad == null) { + id_dominions = new ConcurrentHashMap<>(); + dominion_children = new ConcurrentHashMap<>(); + + List dominions = DominionDTO.selectAll(); + CompletableFuture res = dominion_trees.initAsync(dominions); + count = dominions.size(); + + for (DominionDTO d : dominions) { + 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()); + } + + res.join(); // 等待树的构建完成 + } else { + DominionDTO dominion = DominionDTO.select(idToLoad); + if (dominion == null && id_dominions.containsKey(idToLoad)) { + id_dominions.remove(idToLoad); + } else if (dominion != null) { + id_dominions.put(idToLoad, dominion); + count = 1; + } + } + MapRender.render(); + recheckPlayerState = true; + _last_update_dominion.set(System.currentTimeMillis()); + XLogger.debug("loadDominionsExecution cost: %d ms for %d dominions" + , System.currentTimeMillis() - start, count); + }); + } /** - * 获取指定位置的领地信息 - * 如果位置不在任何领地内,则返回null + * 从数据库加载所有玩家特权 + * 如果player_uuid为null,则加载所有玩家的特权 * - * @param loc 位置 - * @return 领地信息 如果位置不在任何领地内,则返回null + * @param player_uuid 玩家UUID */ - DominionDTO getDominionByLoc(Location loc); + public void loadMembers(UUID player_uuid) { + if (_last_update_member.get() + UPDATE_INTERVAL < System.currentTimeMillis()) { + XLogger.debug("run loadMembersExecution directly"); + loadMembersExecution(player_uuid); + } else { + if (_update_member_is_scheduled.get()) return; + XLogger.debug("schedule loadMembersExecution"); + _update_member_is_scheduled.set(true); + long delay_tick = (UPDATE_INTERVAL - (System.currentTimeMillis() - _last_update_member.get())) / 1000 * 20L; + Scheduler.runTaskLaterAsync(() -> { + XLogger.debug("run loadMembersExecution scheduled"); + loadMembersExecution(player_uuid); + _update_member_is_scheduled.set(false); + }, + delay_tick); + } + } + + public void loadMembers() { + loadMembers(null); + } + + private void loadMembersExecution(UUID player_to_update) { + Scheduler.runTaskAsync(() -> { + long start = System.currentTimeMillis(); + List all_privileges; + if (player_to_update == null) { + all_privileges = MemberDTO.selectAll(); + player_uuid_to_member = new ConcurrentHashMap<>(); + } else { + all_privileges = MemberDTO.selectAll(player_to_update); + if (!player_uuid_to_member.containsKey(player_to_update)) { + player_uuid_to_member.put(player_to_update, new ConcurrentHashMap<>()); + } + player_uuid_to_member.get(player_to_update).clear(); + } + for (MemberDTO privilege : all_privileges) { + UUID player_uuid = privilege.getPlayerUUID(); + if (!player_uuid_to_member.containsKey(player_uuid)) { + player_uuid_to_member.put(player_uuid, new ConcurrentHashMap<>()); + } + player_uuid_to_member.get(player_uuid).put(privilege.getDomID(), privilege); + } + recheckPlayerState = true; + _last_update_member.set(System.currentTimeMillis()); + XLogger.debug("loadMembersExecution cost: %d ms for %d privileges" + , System.currentTimeMillis() - start, all_privileges.size()); + }); + } + + public void loadGroups() { + loadGroups(null); + } + + public void loadGroups(Integer groupId) { + if (_last_update_group.get() + UPDATE_INTERVAL < System.currentTimeMillis()) { + XLogger.debug("run loadGroupsExecution directly"); + loadGroupExecution(groupId); + } else { + if (_update_group_is_scheduled.get()) return; + XLogger.debug("schedule loadGroupsExecution"); + _update_group_is_scheduled.set(true); + long delay_tick = (UPDATE_INTERVAL - (System.currentTimeMillis() - _last_update_group.get())) / 1000 * 20L; + Scheduler.runTaskLaterAsync(() -> { + XLogger.debug("run loadGroupsExecution scheduled"); + loadGroupExecution(groupId); + _update_group_is_scheduled.set(false); + }, + delay_tick); + } + } - GroupDTO getGroup(Integer id); + private void loadGroupExecution(Integer groupId) { + Scheduler.runTaskAsync(() -> { + long start = System.currentTimeMillis(); + if (groupId == null) { + id_groups = new ConcurrentHashMap<>(); + List groups = GroupDTO.selectAll(); + List players = PlayerDTO.all(); + for (GroupDTO group : groups) { + id_groups.put(group.getId(), group); + } + for (PlayerDTO player : players) { + map_player_using_group_title_id.put(player.getUuid(), player.getUsingGroupTitleID()); + } + } else { + GroupDTO group = GroupDTO.select(groupId); + if (group == null && id_groups.containsKey(groupId)) { + id_groups.remove(groupId); + } else if (group != null) { + id_groups.put(groupId, group); + } + } + recheckPlayerState = true; + _last_update_group.set(System.currentTimeMillis()); + XLogger.debug("loadGroupsExecution cost: %d ms", System.currentTimeMillis() - start); + }); + } + + @Override + public DominionDTO getPlayerCurrentDominion(@NotNull Player player) { + try (AutoTimer ignored = new AutoTimer(Dominion.config.TimerEnabled())) { + Integer last_in_dom_id = player_current_dominion_id.get(player.getUniqueId()); + DominionDTO last_dominion = null; + if (last_in_dom_id != null) { + last_dominion = id_dominions.get(last_in_dom_id); + } + if (isInDominion(last_dominion, player.getLocation())) { + if (dominion_children.get(last_in_dom_id) == null || dominion_children.get(last_in_dom_id).isEmpty()) { + // 如果玩家仍在领地内,且领地没有子领地,则直接返回 + if (recheckPlayerState) { + lightOrNot(player, last_dominion); + flyOrNot(player, last_dominion); + recheckPlayerState = false; + } + return last_dominion; + } + } + 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) { + return last_dominion; + } + if (last_dom_id != -1) { + MessageDisplay.show(player, Dominion.config.getMessageDisplayJoinLeave(), last_dominion.getLeaveMessage()); + } + if (current_dom_id != -1) { + MessageDisplay.show(player, Dominion.config.getMessageDisplayJoinLeave(), current_dominion.getJoinMessage()); + } + + lightOrNot(player, current_dominion); // 发光检查 + flyOrNot(player, current_dominion); // 飞行检查 + if (current_dominion == null) { + player_current_dominion_id.put(player.getUniqueId(), null); + return null; + } + player_current_dominion_id.put(player.getUniqueId(), current_dominion.getId()); + // show border + if (current_dominion.getFlagValue(Flag.SHOW_BORDER)) { + Particle.showBorder(player, current_dominion); + } + return current_dominion; + } + } + + @Override + public DominionDTO getDominionByLoc(@NotNull Location loc) { + return dominion_trees.getLocInDominionDTO(loc); + } /** - * 获取玩家在指定领地的特权 - * 如果玩家不存在特权,则返回null + * 玩家退出时调用 用于清除玩家当前所在领地 + * 会将玩家当前所在领地设置为null + * 这样当玩家下次进入领地时,会重新检查玩家所在位置 + * + * @param player 玩家 + */ + public void onPlayerQuit(Player player) { + player_current_dominion_id.put(player.getUniqueId(), null); + } + + /** + * 检查玩家是否需要设置为发光 * * @param player 玩家 * @param dominion 领地 - * @return 特权表 */ - MemberDTO getMember(Player player, DominionDTO dominion); + private void lightOrNot(Player player, DominionDTO dominion) { + if (!Flag.GLOW.getEnable()) { + return; + } + if (dominion == null) { + player.setGlowing(false); + return; + } + MemberDTO privilege = getMember(player, dominion); + if (privilege != null) { + if (privilege.getGroupId() == -1) { + player.setGlowing(privilege.getFlagValue(Flag.GLOW)); + } else { + GroupDTO group = getGroup(privilege.getGroupId()); + if (group != null) { + player.setGlowing(group.getFlagValue(Flag.GLOW)); + } else { + player.setGlowing(dominion.getFlagValue(Flag.GLOW)); + } + } + } else { + player.setGlowing(dominion.getFlagValue(Flag.GLOW)); + } + } + + private void flyOrNot(Player player, DominionDTO dominion) { + for (String flyPN : Dominion.config.getFlyPermissionNodes()) { + if (player.hasPermission(flyPN)) { + return; + } + } + if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) { + return; + } + if (player.isOp() && Dominion.config.getLimitOpBypass()) { + return; + } + if (!Flag.FLY.getEnable()) { + player.setAllowFlight(false); + return; + } + if (dominion == null) { + player.setAllowFlight(false); + return; + } + MemberDTO privilege = getMember(player, dominion); + if (privilege != null) { + if (privilege.getGroupId() == -1) { + player.setAllowFlight(privilege.getFlagValue(Flag.FLY)); + } else { + GroupDTO group = getGroup(privilege.getGroupId()); + if (group != null) { + player.setAllowFlight(group.getFlagValue(Flag.FLY)); + } else { + player.setAllowFlight(dominion.getFlagValue(Flag.FLY)); + } + } + } else { + player.setAllowFlight(dominion.getFlagValue(Flag.FLY)); + } + } + + @Override + public GroupDTO getGroup(@NotNull Integer id) { + return id_groups.get(id); + } + + @Override + public MemberDTO getMember(@NotNull Player player, cn.lunadeer.dominion.api.dtos.@NotNull DominionDTO dominion) { + if (!player_uuid_to_member.containsKey(player.getUniqueId())) return null; + return player_uuid_to_member.get(player.getUniqueId()).get(dominion.getId()); + } + + @Override + public MemberDTO getMember(@NotNull UUID player_uuid, cn.lunadeer.dominion.api.dtos.@NotNull DominionDTO dominion) { + if (!player_uuid_to_member.containsKey(player_uuid)) return null; + return player_uuid_to_member.get(player_uuid).get(dominion.getId()); + } + + public List getBelongGroupsOf(UUID plauer_uuid) { + List groups = new ArrayList<>(); + if (!player_uuid_to_member.containsKey(plauer_uuid)) return groups; + for (MemberDTO member : player_uuid_to_member.get(plauer_uuid).values()) { + if (member.getGroupId() != -1) { + GroupDTO group = getGroup(member.getGroupId()); + if (group != null) { + groups.add(group); + } + } + } + return groups; + } + + @Override + public DominionDTO getDominion(@NotNull Integer id) { + return id_dominions.get(id); + } + + public int getPlayerDominionCount(UUID player_uuid) { + int count = 0; + for (DominionDTO dominion : id_dominions.values()) { + if (dominion.getOwner().equals(player_uuid)) { + count++; + } + } + return count; + } + + public List getResidenceData(UUID player_uuid) { + if (residence_data == null) { + residence_data = new HashMap<>(); + List residences = ResMigration.extractFromResidence(Dominion.instance); + for (ResMigration.ResidenceNode node : residences) { + if (node == null) { + continue; + } + if (!residence_data.containsKey(node.owner)) { + XLogger.debug("residence_data put %s", node.owner); + residence_data.put(node.owner, new ArrayList<>()); + } + residence_data.get(node.owner).add(node); + } + XLogger.debug("residence_data: %d", residence_data.size()); + } + return residence_data.get(player_uuid); + } + + public List getDominions() { + return new ArrayList<>(id_dominions.values()); + } + + public int getDominionCounts() { + return id_dominions.size(); + } + + public int getMemberCounts() { + int count = 0; + for (Map member : player_uuid_to_member.values()) { + count += member.size(); + } + return count; + } + + public int getGroupCounts() { + return id_groups.size(); + } + + public static Cache instance; + private ConcurrentHashMap id_dominions; + 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; + private final AtomicLong _last_update_dominion = new AtomicLong(0); + private final AtomicBoolean _update_dominion_is_scheduled = new AtomicBoolean(false); + private final AtomicLong _last_update_member = new AtomicLong(0); + private final AtomicBoolean _update_member_is_scheduled = new AtomicBoolean(false); + private final AtomicLong _last_update_group = new AtomicLong(0); + private final AtomicBoolean _update_group_is_scheduled = new AtomicBoolean(false); + private static final long UPDATE_INTERVAL = 1000 * 4; + private boolean recheckPlayerState = false; // 是否需要重新检查玩家状态(发光、飞行) + public final Map NextTimeAllowTeleport = new java.util.HashMap<>(); + + private Map> residence_data = null; + + private final Map map_player_using_group_title_id = new HashMap<>(); + + 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 + private Integer section_origin_x = 0; + private Integer section_origin_z = 0; + + public DominionDTO getLocInDominionDTO(@NotNull Location loc) { + try (AutoTimer ignored = new AutoTimer(Dominion.config.TimerEnabled())) { + 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(@NotNull Location loc) { + return getNodes(loc.getWorld().getUID(), loc.getBlockX(), loc.getBlockZ()); + } + + 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 >= section_origin_x && z >= section_origin_z) { + if (world_dominion_tree_sector_a == null) return null; + return world_dominion_tree_sector_a.get(world); + } + if (x <= section_origin_x && z >= section_origin_z) { + if (world_dominion_tree_sector_b == null) return null; + return world_dominion_tree_sector_b.get(world); + } + if (x >= section_origin_x) { + if (world_dominion_tree_sector_c == null) return null; + return world_dominion_tree_sector_c.get(world); + } + if (world_dominion_tree_sector_d == null) return null; + return world_dominion_tree_sector_d.get(world); + } + + public CompletableFuture initAsync(List dominions) { + return CompletableFuture.runAsync(() -> init(dominions)); + } + + + private void init(List dominions) { + try (AutoTimer ignored = new AutoTimer(Dominion.config.TimerEnabled())) { + 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<>(); + + // 根据所有领地的最大最小坐标计算象限中心点 + + int max_x = dominions.stream().mapToInt(DominionDTO::getX1).max().orElse(0); + int min_x = dominions.stream().mapToInt(DominionDTO::getX2).min().orElse(0); + int max_z = dominions.stream().mapToInt(DominionDTO::getZ1).max().orElse(0); + int min_z = dominions.stream().mapToInt(DominionDTO::getZ2).min().orElse(0); + section_origin_x = (max_x + min_x) / 2; + section_origin_z = (max_z + min_z) / 2; + XLogger.debug("Cache init section origin: %d, %d", section_origin_x, section_origin_z); + - MemberDTO getMember(UUID player_uuid, DominionDTO dominion); + for (DominionDTO d : dominions) { + // 对每个世界的领地进行四个象限的划分 + 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() >= section_origin_x && d.getZ1() >= section_origin_z) { + world_dominions_sector_a.get(d.getWorldUid()).add(d); + } else if (d.getX1() <= section_origin_x && d.getZ1() >= section_origin_z) { + if (d.getX2() >= section_origin_x) { + 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.getWorldUid()).add(d); + } + } else if (d.getX1() >= section_origin_x && d.getZ1() <= section_origin_z) { + if (d.getZ2() >= section_origin_z) { + 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.getWorldUid()).add(d); + } + } else { + if (d.getX2() >= section_origin_x && d.getZ2() >= section_origin_z) { + 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() >= section_origin_x && d.getZ2() <= section_origin_z) { + world_dominions_sector_c.get(d.getWorldUid()).add(d); + world_dominions_sector_d.get(d.getWorldUid()).add(d); + } else if (d.getZ2() >= section_origin_z && d.getX2() <= section_origin_x) { + 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.getWorldUid()).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())); + } + } + } + } - DominionDTO getDominion(Integer id); + @Override + public @Nullable GroupDTO getPlayerUsingGroupTitle(@NotNull UUID uuid) { + if (!Dominion.config.getGroupTitleEnable()) { + return null; + } + if (map_player_using_group_title_id.containsKey(uuid)) { + return getGroup(map_player_using_group_title_id.get(uuid)); + } + return null; + } - @Nullable GroupDTO getPlayerUsingGroupTitle(UUID uuid); + public void updatePlayerUsingGroupTitle(UUID uuid, Integer groupId) { + map_player_using_group_title_id.put(uuid, groupId); + } } diff --git a/core/src/main/java/cn/lunadeer/dominion/CacheImpl.java b/core/src/main/java/cn/lunadeer/dominion/CacheImpl.java deleted file mode 100644 index cbc58454..00000000 --- a/core/src/main/java/cn/lunadeer/dominion/CacheImpl.java +++ /dev/null @@ -1,597 +0,0 @@ -package cn.lunadeer.dominion; - -import cn.lunadeer.dominion.dtos.*; -import cn.lunadeer.dominion.utils.MessageDisplay; -import cn.lunadeer.dominion.utils.Particle; -import cn.lunadeer.dominion.utils.ResMigration; -import cn.lunadeer.dominion.utils.map.MapRender; -import cn.lunadeer.minecraftpluginutils.AutoTimer; -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; - -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.getLocInDominionNode; -import static cn.lunadeer.dominion.DominionNode.isInDominion; - -public class CacheImpl implements Cache { - - public CacheImpl() { - player_current_dominion_id = new HashMap<>(); - loadDominions(); - loadMembers(); - loadGroups(); - } - - /** - * 从数据库加载所有领地 - * 如果idToLoad为null,则加载所有领地 - * - * @param idToLoad 领地ID - */ - public void loadDominions(Integer idToLoad) { - if (_last_update_dominion.get() + UPDATE_INTERVAL < System.currentTimeMillis()) { - XLogger.debug("run loadDominionsExecution directly"); - loadDominionsExecution(idToLoad); - } else { - if (_update_dominion_is_scheduled.get()) return; - XLogger.debug("schedule loadDominionsExecution"); - _update_dominion_is_scheduled.set(true); - long delay_tick = (UPDATE_INTERVAL - (System.currentTimeMillis() - _last_update_dominion.get())) / 1000 * 20L; - Scheduler.runTaskLaterAsync(() -> { - XLogger.debug("run loadDominionsExecution scheduled"); - loadDominionsExecution(idToLoad); - _update_dominion_is_scheduled.set(false); - }, - delay_tick); - } - } - - public void loadDominions() { - loadDominions(null); - } - - private void loadDominionsExecution(Integer idToLoad) { - Scheduler.runTaskAsync(() -> { - long start = System.currentTimeMillis(); - int count = 0; - if (idToLoad == null) { - id_dominions = new ConcurrentHashMap<>(); - dominion_children = new ConcurrentHashMap<>(); - - List dominions = DominionDTO.selectAll(); - CompletableFuture res = dominion_trees.initAsync(dominions); - count = dominions.size(); - - for (DominionDTO d : dominions) { - 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()); - } - - res.join(); // 等待树的构建完成 - } else { - DominionDTO dominion = DominionDTO.select(idToLoad); - if (dominion == null && id_dominions.containsKey(idToLoad)) { - id_dominions.remove(idToLoad); - } else if (dominion != null) { - id_dominions.put(idToLoad, dominion); - count = 1; - } - } - MapRender.render(); - recheckPlayerState = true; - _last_update_dominion.set(System.currentTimeMillis()); - XLogger.debug("loadDominionsExecution cost: %d ms for %d dominions" - , System.currentTimeMillis() - start, count); - }); - } - - /** - * 从数据库加载所有玩家特权 - * 如果player_uuid为null,则加载所有玩家的特权 - * - * @param player_uuid 玩家UUID - */ - public void loadMembers(UUID player_uuid) { - if (_last_update_member.get() + UPDATE_INTERVAL < System.currentTimeMillis()) { - XLogger.debug("run loadMembersExecution directly"); - loadMembersExecution(player_uuid); - } else { - if (_update_member_is_scheduled.get()) return; - XLogger.debug("schedule loadMembersExecution"); - _update_member_is_scheduled.set(true); - long delay_tick = (UPDATE_INTERVAL - (System.currentTimeMillis() - _last_update_member.get())) / 1000 * 20L; - Scheduler.runTaskLaterAsync(() -> { - XLogger.debug("run loadMembersExecution scheduled"); - loadMembersExecution(player_uuid); - _update_member_is_scheduled.set(false); - }, - delay_tick); - } - } - - public void loadMembers() { - loadMembers(null); - } - - private void loadMembersExecution(UUID player_to_update) { - Scheduler.runTaskAsync(() -> { - long start = System.currentTimeMillis(); - List all_privileges; - if (player_to_update == null) { - all_privileges = MemberDTO.selectAll(); - player_uuid_to_member = new ConcurrentHashMap<>(); - } else { - all_privileges = MemberDTO.selectAll(player_to_update); - if (!player_uuid_to_member.containsKey(player_to_update)) { - player_uuid_to_member.put(player_to_update, new ConcurrentHashMap<>()); - } - player_uuid_to_member.get(player_to_update).clear(); - } - for (MemberDTO privilege : all_privileges) { - UUID player_uuid = privilege.getPlayerUUID(); - if (!player_uuid_to_member.containsKey(player_uuid)) { - player_uuid_to_member.put(player_uuid, new ConcurrentHashMap<>()); - } - player_uuid_to_member.get(player_uuid).put(privilege.getDomID(), privilege); - } - recheckPlayerState = true; - _last_update_member.set(System.currentTimeMillis()); - XLogger.debug("loadMembersExecution cost: %d ms for %d privileges" - , System.currentTimeMillis() - start, all_privileges.size()); - }); - } - - public void loadGroups() { - loadGroups(null); - } - - public void loadGroups(Integer groupId) { - if (_last_update_group.get() + UPDATE_INTERVAL < System.currentTimeMillis()) { - XLogger.debug("run loadGroupsExecution directly"); - loadGroupExecution(groupId); - } else { - if (_update_group_is_scheduled.get()) return; - XLogger.debug("schedule loadGroupsExecution"); - _update_group_is_scheduled.set(true); - long delay_tick = (UPDATE_INTERVAL - (System.currentTimeMillis() - _last_update_group.get())) / 1000 * 20L; - Scheduler.runTaskLaterAsync(() -> { - XLogger.debug("run loadGroupsExecution scheduled"); - loadGroupExecution(groupId); - _update_group_is_scheduled.set(false); - }, - delay_tick); - } - } - - private void loadGroupExecution(Integer groupId) { - Scheduler.runTaskAsync(() -> { - long start = System.currentTimeMillis(); - if (groupId == null) { - id_groups = new ConcurrentHashMap<>(); - List groups = GroupDTO.selectAll(); - List players = PlayerDTO.all(); - for (GroupDTO group : groups) { - id_groups.put(group.getId(), group); - } - for (PlayerDTO player : players) { - map_player_using_group_title_id.put(player.getUuid(), player.getUsingGroupTitleID()); - } - } else { - GroupDTO group = GroupDTO.select(groupId); - if (group == null && id_groups.containsKey(groupId)) { - id_groups.remove(groupId); - } else if (group != null) { - id_groups.put(groupId, group); - } - } - recheckPlayerState = true; - _last_update_group.set(System.currentTimeMillis()); - XLogger.debug("loadGroupsExecution cost: %d ms", System.currentTimeMillis() - start); - }); - } - - @Override - public DominionDTO getPlayerCurrentDominion(Player player) { - try (AutoTimer ignored = new AutoTimer(Dominion.config.TimerEnabled())) { - Integer last_in_dom_id = player_current_dominion_id.get(player.getUniqueId()); - DominionDTO last_dominion = null; - if (last_in_dom_id != null) { - last_dominion = id_dominions.get(last_in_dom_id); - } - if (isInDominion(last_dominion, player.getLocation())) { - if (dominion_children.get(last_in_dom_id) == null || dominion_children.get(last_in_dom_id).isEmpty()) { - // 如果玩家仍在领地内,且领地没有子领地,则直接返回 - if (recheckPlayerState) { - lightOrNot(player, last_dominion); - flyOrNot(player, last_dominion); - recheckPlayerState = false; - } - return last_dominion; - } - } - 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) { - return last_dominion; - } - if (last_dom_id != -1) { - MessageDisplay.show(player, Dominion.config.getMessageDisplayJoinLeave(), last_dominion.getLeaveMessage()); - } - if (current_dom_id != -1) { - MessageDisplay.show(player, Dominion.config.getMessageDisplayJoinLeave(), current_dominion.getJoinMessage()); - } - - lightOrNot(player, current_dominion); // 发光检查 - flyOrNot(player, current_dominion); // 飞行检查 - if (current_dominion == null) { - player_current_dominion_id.put(player.getUniqueId(), null); - return null; - } - player_current_dominion_id.put(player.getUniqueId(), current_dominion.getId()); - // show border - if (current_dominion.getFlagValue(Flag.SHOW_BORDER)) { - Particle.showBorder(player, current_dominion); - } - return current_dominion; - } - } - - @Override - public DominionDTO getDominionByLoc(Location loc) { - return dominion_trees.getLocInDominionDTO(loc); - } - - /** - * 玩家退出时调用 用于清除玩家当前所在领地 - * 会将玩家当前所在领地设置为null - * 这样当玩家下次进入领地时,会重新检查玩家所在位置 - * - * @param player 玩家 - */ - public void onPlayerQuit(Player player) { - player_current_dominion_id.put(player.getUniqueId(), null); - } - - /** - * 检查玩家是否需要设置为发光 - * - * @param player 玩家 - * @param dominion 领地 - */ - private void lightOrNot(Player player, DominionDTO dominion) { - if (!Flag.GLOW.getEnable()) { - return; - } - if (dominion == null) { - player.setGlowing(false); - return; - } - MemberDTO privilege = getMember(player, dominion); - if (privilege != null) { - if (privilege.getGroupId() == -1) { - player.setGlowing(privilege.getFlagValue(Flag.GLOW)); - } else { - GroupDTO group = getGroup(privilege.getGroupId()); - if (group != null) { - player.setGlowing(group.getFlagValue(Flag.GLOW)); - } else { - player.setGlowing(dominion.getFlagValue(Flag.GLOW)); - } - } - } else { - player.setGlowing(dominion.getFlagValue(Flag.GLOW)); - } - } - - private void flyOrNot(Player player, DominionDTO dominion) { - for (String flyPN : Dominion.config.getFlyPermissionNodes()) { - if (player.hasPermission(flyPN)) { - return; - } - } - if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) { - return; - } - if (player.isOp() && Dominion.config.getLimitOpBypass()) { - return; - } - if (!Flag.FLY.getEnable()) { - player.setAllowFlight(false); - return; - } - if (dominion == null) { - player.setAllowFlight(false); - return; - } - MemberDTO privilege = getMember(player, dominion); - if (privilege != null) { - if (privilege.getGroupId() == -1) { - player.setAllowFlight(privilege.getFlagValue(Flag.FLY)); - } else { - GroupDTO group = getGroup(privilege.getGroupId()); - if (group != null) { - player.setAllowFlight(group.getFlagValue(Flag.FLY)); - } else { - player.setAllowFlight(dominion.getFlagValue(Flag.FLY)); - } - } - } else { - player.setAllowFlight(dominion.getFlagValue(Flag.FLY)); - } - } - - @Override - public GroupDTO getGroup(Integer id) { - return id_groups.get(id); - } - - @Override - public MemberDTO getMember(Player player, DominionDTO dominion) { - if (!player_uuid_to_member.containsKey(player.getUniqueId())) return null; - return player_uuid_to_member.get(player.getUniqueId()).get(dominion.getId()); - } - - @Override - public MemberDTO getMember(UUID player_uuid, DominionDTO dominion) { - if (!player_uuid_to_member.containsKey(player_uuid)) return null; - return player_uuid_to_member.get(player_uuid).get(dominion.getId()); - } - - public List getBelongGroupsOf(UUID plauer_uuid) { - List groups = new ArrayList<>(); - if (!player_uuid_to_member.containsKey(plauer_uuid)) return groups; - for (MemberDTO member : player_uuid_to_member.get(plauer_uuid).values()) { - if (member.getGroupId() != -1) { - GroupDTO group = getGroup(member.getGroupId()); - if (group != null) { - groups.add(group); - } - } - } - return groups; - } - - @Override - public DominionDTO getDominion(Integer id) { - return id_dominions.get(id); - } - - public int getPlayerDominionCount(UUID player_uuid) { - int count = 0; - for (DominionDTO dominion : id_dominions.values()) { - if (dominion.getOwner().equals(player_uuid)) { - count++; - } - } - return count; - } - - public List getResidenceData(UUID player_uuid) { - if (residence_data == null) { - residence_data = new HashMap<>(); - List residences = ResMigration.extractFromResidence(Dominion.instance); - for (ResMigration.ResidenceNode node : residences) { - if (node == null) { - continue; - } - if (!residence_data.containsKey(node.owner)) { - XLogger.debug("residence_data put %s", node.owner); - residence_data.put(node.owner, new ArrayList<>()); - } - residence_data.get(node.owner).add(node); - } - XLogger.debug("residence_data: %d", residence_data.size()); - } - return residence_data.get(player_uuid); - } - - public List getDominions() { - return new ArrayList<>(id_dominions.values()); - } - - public int getDominionCounts() { - return id_dominions.size(); - } - - public int getMemberCounts() { - int count = 0; - for (Map member : player_uuid_to_member.values()) { - count += member.size(); - } - return count; - } - - public int getGroupCounts() { - return id_groups.size(); - } - - public static CacheImpl instance; - private ConcurrentHashMap id_dominions; - 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; - private final AtomicLong _last_update_dominion = new AtomicLong(0); - private final AtomicBoolean _update_dominion_is_scheduled = new AtomicBoolean(false); - private final AtomicLong _last_update_member = new AtomicLong(0); - private final AtomicBoolean _update_member_is_scheduled = new AtomicBoolean(false); - private final AtomicLong _last_update_group = new AtomicLong(0); - private final AtomicBoolean _update_group_is_scheduled = new AtomicBoolean(false); - private static final long UPDATE_INTERVAL = 1000 * 4; - private boolean recheckPlayerState = false; // 是否需要重新检查玩家状态(发光、飞行) - public final Map NextTimeAllowTeleport = new java.util.HashMap<>(); - - private Map> residence_data = null; - - private final Map map_player_using_group_title_id = new HashMap<>(); - - 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 - private Integer section_origin_x = 0; - private Integer section_origin_z = 0; - - public DominionDTO getLocInDominionDTO(@NotNull Location loc) { - try (AutoTimer ignored = new AutoTimer(Dominion.config.TimerEnabled())) { - 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(@NotNull Location loc) { - return getNodes(loc.getWorld().getUID(), loc.getBlockX(), loc.getBlockZ()); - } - - 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 >= section_origin_x && z >= section_origin_z) { - if (world_dominion_tree_sector_a == null) return null; - return world_dominion_tree_sector_a.get(world); - } - if (x <= section_origin_x && z >= section_origin_z) { - if (world_dominion_tree_sector_b == null) return null; - return world_dominion_tree_sector_b.get(world); - } - if (x >= section_origin_x) { - if (world_dominion_tree_sector_c == null) return null; - return world_dominion_tree_sector_c.get(world); - } - if (world_dominion_tree_sector_d == null) return null; - return world_dominion_tree_sector_d.get(world); - } - - public CompletableFuture initAsync(List dominions) { - return CompletableFuture.runAsync(() -> init(dominions)); - } - - - private void init(List dominions) { - try (AutoTimer ignored = new AutoTimer(Dominion.config.TimerEnabled())) { - 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<>(); - - // 根据所有领地的最大最小坐标计算象限中心点 - - int max_x = dominions.stream().mapToInt(DominionDTO::getX1).max().orElse(0); - int min_x = dominions.stream().mapToInt(DominionDTO::getX2).min().orElse(0); - int max_z = dominions.stream().mapToInt(DominionDTO::getZ1).max().orElse(0); - int min_z = dominions.stream().mapToInt(DominionDTO::getZ2).min().orElse(0); - section_origin_x = (max_x + min_x) / 2; - section_origin_z = (max_z + min_z) / 2; - XLogger.debug("Cache init section origin: %d, %d", section_origin_x, section_origin_z); - - - for (DominionDTO d : dominions) { - // 对每个世界的领地进行四个象限的划分 - 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() >= section_origin_x && d.getZ1() >= section_origin_z) { - world_dominions_sector_a.get(d.getWorldUid()).add(d); - } else if (d.getX1() <= section_origin_x && d.getZ1() >= section_origin_z) { - if (d.getX2() >= section_origin_x) { - 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.getWorldUid()).add(d); - } - } else if (d.getX1() >= section_origin_x && d.getZ1() <= section_origin_z) { - if (d.getZ2() >= section_origin_z) { - 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.getWorldUid()).add(d); - } - } else { - if (d.getX2() >= section_origin_x && d.getZ2() >= section_origin_z) { - 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() >= section_origin_x && d.getZ2() <= section_origin_z) { - world_dominions_sector_c.get(d.getWorldUid()).add(d); - world_dominions_sector_d.get(d.getWorldUid()).add(d); - } else if (d.getZ2() >= section_origin_z && d.getX2() <= section_origin_x) { - 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.getWorldUid()).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())); - } - } - } - } - - @Override - public @Nullable GroupDTO getPlayerUsingGroupTitle(UUID uuid) { - if (!Dominion.config.getGroupTitleEnable()) { - return null; - } - if (map_player_using_group_title_id.containsKey(uuid)) { - return getGroup(map_player_using_group_title_id.get(uuid)); - } - return null; - } - - public void updatePlayerUsingGroupTitle(UUID uuid, Integer groupId) { - map_player_using_group_title_id.put(uuid, groupId); - } -} diff --git a/core/src/main/java/cn/lunadeer/dominion/Dominion.java b/core/src/main/java/cn/lunadeer/dominion/Dominion.java index 1659abbc..f16b1e1d 100644 --- a/core/src/main/java/cn/lunadeer/dominion/Dominion.java +++ b/core/src/main/java/cn/lunadeer/dominion/Dominion.java @@ -19,7 +19,7 @@ import java.util.Objects; import java.util.UUID; -public final class Dominion extends JavaPlugin { +public final class Dominion extends JavaPlugin implements cn.lunadeer.dominion.api.Dominion { @Override public void onEnable() { @@ -38,7 +38,7 @@ public void onEnable() { DatabaseTables.migrate(); new Scheduler(this); AutoClean.run(); - CacheImpl.instance = new CacheImpl(); + Cache.instance = new Cache(); if (config.getGroupTitleEnable()) { if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) { @@ -54,9 +54,9 @@ public void onEnable() { bStatsMetrics metrics = new bStatsMetrics(this, 21445); metrics.addCustomChart(new bStatsMetrics.SimplePie("database", () -> config.getDbType())); - metrics.addCustomChart(new bStatsMetrics.SingleLineChart("dominion_count", () -> CacheImpl.instance.getDominionCounts())); - metrics.addCustomChart(new bStatsMetrics.SingleLineChart("group_count", () -> CacheImpl.instance.getGroupCounts())); - metrics.addCustomChart(new bStatsMetrics.SingleLineChart("member_count", () -> CacheImpl.instance.getMemberCounts())); + metrics.addCustomChart(new bStatsMetrics.SingleLineChart("dominion_count", () -> Cache.instance.getDominionCounts())); + metrics.addCustomChart(new bStatsMetrics.SingleLineChart("group_count", () -> Cache.instance.getGroupCounts())); + metrics.addCustomChart(new bStatsMetrics.SingleLineChart("member_count", () -> Cache.instance.getMemberCounts())); if (config.getCheckUpdate()) { giteaReleaseCheck = new GiteaReleaseCheck(this, diff --git a/core/src/main/java/cn/lunadeer/dominion/DominionNode.java b/core/src/main/java/cn/lunadeer/dominion/DominionNode.java index e095ff48..0cde4bf9 100644 --- a/core/src/main/java/cn/lunadeer/dominion/DominionNode.java +++ b/core/src/main/java/cn/lunadeer/dominion/DominionNode.java @@ -12,7 +12,7 @@ public class DominionNode { private List children = new ArrayList<>(); public DominionDTO getDominion() { - return CacheImpl.instance.getDominion(dominion_id); + return Cache.instance.getDominion(dominion_id); } public List getChildren() { 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 87d8207f..ac9acee3 100644 --- a/core/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java +++ b/core/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.commands; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.controllers.BukkitPlayerOperator; import cn.lunadeer.dominion.controllers.DominionController; @@ -421,7 +421,7 @@ public static void teleportToDominion(CommandSender sender, String[] args) { return; } } else { - GroupDTO groupDTO = CacheImpl.instance.getGroup(privilegeDTO.getGroupId()); + GroupDTO groupDTO = Cache.instance.getGroup(privilegeDTO.getGroupId()); if (privilegeDTO.getGroupId() != -1 && groupDTO != null) { if (!groupDTO.getFlagValue(Flag.TELEPORT)) { Notification.error(sender, Translation.Messages_GroupNoTp); @@ -437,7 +437,7 @@ public static void teleportToDominion(CommandSender sender, String[] args) { } LocalDateTime now = LocalDateTime.now(); - LocalDateTime next_time = CacheImpl.instance.NextTimeAllowTeleport.get(player.getUniqueId()); + LocalDateTime next_time = Cache.instance.NextTimeAllowTeleport.get(player.getUniqueId()); if (next_time != null) { if (now.isBefore(next_time)) { long secs_until_next = now.until(next_time, java.time.temporal.ChronoUnit.SECONDS); @@ -463,7 +463,7 @@ public static void teleportToDominion(CommandSender sender, String[] args) { } }); } - CacheImpl.instance.NextTimeAllowTeleport.put(player.getUniqueId(), now.plusSeconds(Dominion.config.getTpCoolDown())); + Cache.instance.NextTimeAllowTeleport.put(player.getUniqueId(), now.plusSeconds(Dominion.config.getTpCoolDown())); Scheduler.runTaskLater(() -> { Location location = dominionDTO.getTpLocation(); int center_x = (dominionDTO.getX1() + dominionDTO.getX2()) / 2; diff --git a/core/src/main/java/cn/lunadeer/dominion/commands/Migration.java b/core/src/main/java/cn/lunadeer/dominion/commands/Migration.java index cb6ff16f..fd315cd3 100644 --- a/core/src/main/java/cn/lunadeer/dominion/commands/Migration.java +++ b/core/src/main/java/cn/lunadeer/dominion/commands/Migration.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.commands; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.controllers.BukkitPlayerOperator; import cn.lunadeer.dominion.controllers.DominionController; @@ -38,7 +38,7 @@ public static void migrate(CommandSender sender, String[] args) { return; } String resName = args[1]; - List res_data = CacheImpl.instance.getResidenceData(player.getUniqueId()); + List res_data = Cache.instance.getResidenceData(player.getUniqueId()); if (res_data == null) { Notification.error(sender, Translation.Commands_Residence_NoMigrationData); return; 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 f9017856..c7105124 100644 --- a/core/src/main/java/cn/lunadeer/dominion/commands/Operator.java +++ b/core/src/main/java/cn/lunadeer/dominion/commands/Operator.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.commands; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.managers.Translation; @@ -30,17 +30,17 @@ public static void reloadCache(CommandSender sender, String[] args) { } Scheduler.runTaskAsync(() -> { Notification.info(sender, Translation.Commands_Operator_ReloadingDominionCache); - CacheImpl.instance.loadDominions(); + Cache.instance.loadDominions(); Notification.info(sender, Translation.Commands_Operator_ReloadedDominionCache); }); Scheduler.runTaskAsync(() -> { Notification.info(sender, Translation.Commands_Operator_ReloadingPrivilegeCache); - CacheImpl.instance.loadMembers(); + Cache.instance.loadMembers(); Notification.info(sender, Translation.Commands_Operator_ReloadedPrivilegeCache); }); Scheduler.runTaskAsync(() -> { Notification.info(sender, Translation.Commands_Operator_ReloadingGroupCache); - CacheImpl.instance.loadGroups(); + Cache.instance.loadGroups(); Notification.info(sender, Translation.Commands_Operator_ReloadedGroupCache); }); } @@ -52,7 +52,7 @@ public static void exportMca(CommandSender sender, String[] args) { Scheduler.runTaskAsync(() -> { Notification.info(sender, Translation.Commands_Operator_ExportingMCAList); Map> mca_cords = new HashMap<>(); - List doms = CacheImpl.instance.getDominions(); + List doms = Cache.instance.getDominions(); for (DominionDTO dom : doms) { if (dom.getWorld() == null) { continue; diff --git a/core/src/main/java/cn/lunadeer/dominion/commands/Title.java b/core/src/main/java/cn/lunadeer/dominion/commands/Title.java index 9a2873dd..57880b4d 100644 --- a/core/src/main/java/cn/lunadeer/dominion/commands/Title.java +++ b/core/src/main/java/cn/lunadeer/dominion/commands/Title.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.commands; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.GroupDTO; import cn.lunadeer.dominion.dtos.MemberDTO; @@ -36,18 +36,18 @@ public static void use_title(CommandSender sender, String[] args) { player.setUsingGroupTitleID(id); Notification.info(sender, Translation.Commands_Title_RemoveTitleSuccess); } else { - GroupDTO group = CacheImpl.instance.getGroup(id); + GroupDTO group = Cache.instance.getGroup(id); if (group == null) { Notification.error(sender, Translation.Commands_Title_GroupNotExist); return; } - DominionDTO dominion = CacheImpl.instance.getDominion(group.getDomID()); + DominionDTO dominion = Cache.instance.getDominion(group.getDomID()); if (dominion == null) { Notification.error(sender, Translation.Commands_Title_GroupDominionNotExist, group.getName()); return; } if (!dominion.getOwner().equals(bukkit_player.getUniqueId())) { - MemberDTO member = CacheImpl.instance.getMember(bukkit_player, dominion); + MemberDTO member = Cache.instance.getMember(bukkit_player, dominion); if (member == null) { Notification.error(sender, Translation.Commands_Title_NotDominionMember, dominion.getName()); return; 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 0acdf44c..5ebfc764 100644 --- a/core/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java +++ b/core/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.controllers; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.PlayerDTO; @@ -771,7 +771,7 @@ private static boolean depthNotValid(AbstractOperator operator, DominionDTO pare } int level = 0; while (parent_dom.getParentDomId() != -1) { - parent_dom = CacheImpl.instance.getDominion(parent_dom.getParentDomId()); + parent_dom = Cache.instance.getDominion(parent_dom.getParentDomId()); level++; } if (level >= Dominion.config.getLimitDepth(operator.getPlayer())) { @@ -785,7 +785,7 @@ private static boolean amountNotValid(AbstractOperator operator) { if (operator.isOp() && Dominion.config.getLimitOpBypass()) { return false; } - return CacheImpl.instance.getPlayerDominionCount(operator.getUniqueId()) >= Dominion.config.getLimitAmount(operator.getPlayer()) && Dominion.config.getLimitAmount(operator.getPlayer()) != -1; + return Cache.instance.getPlayerDominionCount(operator.getUniqueId()) >= Dominion.config.getLimitAmount(operator.getPlayer()) && Dominion.config.getLimitAmount(operator.getPlayer()) != -1; } private static boolean worldNotValid(AbstractOperator operator, String worldName) { 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 f89e12a8..4a92e2d1 100644 --- a/core/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java +++ b/core/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java @@ -1,7 +1,8 @@ package cn.lunadeer.dominion.dtos; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; +import cn.lunadeer.dominion.api.dtos.Flag; import cn.lunadeer.minecraftpluginutils.XLogger; import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager; import cn.lunadeer.minecraftpluginutils.databse.Field; @@ -17,7 +18,7 @@ import java.sql.SQLException; import java.util.*; -public class DominionDTO { +public class DominionDTO implements cn.lunadeer.dominion.api.dtos.DominionDTO { private static List query(String sql, Object... args) { List dominions = new ArrayList<>(); try (ResultSet rs = DatabaseManager.instance.query(sql, args)) { @@ -45,7 +46,7 @@ private static List getDTOFromRS(ResultSet rs) throws SQLException Integer parentDomId = rs.getInt("parent_dom_id"); String tp_location = rs.getString("tp_location"); Map flags = new HashMap<>(); - for (Flag f : Flag.getDominionFlagsEnabled()) { + for (Flag f : cn.lunadeer.dominion.dtos.Flag.getDominionFlagsEnabled()) { flags.put(f, rs.getBoolean(f.getFlagName())); } String color = rs.getString("color"); @@ -125,11 +126,11 @@ public static DominionDTO insert(DominionDTO dominion) { .field(dominion.parentDomId) .field(dominion.joinMessage).field(dominion.leaveMessage) .field(dominion.tp_location); - for (Flag f : Flag.getDominionFlagsEnabled()) { + for (Flag f : cn.lunadeer.dominion.dtos.Flag.getDominionFlagsEnabled()) { insert.field(new Field(f.getFlagName(), f.getDefaultValue())); } try (ResultSet rs = insert.execute()) { - CacheImpl.instance.loadDominions(); + Cache.instance.loadDominions(); List dominions = getDTOFromRS(rs); if (dominions.isEmpty()) return null; return dominions.getFirst(); @@ -142,7 +143,7 @@ public static DominionDTO insert(DominionDTO dominion) { public static void delete(DominionDTO dominion) { String sql = "DELETE FROM dominion WHERE id = ?;"; query(sql, dominion.getId()); - CacheImpl.instance.loadDominions(); + Cache.instance.loadDominions(); } private DominionDTO(Integer id, UUID owner, String name, UUID world_uid, @@ -216,10 +217,12 @@ public static DominionDTO create(UUID owner, String name, @NotNull World world, // getters and setters + @Override public Integer getId() { return (Integer) id.value; } + @Override public UUID getOwner() { return UUID.fromString((String) owner.value); } @@ -231,7 +234,7 @@ private DominionDTO doUpdate(UpdateRow updateRow) { try (ResultSet rs = updateRow.execute()) { List dominions = getDTOFromRS(rs); if (dominions.isEmpty()) return null; - CacheImpl.instance.loadDominions((Integer) id.value); + Cache.instance.loadDominions((Integer) id.value); return dominions.getFirst(); } catch (SQLException e) { DatabaseManager.handleDatabaseError("DominionDTO.doUpdate ", e, updateRow.toString()); @@ -244,6 +247,7 @@ public DominionDTO setOwner(UUID owner) { return doUpdate(new UpdateRow().field(this.owner)); } + @Override public String getName() { return (String) name.value; } @@ -253,14 +257,17 @@ public DominionDTO setName(String name) { return doUpdate(new UpdateRow().field(this.name)); } + @Override public @Nullable World getWorld() { return Dominion.instance.getServer().getWorld(getWorldUid()); } + @Override public UUID getWorldUid() { return UUID.fromString((String) world_uid.value); } + @Override public Integer getX1() { return (Integer) x1.value; } @@ -270,6 +277,7 @@ public DominionDTO setX1(Integer x1) { return doUpdate(new UpdateRow().field(this.x1)); } + @Override public Integer getY1() { return (Integer) y1.value; } @@ -279,6 +287,7 @@ public DominionDTO setY1(Integer y1) { return doUpdate(new UpdateRow().field(this.y1)); } + @Override public Integer getZ1() { return (Integer) z1.value; } @@ -288,6 +297,7 @@ public DominionDTO setZ1(Integer z1) { return doUpdate(new UpdateRow().field(this.z1)); } + @Override public Integer getX2() { return (Integer) x2.value; } @@ -297,6 +307,7 @@ public DominionDTO setX2(Integer x2) { return doUpdate(new UpdateRow().field(this.x2)); } + @Override public Integer getY2() { return (Integer) y2.value; } @@ -306,6 +317,7 @@ public DominionDTO setY2(Integer y2) { return doUpdate(new UpdateRow().field(this.y2)); } + @Override public Integer getZ2() { return (Integer) z2.value; } @@ -315,30 +327,37 @@ public DominionDTO setZ2(Integer z2) { return doUpdate(new UpdateRow().field(this.z2)); } + @Override public Integer getSquare() { return getWidthX() * getWidthZ(); } + @Override public Integer getVolume() { return getSquare() * getHeight(); } + @Override public Integer getWidthX() { return getX2() - getX1(); } + @Override public Integer getHeight() { return getY2() - getY1(); } + @Override public Integer getWidthZ() { return getZ2() - getZ1(); } + @Override public Integer getParentDomId() { return (Integer) parentDomId.value; } + @Override public String getJoinMessage() { return (String) joinMessage.value; } @@ -348,6 +367,7 @@ public DominionDTO setJoinMessage(String joinMessage) { return doUpdate(new UpdateRow().field(this.joinMessage)); } + @Override public String getLeaveMessage() { return (String) leaveMessage.value; } @@ -357,6 +377,7 @@ public DominionDTO setLeaveMessage(String leaveMessage) { return doUpdate(new UpdateRow().field(this.leaveMessage)); } + @Override public Boolean getFlagValue(Flag flag) { if (!flags.containsKey(flag)) return flag.getDefaultValue(); return flags.get(flag); @@ -388,6 +409,7 @@ public DominionDTO setXYZ(int[] cords) { } + @Override public Location getTpLocation() { if (Objects.equals(tp_location.value, "default")) { return null; @@ -410,10 +432,12 @@ public DominionDTO setTpLocation(Location loc) { return doUpdate(new UpdateRow().field(tp_location)); } + @Override public Location getLocation1() { return new Location(getWorld(), getX1(), getY1(), getZ1()); } + @Override public Location getLocation2() { return new Location(getWorld(), getX2(), getY2(), getZ2()); } @@ -423,22 +447,27 @@ public DominionDTO setColor(String color) { return doUpdate(new UpdateRow().field(this.color)); } + @Override public int getColorR() { return Integer.valueOf(getColor().substring(1, 3), 16); } + @Override public int getColorG() { return Integer.valueOf(getColor().substring(3, 5), 16); } + @Override public int getColorB() { return Integer.valueOf(getColor().substring(5, 7), 16); } + @Override public String getColor() { return (String) color.value; } + @Override public int getColorHex() { return (getColorR() << 16) + (getColorG() << 8) + getColorB(); } diff --git a/core/src/main/java/cn/lunadeer/dominion/dtos/Flag.java b/core/src/main/java/cn/lunadeer/dominion/dtos/Flag.java index f8b54201..8c4642df 100644 --- a/core/src/main/java/cn/lunadeer/dominion/dtos/Flag.java +++ b/core/src/main/java/cn/lunadeer/dominion/dtos/Flag.java @@ -13,7 +13,7 @@ import java.text.Collator; import java.util.*; -public enum Flag { +public enum Flag implements cn.lunadeer.dominion.api.dtos.Flag { ANCHOR("anchor", "重生锚", "是否允许设置/使用重生锚", false, false, true), ANIMAL_KILLING("animal_killing", "对动物造成伤害", "是否允许对动物造成伤害", false, false, true), ANIMAL_SPAWN("animal_spawn", "动物生成(繁殖)", "是否允许动物生成(包括繁殖)", true, true, false), @@ -101,22 +101,27 @@ public enum Flag { this.enable = enable; } + @Override public String getFlagName() { return flag_name; } + @Override public String getDisplayName() { return display_name; } + @Override public String getDescription() { return description; } + @Override public Boolean getDefaultValue() { return default_value; } + @Override public Boolean getEnable() { return enable; } diff --git a/core/src/main/java/cn/lunadeer/dominion/dtos/GroupDTO.java b/core/src/main/java/cn/lunadeer/dominion/dtos/GroupDTO.java index 3dd83dc3..77ba0894 100644 --- a/core/src/main/java/cn/lunadeer/dominion/dtos/GroupDTO.java +++ b/core/src/main/java/cn/lunadeer/dominion/dtos/GroupDTO.java @@ -1,7 +1,8 @@ package cn.lunadeer.dominion.dtos; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; +import cn.lunadeer.dominion.api.dtos.Flag; import cn.lunadeer.minecraftpluginutils.ColorParser; import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager; import cn.lunadeer.minecraftpluginutils.databse.Field; @@ -16,7 +17,7 @@ import java.util.List; import java.util.Map; -public class GroupDTO { +public class GroupDTO implements cn.lunadeer.dominion.api.dtos.GroupDTO { Field id = new Field("id", FieldType.INT); Field domID = new Field("dom_id", FieldType.INT); @@ -26,18 +27,22 @@ public class GroupDTO { private final Map flags = new HashMap<>(); + @Override public Integer getId() { return (Integer) id.value; } + @Override public Integer getDomID() { return (Integer) domID.value; } + @Override public String getName() { return (String) name.value; } + @Override public Component getNameColoredComponent() { String with_pre_suf = "&#ffffff" + Dominion.config.getGroupTitlePrefix() + @@ -47,6 +52,7 @@ public Component getNameColoredComponent() { return ColorParser.getComponentType(with_pre_suf); } + @Override public String getNameColoredBukkit() { String with_pre_suf = "&#ffffff" + Dominion.config.getGroupTitlePrefix() + @@ -56,10 +62,12 @@ public String getNameColoredBukkit() { return ColorParser.getBukkitType(with_pre_suf); } + @Override public Boolean getAdmin() { return (Boolean) admin.value; } + @Override public Boolean getFlagValue(Flag flag) { if (!flags.containsKey(flag)) return flag.getDefaultValue(); return flags.get(flag); @@ -93,13 +101,13 @@ public static GroupDTO create(String name, DominionDTO dominionDTO) { .field(group.name) .field(group.admin) .field(group.name_colored); - for (Flag f : Flag.getPrivilegeFlagsEnabled()) { + for (Flag f : cn.lunadeer.dominion.dtos.Flag.getPrivilegeFlagsEnabled()) { insertRow.field(new Field(f.getFlagName(), dominionDTO.getFlagValue(f))); } try (ResultSet rs = insertRow.execute()) { List groups = getDTOFromRS(rs); if (groups.isEmpty()) return null; - CacheImpl.instance.loadGroups(groups.getFirst().getId()); + Cache.instance.loadGroups(groups.getFirst().getId()); return groups.getFirst(); } catch (Exception e) { DatabaseManager.handleDatabaseError("GroupDTO.create ", e, ""); @@ -114,7 +122,7 @@ public void delete() { public static void delete(Integer id) { String sql = "DELETE FROM dominion_group WHERE id = ?;"; DatabaseManager.instance.query(sql, id); - CacheImpl.instance.loadGroups(id); + Cache.instance.loadGroups(id); List players = MemberDTO.selectByGroupId(id); for (MemberDTO player : players) { player.setGroupId(-1); @@ -150,7 +158,7 @@ private GroupDTO(String name, Integer domID) { this.name.value = ColorParser.getPlainText(name); this.name_colored.value = name; this.admin.value = false; - for (Flag f : Flag.getPrivilegeFlagsEnabled()) { + for (Flag f : cn.lunadeer.dominion.dtos.Flag.getPrivilegeFlagsEnabled()) { flags.put(f, f.getDefaultValue()); } } @@ -170,7 +178,7 @@ private static List getDTOFromRS(ResultSet rs) { try { while (rs.next()) { Map flags = new HashMap<>(); - for (Flag f : Flag.getPrivilegeFlagsEnabled()) { + for (Flag f : cn.lunadeer.dominion.dtos.Flag.getPrivilegeFlagsEnabled()) { flags.put(f, rs.getBoolean(f.getFlagName())); } GroupDTO group = new GroupDTO( @@ -196,7 +204,7 @@ private GroupDTO doUpdate(UpdateRow updateRow) { try (ResultSet rs = updateRow.execute()) { List groups = getDTOFromRS(rs); if (groups.isEmpty()) return null; - CacheImpl.instance.loadGroups((Integer) id.value); + Cache.instance.loadGroups((Integer) id.value); return groups.getFirst(); } catch (Exception e) { DatabaseManager.handleDatabaseError("更新权限组失败: ", e, ""); diff --git a/core/src/main/java/cn/lunadeer/dominion/dtos/MemberDTO.java b/core/src/main/java/cn/lunadeer/dominion/dtos/MemberDTO.java index 561d68b8..a60add6a 100644 --- a/core/src/main/java/cn/lunadeer/dominion/dtos/MemberDTO.java +++ b/core/src/main/java/cn/lunadeer/dominion/dtos/MemberDTO.java @@ -1,6 +1,7 @@ package cn.lunadeer.dominion.dtos; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; +import cn.lunadeer.dominion.api.dtos.Flag; import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager; import cn.lunadeer.minecraftpluginutils.databse.Field; import cn.lunadeer.minecraftpluginutils.databse.FieldType; @@ -10,7 +11,7 @@ import java.sql.ResultSet; import java.util.*; -public class MemberDTO { +public class MemberDTO implements cn.lunadeer.dominion.api.dtos.MemberDTO { private static List query(String sql, Object... params) { List players = new ArrayList<>(); @@ -28,7 +29,7 @@ private static List getDTOFromRS(ResultSet rs) { try { while (rs.next()) { Map flags = new HashMap<>(); - for (Flag f : Flag.getPrivilegeFlagsEnabled()) { + for (Flag f : cn.lunadeer.dominion.dtos.Flag.getPrivilegeFlagsEnabled()) { flags.put(f, rs.getBoolean(f.getFlagName())); } MemberDTO player = new MemberDTO( @@ -54,7 +55,7 @@ private MemberDTO doUpdate(UpdateRow updateRow) { try (ResultSet rs = updateRow.execute()) { List players = getDTOFromRS(rs); if (players.isEmpty()) return null; - CacheImpl.instance.loadMembers(getPlayerUUID()); + Cache.instance.loadMembers(getPlayerUUID()); return players.getFirst(); } catch (Exception e) { DatabaseManager.handleDatabaseError("MemberDTO.doUpdate ", e, ""); @@ -68,11 +69,11 @@ public static MemberDTO insert(MemberDTO player) { .field(player.playerUUID) .field(player.admin) .field(player.domID); - for (Flag f : Flag.getPrivilegeFlagsEnabled()) { + for (Flag f : cn.lunadeer.dominion.dtos.Flag.getPrivilegeFlagsEnabled()) { insertRow.field(new Field(f.getFlagName(), player.getFlagValue(f))); } try (ResultSet rs = insertRow.execute()) { - CacheImpl.instance.loadMembers(player.getPlayerUUID()); + Cache.instance.loadMembers(player.getPlayerUUID()); List players = getDTOFromRS(rs); if (players.isEmpty()) return null; return players.getFirst(); @@ -97,7 +98,7 @@ public static List select(Integer dom_id) { public static void delete(UUID player, Integer domID) { String sql = "DELETE FROM dominion_member WHERE player_uuid = ? AND dom_id = ?;"; query(sql, player.toString(), domID); - CacheImpl.instance.loadMembers(player); + Cache.instance.loadMembers(player); } public static List selectAll() { @@ -126,28 +127,34 @@ public static List selectByDomGroupId(Integer domId, Integer groupId) Field domID = new Field("dom_id", FieldType.INT); Field groupId = new Field("group_id", FieldType.INT); + @Override public Integer getId() { return (Integer) id.value; } + @Override public UUID getPlayerUUID() { return UUID.fromString((String) playerUUID.value); } + @Override public Boolean getAdmin() { return (Boolean) admin.value; } + @Override public Integer getDomID() { return (Integer) domID.value; } + @Override public Integer getGroupId() { return (Integer) groupId.value; } private final Map flags = new HashMap<>(); + @Override public Boolean getFlagValue(Flag flag) { if (!flags.containsKey(flag)) return flag.getDefaultValue(); return flags.get(flag); @@ -175,7 +182,7 @@ public MemberDTO setGroupId(Integer groupId) { public MemberDTO applyTemplate(PrivilegeTemplateDTO template) { this.admin.value = template.getAdmin(); UpdateRow updateRow = new UpdateRow().field(admin); - for (Flag f : Flag.getPrivilegeFlagsEnabled()) { + for (Flag f : cn.lunadeer.dominion.dtos.Flag.getPrivilegeFlagsEnabled()) { this.flags.put(f, template.getFlagValue(f)); updateRow.field(new Field(f.getFlagName(), template.getFlagValue(f))); } @@ -196,7 +203,7 @@ public MemberDTO(UUID playerUUID, DominionDTO dom) { this.playerUUID.value = playerUUID.toString(); this.admin.value = false; this.domID.value = dom.getId(); - for (Flag f : Flag.getPrivilegeFlagsEnabled()) { + for (Flag f : cn.lunadeer.dominion.dtos.Flag.getPrivilegeFlagsEnabled()) { this.flags.put(f, dom.getFlagValue(f)); } } diff --git a/core/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java b/core/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java index 91071f64..d1958994 100644 --- a/core/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java +++ b/core/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.dtos; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager; import cn.lunadeer.minecraftpluginutils.databse.Field; import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow; @@ -194,7 +194,7 @@ public Integer getUsingGroupTitleID() { public void setUsingGroupTitleID(Integer usingGroupTitleID) { this.using_group_title_id = usingGroupTitleID; update(this); - CacheImpl.instance.updatePlayerUsingGroupTitle(uuid, usingGroupTitleID); + Cache.instance.updatePlayerUsingGroupTitle(uuid, usingGroupTitleID); } private Integer id; diff --git a/core/src/main/java/cn/lunadeer/dominion/dtos/PrivilegeTemplateDTO.java b/core/src/main/java/cn/lunadeer/dominion/dtos/PrivilegeTemplateDTO.java index 8eed934b..fe1d190d 100644 --- a/core/src/main/java/cn/lunadeer/dominion/dtos/PrivilegeTemplateDTO.java +++ b/core/src/main/java/cn/lunadeer/dominion/dtos/PrivilegeTemplateDTO.java @@ -1,5 +1,6 @@ package cn.lunadeer.dominion.dtos; +import cn.lunadeer.dominion.api.dtos.Flag; import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager; import cn.lunadeer.minecraftpluginutils.databse.Field; import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow; @@ -8,7 +9,7 @@ import java.sql.ResultSet; import java.util.*; -public class PrivilegeTemplateDTO { +public class PrivilegeTemplateDTO implements cn.lunadeer.dominion.api.dtos.PrivilegeTemplateDTO { private static List query(String sql, Object... params) { List templates = new ArrayList<>(); @@ -26,7 +27,7 @@ private static List getDTOFromRS(ResultSet rs) { try { while (rs.next()) { Map flags = new HashMap<>(); - for (Flag f : Flag.getPrivilegeFlagsEnabled()) { + for (Flag f : cn.lunadeer.dominion.dtos.Flag.getPrivilegeFlagsEnabled()) { flags.put(f, rs.getBoolean(f.getFlagName())); } PrivilegeTemplateDTO template = new PrivilegeTemplateDTO( @@ -108,22 +109,27 @@ private PrivilegeTemplateDTO(Integer id, UUID creator, String name, Boolean admi private final Map flags = new HashMap<>(); + @Override public Integer getId() { return id; } + @Override public UUID getCreator() { return creator; } + @Override public String getName() { return name; } + @Override public Boolean getAdmin() { return admin; } + @Override public Boolean getFlagValue(Flag flag) { if (!flags.containsKey(flag)) return flag.getDefaultValue(); return flags.get(flag); diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/PlaceHolderApi.java b/core/src/main/java/cn/lunadeer/dominion/managers/PlaceHolderApi.java index acf3339b..0813ba90 100644 --- a/core/src/main/java/cn/lunadeer/dominion/managers/PlaceHolderApi.java +++ b/core/src/main/java/cn/lunadeer/dominion/managers/PlaceHolderApi.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.managers; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.GroupDTO; import cn.lunadeer.minecraftpluginutils.XLogger; @@ -25,14 +25,14 @@ public PlaceHolderApi(JavaPlugin plugin) { @Override public String onPlaceholderRequest(Player bukkitPlayer, @NotNull String params) { if (params.equalsIgnoreCase("group_title")) { - GroupDTO group = CacheImpl.instance.getPlayerUsingGroupTitle(bukkitPlayer.getUniqueId()); + GroupDTO group = Cache.instance.getPlayerUsingGroupTitle(bukkitPlayer.getUniqueId()); if (group == null) { return ""; } return group.getNameColoredBukkit(); } if (params.equalsIgnoreCase("current_dominion")) { - DominionDTO dominion = CacheImpl.instance.getDominionByLoc(bukkitPlayer.getLocation()); + DominionDTO dominion = Cache.instance.getDominionByLoc(bukkitPlayer.getLocation()); if (dominion == null) { return ""; } diff --git a/core/src/main/java/cn/lunadeer/dominion/uis/tuis/MigrateList.java b/core/src/main/java/cn/lunadeer/dominion/uis/tuis/MigrateList.java index 3a045ea6..0212b8e9 100644 --- a/core/src/main/java/cn/lunadeer/dominion/uis/tuis/MigrateList.java +++ b/core/src/main/java/cn/lunadeer/dominion/uis/tuis/MigrateList.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.uis.tuis; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.managers.Translation; import cn.lunadeer.dominion.utils.ResMigration; @@ -35,7 +35,7 @@ public static void show(CommandSender sender, String[] args) { view.title(Translation.TUI_Migrate_Title); view.navigator(Line.create().append(Button.create(Translation.TUI_Navigation_Menu).setExecuteCommand("/dominion menu").build()).append(Translation.TUI_Navigation_MigrateList)); - List res_data = CacheImpl.instance.getResidenceData(player.getUniqueId()); + List res_data = Cache.instance.getResidenceData(player.getUniqueId()); if (res_data == null) { view.add(Line.create().append(Translation.TUI_Migrate_NoData)); diff --git a/core/src/main/java/cn/lunadeer/dominion/uis/tuis/TitleList.java b/core/src/main/java/cn/lunadeer/dominion/uis/tuis/TitleList.java index 2393be86..e41e1f9e 100644 --- a/core/src/main/java/cn/lunadeer/dominion/uis/tuis/TitleList.java +++ b/core/src/main/java/cn/lunadeer/dominion/uis/tuis/TitleList.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.uis.tuis; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.GroupDTO; import cn.lunadeer.dominion.managers.Translation; @@ -30,8 +30,8 @@ public static void show(CommandSender sender, String[] args) { view.title(Translation.TUI_TitleList_Title); view.navigator(Line.create().append(Button.create(Translation.TUI_Navigation_Menu).setExecuteCommand("/dominion menu").build()).append(Translation.TUI_Navigation_TitleList)); - List groups = CacheImpl.instance.getBelongGroupsOf(player.getUniqueId()); - GroupDTO using = CacheImpl.instance.getPlayerUsingGroupTitle(player.getUniqueId()); + List groups = Cache.instance.getBelongGroupsOf(player.getUniqueId()); + GroupDTO using = Cache.instance.getPlayerUsingGroupTitle(player.getUniqueId()); // 将其拥有的所有领地的权限组称号都加入列表 - 领地所有者可以使用其领地的任意权限组称号 List dominions = DominionDTO.selectByOwner(player.getUniqueId()); @@ -41,7 +41,7 @@ public static void show(CommandSender sender, String[] args) { } for (GroupDTO group : groups) { - DominionDTO dominion = CacheImpl.instance.getDominion(group.getDomID()); + DominionDTO dominion = Cache.instance.getDominion(group.getDomID()); Line line = Line.create(); if (using != null && using.getId().equals(group.getId())) { line.append(Button.createRed(Translation.TUI_TitleList_RemoveButton).setExecuteCommand("/dominion use_title -1").build()); diff --git a/core/src/main/java/cn/lunadeer/dominion/uis/tuis/dominion/manage/member/MemberList.java b/core/src/main/java/cn/lunadeer/dominion/uis/tuis/dominion/manage/member/MemberList.java index 35f37dc7..cd98daaf 100644 --- a/core/src/main/java/cn/lunadeer/dominion/uis/tuis/dominion/manage/member/MemberList.java +++ b/core/src/main/java/cn/lunadeer/dominion/uis/tuis/dominion/manage/member/MemberList.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.uis.tuis.dominion.manage.member; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.*; import cn.lunadeer.dominion.managers.Translation; import cn.lunadeer.minecraftpluginutils.Notification; @@ -60,7 +60,7 @@ public static void show(CommandSender sender, String[] args) { for (MemberDTO privilege : privileges) { PlayerDTO p_player = PlayerDTO.select(privilege.getPlayerUUID()); if (p_player == null) continue; - GroupDTO group = CacheImpl.instance.getGroup(privilege.getGroupId()); + GroupDTO group = Cache.instance.getGroup(privilege.getGroupId()); Line line = Line.create(); if (group != null) { diff --git a/core/src/main/java/cn/lunadeer/dominion/utils/ControllerUtils.java b/core/src/main/java/cn/lunadeer/dominion/utils/ControllerUtils.java index 168c0961..a4e8ef63 100644 --- a/core/src/main/java/cn/lunadeer/dominion/utils/ControllerUtils.java +++ b/core/src/main/java/cn/lunadeer/dominion/utils/ControllerUtils.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.utils; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.controllers.AbstractOperator; import cn.lunadeer.dominion.dtos.DominionDTO; @@ -42,7 +42,7 @@ public static DominionDTO getPlayerCurrentDominion(AbstractOperator player) { player.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Messages_CannotGetDominionAuto)); return null; } - DominionDTO dominion = CacheImpl.instance.getDominionByLoc(location); + DominionDTO dominion = Cache.instance.getDominionByLoc(location); if (dominion == null) { return null; } diff --git a/core/src/main/java/cn/lunadeer/dominion/utils/EventUtils.java b/core/src/main/java/cn/lunadeer/dominion/utils/EventUtils.java index 5e41da10..2a8c7b22 100644 --- a/core/src/main/java/cn/lunadeer/dominion/utils/EventUtils.java +++ b/core/src/main/java/cn/lunadeer/dominion/utils/EventUtils.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.utils; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; @@ -29,7 +29,7 @@ public static boolean canByPass(Player player, DominionDTO dom, MemberDTO prev) if (prev.getGroupId() == -1) { return prev.getAdmin(); } else { - GroupDTO group = CacheImpl.instance.getGroup(prev.getGroupId()); + GroupDTO group = Cache.instance.getGroup(prev.getGroupId()); return group != null && group.getAdmin(); } } @@ -40,7 +40,7 @@ public static DominionDTO getInvDominion(Player bukkitPlayer, Inventory inv) { if (inv.getLocation() == null) { return null; } else { - return CacheImpl.instance.getDominionByLoc(inv.getLocation()); + return Cache.instance.getDominionByLoc(inv.getLocation()); } } @@ -51,12 +51,12 @@ public static boolean checkFlag(DominionDTO dom, Flag flag, Player player, Cance if (dom == null) { return true; } - MemberDTO prev = CacheImpl.instance.getMember(player, dom); + MemberDTO prev = Cache.instance.getMember(player, dom); if (canByPass(player, dom, prev)) { return true; } if (prev != null) { - GroupDTO group = CacheImpl.instance.getGroup(prev.getGroupId()); + GroupDTO group = Cache.instance.getGroup(prev.getGroupId()); if (prev.getGroupId() != -1 && group != null) { if (group.getFlagValue(flag)) { return true; diff --git a/core/src/main/java/cn/lunadeer/dominion/utils/TuiUtils.java b/core/src/main/java/cn/lunadeer/dominion/utils/TuiUtils.java index 65e4d1ec..9519f956 100644 --- a/core/src/main/java/cn/lunadeer/dominion/utils/TuiUtils.java +++ b/core/src/main/java/cn/lunadeer/dominion/utils/TuiUtils.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.utils; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.MemberDTO; import cn.lunadeer.dominion.managers.Translation; @@ -38,7 +38,7 @@ public static DominionDTO getDominionNameArg_1(Player player, String[] args) { if (args.length >= 2) { return DominionDTO.select(args[1]); } else { - return CacheImpl.instance.getPlayerCurrentDominion(player); + return Cache.instance.getPlayerCurrentDominion(player); } } diff --git a/core/src/main/java/cn/lunadeer/dominion/utils/map/BlueMapConnect.java b/core/src/main/java/cn/lunadeer/dominion/utils/map/BlueMapConnect.java index 9becd587..d10c6afe 100644 --- a/core/src/main/java/cn/lunadeer/dominion/utils/map/BlueMapConnect.java +++ b/core/src/main/java/cn/lunadeer/dominion/utils/map/BlueMapConnect.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.utils.map; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.PlayerDTO; import cn.lunadeer.dominion.managers.Translation; @@ -22,7 +22,7 @@ public static void render() { try { BlueMapAPI.getInstance().ifPresent(api -> { Map> world_dominions = new HashMap<>(); - for (DominionDTO dominion : CacheImpl.instance.getDominions()) { + for (DominionDTO dominion : Cache.instance.getDominions()) { if (dominion.getWorld() == null) { continue; } diff --git a/core/src/main/java/cn/lunadeer/dominion/utils/map/MapRender.java b/core/src/main/java/cn/lunadeer/dominion/utils/map/MapRender.java index 4adeb616..1247d1ff 100644 --- a/core/src/main/java/cn/lunadeer/dominion/utils/map/MapRender.java +++ b/core/src/main/java/cn/lunadeer/dominion/utils/map/MapRender.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.utils.map; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; import java.util.List; @@ -14,7 +14,7 @@ public static void render() { } if (Dominion.config.getDynmap()) { - DynmapConnect.instance.setDominionMarkers(CacheImpl.instance.getDominions()); + DynmapConnect.instance.setDominionMarkers(Cache.instance.getDominions()); } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 6f5ea9f7..eba69c68 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,7 @@ rootProject.name = "Dominion" include( + "api", "core", "v1_20_1", "v1_21" diff --git a/v1_20_1/build.gradle.kts b/v1_20_1/build.gradle.kts index 7e0454c0..afb274ee 100644 --- a/v1_20_1/build.gradle.kts +++ b/v1_20_1/build.gradle.kts @@ -12,6 +12,7 @@ tasks.withType { } dependencies { + compileOnly(project(":api")) compileOnly(project(":core")) compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") } \ No newline at end of file diff --git a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/EnvironmentEvents.java b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/EnvironmentEvents.java index 6e87ed35..803116d9 100644 --- a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/EnvironmentEvents.java +++ b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/EnvironmentEvents.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.events_v1_20_1; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; import cn.lunadeer.minecraftpluginutils.XLogger; @@ -39,7 +39,7 @@ public void onEntityExplode(EntityExplodeEvent event) { } XLogger.debug("blockList" + event.blockList().size()); event.blockList().removeIf(block -> { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); return !checkFlag(dom, Flag.CREEPER_EXPLODE, null); }); } @@ -51,7 +51,7 @@ public void onBedAnchorExplosion(BlockExplodeEvent event) { return; } event.blockList().removeIf(blockState -> { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(blockState.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(blockState.getLocation()); return !checkFlag(dom, Flag.CREEPER_EXPLODE, null); }); } @@ -62,7 +62,7 @@ public void onItemFrameExploded(HangingBreakByEntityEvent event) { if (event.getCause() != HangingBreakEvent.RemoveCause.EXPLOSION) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.CREEPER_EXPLODE, event); } @@ -78,7 +78,7 @@ public void onItemFrameShot(ProjectileHitEvent event) { if (!(hit instanceof Hanging)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(hit.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(hit.getLocation()); checkFlag(dom, Flag.CREEPER_EXPLODE, event); } @@ -91,7 +91,7 @@ public void onArmorStandExploded(EntityDamageByEntityEvent event) { if (isNotExplodeEntity(event.getDamager())) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.CREEPER_EXPLODE, event); } @@ -108,7 +108,7 @@ public void removeSomeOnItemFrameByArrow(HangingBreakByEntityEvent event) { // 玩家破坏由 玩家 break 权限控制 return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getEntity().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.ITEM_FRAME_PROJ_DAMAGE, event); } @@ -128,7 +128,7 @@ public void onDragonBreakBlock(EntityExplodeEvent event) { return; } event.blockList().removeIf(block -> { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); return !checkFlag(dom, Flag.DRAGON_BREAK_BLOCK, null); }); } @@ -140,7 +140,7 @@ public void onFireSpread(BlockIgniteEvent event) { // 如果点燃事件没有玩家触发,那么就是火焰蔓延 return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getBlock().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getBlock().getLocation()); checkFlag(dom, Flag.FIRE_SPREAD, event); } @@ -148,11 +148,11 @@ public void onFireSpread(BlockIgniteEvent event) { public void onLiquidFlowIn(BlockFromToEvent event) { Location from = event.getBlock().getLocation(); Location to = event.getToBlock().getLocation(); - DominionDTO dom_to = CacheImpl.instance.getDominionByLoc(to); + DominionDTO dom_to = Cache.instance.getDominionByLoc(to); if (dom_to == null) { return; } - DominionDTO dom_from = CacheImpl.instance.getDominionByLoc(from); + DominionDTO dom_from = Cache.instance.getDominionByLoc(from); if (dom_from != null) { if (Objects.equals(dom_from.getId(), dom_to.getId())) { return; @@ -167,7 +167,7 @@ public void onMobDropItem(EntityDeathEvent event) { if (entity instanceof Player) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); if (dom == null) { return; } @@ -187,7 +187,7 @@ public void onTntExplode(EntityExplodeEvent event) { return; } event.blockList().removeIf(block -> { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); return !checkFlag(dom, Flag.TNT_EXPLODE, null); }); } @@ -199,7 +199,7 @@ public void onArmorStandExplodedByTnt(EntityDamageByEntityEvent event) { if (harmer.getType() != EntityType.MINECART_TNT && harmer.getType() != EntityType.PRIMED_TNT) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.TNT_EXPLODE, event); } @@ -215,7 +215,7 @@ public void onFarmlandTrample(PlayerInteractEvent event) { if (block.getType() != FARMLAND) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.TRAMPLE, event); } @@ -233,7 +233,7 @@ public void onPressurePlateTriggeredByProjectile(EntityInteractEvent event) { if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.TRIG_PRESSURE_PROJ, event); } @@ -246,7 +246,7 @@ public void onPressurePlateTriggeredByMob(EntityInteractEvent event) { if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.TRIG_PRESSURE_MOB, event); } @@ -259,7 +259,7 @@ public void onPressurePlateTriggeredByDrop(EntityInteractEvent event) { if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.TRIG_PRESSURE_DROP, event); } @@ -269,7 +269,7 @@ public void onWitherSpawn(CreatureSpawnEvent event) { if (entity.getType() != EntityType.WITHER) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.WITHER_SPAWN, event); } @@ -280,7 +280,7 @@ public void onWitherSpawnExplode(EntityExplodeEvent event) { return; } event.blockList().removeIf(block -> { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); return !checkFlag(dom, Flag.WITHER_SPAWN, null); }); } @@ -291,7 +291,7 @@ public void onEnderManSpawn(CreatureSpawnEvent event) { if (entity.getType() != EntityType.ENDERMAN) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.ENDER_MAN, event); } @@ -301,7 +301,7 @@ public void onEnderManEscape(EntityTeleportEvent event) { if (entity.getType() != EntityType.ENDERMAN) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.ENDER_MAN, event); } @@ -311,7 +311,7 @@ public void onMonsterSpawn(CreatureSpawnEvent event) { if (!(entity instanceof Monster)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.MONSTER_SPAWN, event); } @@ -321,7 +321,7 @@ public void onAnimalSpawn(CreatureSpawnEvent event) { if (!(entity instanceof Animals)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.ANIMAL_SPAWN, event); } @@ -331,7 +331,7 @@ public void onVillagerSpawn(CreatureSpawnEvent event) { if (entity.getType() != EntityType.VILLAGER) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.VILLAGER_SPAWN, event); } @@ -339,8 +339,8 @@ public void onVillagerSpawn(CreatureSpawnEvent event) { public void onHopper(InventoryMoveItemEvent event) { // hopper_outside Inventory hopper = event.getDestination(); Inventory inventory = event.getSource(); - DominionDTO hopperDom = CacheImpl.instance.getDominionByLoc(hopper.getLocation()); - DominionDTO inventoryDom = CacheImpl.instance.getDominionByLoc(inventory.getLocation()); + DominionDTO hopperDom = Cache.instance.getDominionByLoc(hopper.getLocation()); + DominionDTO inventoryDom = Cache.instance.getDominionByLoc(inventory.getLocation()); if (hopperDom == null && inventoryDom != null) { checkFlag(inventoryDom, Flag.HOPPER_OUTSIDE, event); } @@ -354,10 +354,10 @@ public void onHopper(InventoryMoveItemEvent event) { // hopper_outside @EventHandler(priority = EventPriority.HIGHEST) public void onBlockPushedByPiston(BlockPistonExtendEvent event) { // piston_outside Block piston = event.getBlock(); - DominionDTO pistonDom = CacheImpl.instance.getDominionByLoc(piston.getLocation()); + DominionDTO pistonDom = Cache.instance.getDominionByLoc(piston.getLocation()); BlockFace direction = event.getDirection(); Block endBlockAfterPush = piston.getRelative(direction, event.getBlocks().size() + 1); - DominionDTO endBlockDom = CacheImpl.instance.getDominionByLoc(endBlockAfterPush.getLocation()); + DominionDTO endBlockDom = Cache.instance.getDominionByLoc(endBlockAfterPush.getLocation()); if (pistonDom != null && endBlockDom == null) { checkFlag(pistonDom, Flag.PISTON_OUTSIDE, event); } @@ -389,8 +389,8 @@ public void onGravityBlockFalling(EntityChangeBlockEvent event) { // gravity_b } fallingBlockMap.remove(entity.getUniqueId()); Location locEnd = block.getLocation(); - DominionDTO domStart = CacheImpl.instance.getDominionByLoc(locStart); - DominionDTO domEnd = CacheImpl.instance.getDominionByLoc(locEnd); + DominionDTO domStart = Cache.instance.getDominionByLoc(locStart); + DominionDTO domEnd = Cache.instance.getDominionByLoc(locEnd); if (domEnd == null) { return; } diff --git a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/PlayerEvents.java b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/PlayerEvents.java index d12c2eae..7e889efd 100644 --- a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/PlayerEvents.java +++ b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/PlayerEvents.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.events_v1_20_1; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; import cn.lunadeer.dominion.dtos.PlayerDTO; @@ -44,7 +44,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { Player bukkitPlayer = event.getPlayer(); - CacheImpl.instance.onPlayerQuit(bukkitPlayer); + Cache.instance.onPlayerQuit(bukkitPlayer); } @EventHandler(priority = EventPriority.HIGHEST) // anchor @@ -53,7 +53,7 @@ public void onRespawnAnchor(PlayerRespawnEvent event) { if (!event.isAnchorSpawn()) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getRespawnLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getRespawnLocation()); if (!checkFlag(dom, Flag.ANCHOR, bukkitPlayer, null)) { if (bukkitPlayer.getBedSpawnLocation() != null) { event.setRespawnLocation(bukkitPlayer.getBedSpawnLocation()); @@ -77,7 +77,7 @@ public void onAnchorInteractive(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.ANCHOR, player, event); } @@ -90,7 +90,7 @@ public void onAnimalKilling(EntityDamageByEntityEvent event) { if (!(event.getEntity() instanceof Animals)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getEntity().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.ANIMAL_KILLING, bukkitPlayer, event); } @@ -102,7 +102,7 @@ public void onAnvilUse(InventoryOpenEvent event) { if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - DominionDTO dom = CacheImpl.instance.getPlayerCurrentDominion(bukkitPlayer); + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); checkFlag(dom, Flag.ANVIL, bukkitPlayer, event); } @@ -118,7 +118,7 @@ public void onBeaconUse(InventoryOpenEvent event) { if (inv.getLocation() == null) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(inv.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(inv.getLocation()); checkFlag(dom, Flag.BEACON, bukkitPlayer, event); } @@ -135,7 +135,7 @@ public void onBedUse(PlayerInteractEvent event) { if (!(Tag.BEDS.isTagged(block.getType()))) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.BED, bukkitPlayer, event); } @@ -147,7 +147,7 @@ public void onBrewUse(InventoryOpenEvent event) { if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - DominionDTO dom = CacheImpl.instance.getPlayerCurrentDominion(bukkitPlayer); + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); checkFlag(dom, Flag.BREW, bukkitPlayer, event); } @@ -196,7 +196,7 @@ public void onArmorStandBreak(EntityDamageByEntityEvent event) { } public static boolean onBreak(Player player, Location location) { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(location); + DominionDTO dom = Cache.instance.getDominionByLoc(location); return checkFlag(dom, Flag.BREAK_BLOCK, player, null); } @@ -213,7 +213,7 @@ public void onButton(PlayerInteractEvent event) { if (!Tag.BUTTONS.isTagged(block.getType())) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.BUTTON, player, event); } @@ -231,7 +231,7 @@ public void eatCake(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.CAKE, player, event); } @@ -241,7 +241,7 @@ private static boolean hasContainerPermission(Player player, Location loc) { if (loc == null) { dom = null; } else { - dom = CacheImpl.instance.getDominionByLoc(loc); + dom = Cache.instance.getDominionByLoc(loc); } return checkFlag(dom, Flag.CONTAINER, player, null); } @@ -367,7 +367,7 @@ public void comparerChange(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getClickedBlock().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getClickedBlock().getLocation()); checkFlag(dom, Flag.COMPARER, player, event); } @@ -384,7 +384,7 @@ public void doorUse(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getClickedBlock().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getClickedBlock().getLocation()); checkFlag(dom, Flag.DOOR, player, event); } @@ -398,7 +398,7 @@ public void touchDragonEdd(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.DRAGON_EGG, player, event); } @@ -409,7 +409,7 @@ public void dyeEvent(PlayerInteractEntityEvent event) { if (!(entity instanceof Colorable)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.DYE, player, event); } @@ -426,7 +426,7 @@ public void onSignOpen(PlayerInteractEvent event) { if (!(Tag.SIGNS.isTagged(block.getType()))) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.EDIT_SIGN, player, event); } @@ -434,7 +434,7 @@ public void onSignOpen(PlayerInteractEvent event) { public void onSignEdit(SignChangeEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.EDIT_SIGN, player, event); } @@ -447,7 +447,7 @@ public void onThrowingEgg(ProjectileHitEvent event) { if (projectile.getType() != EntityType.EGG) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(projectile.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(projectile.getLocation()); checkFlag(dom, Flag.EGG, player, event); } @@ -472,7 +472,7 @@ public void onThrowingEndPearl(ProjectileHitEvent event) { if (projectile.getType() != EntityType.ENDER_PEARL) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(projectile.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(projectile.getLocation()); checkFlag(dom, Flag.ENDER_PEARL, player, event); } @@ -486,7 +486,7 @@ public void onFeedAnimal(PlayerInteractEntityEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getRightClicked().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getRightClicked().getLocation()); checkFlag(dom, Flag.FEED, player, event); } @@ -512,7 +512,7 @@ public void onHarvest(BlockBreakEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.HARVEST, player, event); } @@ -530,7 +530,7 @@ public void honeyInteractive(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.HONEY, player, event); } @@ -541,7 +541,7 @@ public void onHook(PlayerFishEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(caught.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(caught.getLocation()); checkFlag(dom, Flag.HOOK, player, event); } @@ -569,7 +569,7 @@ public void onPlayerIgnite(BlockIgniteEvent event) { if (player == null) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getBlock().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getBlock().getLocation()); checkFlag(dom, Flag.IGNITE, player, event); } @@ -584,7 +584,7 @@ public void onItemFrameInteractive(PlayerInteractEntityEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.ITEM_FRAME_INTERACTIVE, player, event); } @@ -602,7 +602,7 @@ public void onLever(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.LEVER, player, event); } @@ -616,14 +616,14 @@ public void onMonsterKilling(EntityDamageByEntityEvent event) { if (!(entity instanceof Monster)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.MONSTER_KILLING, bukkitPlayer, event); } @EventHandler(priority = EventPriority.HIGHEST) // move public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getPlayerCurrentDominion(player); + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player); if (!checkFlag(dom, Flag.MOVE, player, null)) { Location to = player.getLocation(); int x1 = Math.abs(to.getBlockX() - dom.getX1()); @@ -673,7 +673,7 @@ public void onNoteBlockClicked(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.NOTE_BLOCK, player, event); } @@ -725,7 +725,7 @@ public void placeArmorStand(EntityPlaceEvent event) { } public static boolean onPlace(Player player, Location location) { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(location); + DominionDTO dom = Cache.instance.getDominionByLoc(location); return checkFlag(dom, Flag.PLACE, player, null); } @@ -742,7 +742,7 @@ public void onPressure(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.PRESSURE, player, event); } @@ -751,7 +751,7 @@ public void onRiding(EntityMountEvent event) { if (!(event.getEntity() instanceof Player player)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getMount().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getMount().getLocation()); checkFlag(dom, Flag.RIDING, player, event); } @@ -766,14 +766,14 @@ public void onRepeaterChange(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(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 = CacheImpl.instance.getDominionByLoc(event.getEntity().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.SHEAR, player, event); } @@ -786,7 +786,7 @@ public void onShootArrowSnowball(ProjectileHitEvent event) { if (projectile.getType() == EntityType.ENDER_PEARL || projectile.getType() == EntityType.EGG) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(projectile.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(projectile.getLocation()); checkFlag(dom, Flag.SHOOT, player, event); } @@ -807,7 +807,7 @@ public void onVehicleDestroy(VehicleDestroyEvent event) { if (!(event.getAttacker() instanceof Player player)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getVehicle().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getVehicle().getLocation()); checkFlag(dom, Flag.VEHICLE_DESTROY, player, event); } @@ -821,7 +821,7 @@ public void onVehicleSpawn(EntityPlaceEvent event) { if (!(entity instanceof Vehicle)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.VEHICLE_SPAWN, player, event); } @@ -833,7 +833,7 @@ public void onVillagerKilling(EntityDamageByEntityEvent event) { if (!(event.getEntity() instanceof Villager)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getEntity().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.VILLAGER_KILLING, player, event); } } diff --git a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/special/Paper.java b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/special/Paper.java index a1fe85e0..5fc71229 100644 --- a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/special/Paper.java +++ b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/special/Paper.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.events_v1_20_1.special; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; import com.destroystokyo.paper.event.entity.EntityPathfindEvent; @@ -21,7 +21,7 @@ public void onMonsterPathfinding(EntityPathfindEvent event) { if (!(entity instanceof Monster)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getLoc()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getLoc()); checkFlag(dom, Flag.MONSTER_MOVE, event); } @@ -31,7 +31,7 @@ public void onAnimalPathfinding(EntityPathfindEvent event) { if (!(entity instanceof Animals)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getLoc()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getLoc()); checkFlag(dom, Flag.ANIMAL_MOVE, event); } diff --git a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/special/Spigot.java b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/special/Spigot.java index b09a1173..7d936595 100644 --- a/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/special/Spigot.java +++ b/v1_20_1/src/main/java/cn/lunadeer/dominion/events_v1_20_1/special/Spigot.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.events_v1_20_1.special; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; @@ -33,7 +33,7 @@ public class Spigot implements Listener { } else { Location lastLoc = entityMap.get(entity.getUniqueId()); Location currentLoc = entity.getLocation(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(currentLoc); + DominionDTO dom = Cache.instance.getDominionByLoc(currentLoc); if (!checkFlag(dom, Flag.ANIMAL_MOVE, null) && entity instanceof Animals) { entity.teleport(lastLoc); } else if (!checkFlag(dom, Flag.MONSTER_MOVE, null) && entity instanceof Monster) { diff --git a/v1_21/build.gradle.kts b/v1_21/build.gradle.kts index 7a133f28..aaa4fdb0 100644 --- a/v1_21/build.gradle.kts +++ b/v1_21/build.gradle.kts @@ -12,6 +12,7 @@ tasks.withType { } dependencies { + compileOnly(project(":api")) compileOnly(project(":core")) compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") } \ No newline at end of file diff --git a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/EnvironmentEvents.java b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/EnvironmentEvents.java index 457e37aa..24bc243c 100644 --- a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/EnvironmentEvents.java +++ b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/EnvironmentEvents.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.events_v1_21; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; import cn.lunadeer.minecraftpluginutils.XLogger; @@ -38,7 +38,7 @@ public void onEntityExplode(EntityExplodeEvent event) { } XLogger.debug("blockList" + event.blockList().size()); event.blockList().removeIf(block -> { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); return !checkFlag(dom, Flag.CREEPER_EXPLODE, null); }); } @@ -46,7 +46,7 @@ public void onEntityExplode(EntityExplodeEvent event) { @EventHandler(priority = EventPriority.HIGHEST) // creeper_explode - bed anchor public void onBedAnchorExplosion(BlockExplodeEvent event) { event.blockList().removeIf(blockState -> { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(blockState.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(blockState.getLocation()); return !checkFlag(dom, Flag.CREEPER_EXPLODE, null); }); } @@ -57,7 +57,7 @@ public void onItemFrameExploded(HangingBreakByEntityEvent event) { if (event.getCause() != HangingBreakEvent.RemoveCause.EXPLOSION) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.CREEPER_EXPLODE, event); } @@ -73,7 +73,7 @@ public void onItemFrameShot(ProjectileHitEvent event) { if (!(hit instanceof Hanging)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(hit.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(hit.getLocation()); checkFlag(dom, Flag.CREEPER_EXPLODE, event); } @@ -86,7 +86,7 @@ public void onArmorStandExploded(EntityDamageByEntityEvent event) { if (isNotExplodeEntity(event.getDamager())) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.CREEPER_EXPLODE, event); } @@ -103,7 +103,7 @@ public void removeSomeOnItemFrameByArrow(HangingBreakByEntityEvent event) { // 玩家破坏由 玩家 break 权限控制 return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getEntity().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.ITEM_FRAME_PROJ_DAMAGE, event); } @@ -123,7 +123,7 @@ public void onDragonBreakBlock(EntityExplodeEvent event) { return; } event.blockList().removeIf(block -> { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); return !checkFlag(dom, Flag.DRAGON_BREAK_BLOCK, null); }); } @@ -135,7 +135,7 @@ public void onFireSpread(BlockIgniteEvent event) { // 如果点燃事件没有玩家触发,那么就是火焰蔓延 return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getBlock().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getBlock().getLocation()); checkFlag(dom, Flag.FIRE_SPREAD, event); } @@ -143,11 +143,11 @@ public void onFireSpread(BlockIgniteEvent event) { public void onLiquidFlowIn(BlockFromToEvent event) { Location from = event.getBlock().getLocation(); Location to = event.getToBlock().getLocation(); - DominionDTO dom_to = CacheImpl.instance.getDominionByLoc(to); + DominionDTO dom_to = Cache.instance.getDominionByLoc(to); if (dom_to == null) { return; } - DominionDTO dom_from = CacheImpl.instance.getDominionByLoc(from); + DominionDTO dom_from = Cache.instance.getDominionByLoc(from); if (dom_from != null) { if (Objects.equals(dom_from.getId(), dom_to.getId())) { return; @@ -162,7 +162,7 @@ public void onMobDropItem(EntityDeathEvent event) { if (entity instanceof Player) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); if (dom == null) { return; } @@ -182,7 +182,7 @@ public void onTntExplode(EntityExplodeEvent event) { return; } event.blockList().removeIf(block -> { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); return !checkFlag(dom, Flag.TNT_EXPLODE, null); }); } @@ -194,7 +194,7 @@ public void onArmorStandExplodedByTnt(EntityDamageByEntityEvent event) { if (harmer.getType() != EntityType.TNT_MINECART && harmer.getType() != EntityType.TNT) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.TNT_EXPLODE, event); } @@ -210,7 +210,7 @@ public void onFarmlandTrample(PlayerInteractEvent event) { if (block.getType() != FARMLAND) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.TRAMPLE, event); } @@ -228,7 +228,7 @@ public void onPressurePlateTriggeredByProjectile(EntityInteractEvent event) { if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.TRIG_PRESSURE_PROJ, event); } @@ -241,7 +241,7 @@ public void onPressurePlateTriggeredByMob(EntityInteractEvent event) { if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.TRIG_PRESSURE_MOB, event); } @@ -254,7 +254,7 @@ public void onPressurePlateTriggeredByDrop(EntityInteractEvent event) { if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.TRIG_PRESSURE_DROP, event); } @@ -264,7 +264,7 @@ public void onWitherSpawn(CreatureSpawnEvent event) { if (entity.getType() != EntityType.WITHER) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.WITHER_SPAWN, event); } @@ -275,7 +275,7 @@ public void onWitherSpawnExplode(EntityExplodeEvent event) { return; } event.blockList().removeIf(block -> { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); return !checkFlag(dom, Flag.WITHER_SPAWN, null); }); } @@ -286,7 +286,7 @@ public void onEnderManSpawn(CreatureSpawnEvent event) { if (entity.getType() != EntityType.ENDERMAN) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.ENDER_MAN, event); } @@ -296,7 +296,7 @@ public void onEnderManEscape(EntityTeleportEvent event) { if (entity.getType() != EntityType.ENDERMAN) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.ENDER_MAN, event); } @@ -306,7 +306,7 @@ public void onMonsterSpawn(CreatureSpawnEvent event) { if (!(entity instanceof Monster)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.MONSTER_SPAWN, event); } @@ -316,7 +316,7 @@ public void onAnimalSpawn(CreatureSpawnEvent event) { if (!(entity instanceof Animals)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.ANIMAL_SPAWN, event); } @@ -326,7 +326,7 @@ public void onVillagerSpawn(CreatureSpawnEvent event) { if (entity.getType() != EntityType.VILLAGER) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.VILLAGER_SPAWN, event); } @@ -335,8 +335,8 @@ public void onVillagerSpawn(CreatureSpawnEvent event) { public void onHopper(InventoryMoveItemEvent event) { // hopper_outside Inventory hopper = event.getDestination(); Inventory inventory = event.getSource(); - DominionDTO hopperDom = CacheImpl.instance.getDominionByLoc(hopper.getLocation()); - DominionDTO inventoryDom = CacheImpl.instance.getDominionByLoc(inventory.getLocation()); + DominionDTO hopperDom = Cache.instance.getDominionByLoc(hopper.getLocation()); + DominionDTO inventoryDom = Cache.instance.getDominionByLoc(inventory.getLocation()); if (hopperDom == null && inventoryDom != null) { checkFlag(inventoryDom, Flag.HOPPER_OUTSIDE, event); } @@ -350,10 +350,10 @@ public void onHopper(InventoryMoveItemEvent event) { // hopper_outside @EventHandler(priority = EventPriority.HIGHEST) public void onBlockPushedByPiston(BlockPistonExtendEvent event) { // piston_outside Block piston = event.getBlock(); - DominionDTO pistonDom = CacheImpl.instance.getDominionByLoc(piston.getLocation()); + DominionDTO pistonDom = Cache.instance.getDominionByLoc(piston.getLocation()); BlockFace direction = event.getDirection(); Block endBlockAfterPush = piston.getRelative(direction, event.getBlocks().size() + 1); - DominionDTO endBlockDom = CacheImpl.instance.getDominionByLoc(endBlockAfterPush.getLocation()); + DominionDTO endBlockDom = Cache.instance.getDominionByLoc(endBlockAfterPush.getLocation()); if (pistonDom != null && endBlockDom == null) { checkFlag(pistonDom, Flag.PISTON_OUTSIDE, event); } @@ -385,8 +385,8 @@ public void onGravityBlockFalling(EntityChangeBlockEvent event) { // gravity_b } fallingBlockMap.remove(entity.getUniqueId()); Location locEnd = block.getLocation(); - DominionDTO domStart = CacheImpl.instance.getDominionByLoc(locStart); - DominionDTO domEnd = CacheImpl.instance.getDominionByLoc(locEnd); + DominionDTO domStart = Cache.instance.getDominionByLoc(locStart); + DominionDTO domEnd = Cache.instance.getDominionByLoc(locEnd); if (domEnd == null) { return; } diff --git a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/PlayerEvents.java b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/PlayerEvents.java index d8c380b5..e0d1f1c5 100644 --- a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/PlayerEvents.java +++ b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/PlayerEvents.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.events_v1_21; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; import cn.lunadeer.dominion.dtos.PlayerDTO; @@ -45,7 +45,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { Player bukkitPlayer = event.getPlayer(); - CacheImpl.instance.onPlayerQuit(bukkitPlayer); + Cache.instance.onPlayerQuit(bukkitPlayer); } @EventHandler(priority = EventPriority.HIGHEST) // anchor @@ -54,7 +54,7 @@ public void onRespawnAnchor(PlayerRespawnEvent event) { if (!event.isAnchorSpawn()) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getRespawnLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getRespawnLocation()); if (!checkFlag(dom, Flag.ANCHOR, bukkitPlayer, null)) { if (bukkitPlayer.getRespawnLocation() != null) { event.setRespawnLocation(bukkitPlayer.getRespawnLocation()); @@ -78,7 +78,7 @@ public void onAnchorInteractive(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.ANCHOR, player, event); } @@ -91,7 +91,7 @@ public void onAnimalKilling(EntityDamageByEntityEvent event) { if (!(event.getEntity() instanceof Animals)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getEntity().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.ANIMAL_KILLING, bukkitPlayer, event); } @@ -103,7 +103,7 @@ public void onAnvilUse(InventoryOpenEvent event) { if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - DominionDTO dom = CacheImpl.instance.getPlayerCurrentDominion(bukkitPlayer); + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); checkFlag(dom, Flag.ANVIL, bukkitPlayer, event); } @@ -119,7 +119,7 @@ public void onBeaconUse(InventoryOpenEvent event) { if (inv.getLocation() == null) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(inv.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(inv.getLocation()); checkFlag(dom, Flag.BEACON, bukkitPlayer, event); } @@ -136,7 +136,7 @@ public void onBedUse(PlayerInteractEvent event) { if (!(Tag.BEDS.isTagged(block.getType()))) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.BED, bukkitPlayer, event); } @@ -148,7 +148,7 @@ public void onBrewUse(InventoryOpenEvent event) { if (!(event.getPlayer() instanceof Player bukkitPlayer)) { return; } - DominionDTO dom = CacheImpl.instance.getPlayerCurrentDominion(bukkitPlayer); + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(bukkitPlayer); checkFlag(dom, Flag.BREW, bukkitPlayer, event); } @@ -197,7 +197,7 @@ public void onArmorStandBreak(EntityDamageByEntityEvent event) { } public static boolean onBreak(Player player, Location location) { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(location); + DominionDTO dom = Cache.instance.getDominionByLoc(location); return checkFlag(dom, Flag.BREAK_BLOCK, player, null); } @@ -214,7 +214,7 @@ public void onButton(PlayerInteractEvent event) { if (!Tag.BUTTONS.isTagged(block.getType())) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.BUTTON, player, event); } @@ -232,7 +232,7 @@ public void eatCake(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.CAKE, player, event); } @@ -242,7 +242,7 @@ private static boolean hasContainerPermission(Player player, Location loc) { if (loc == null) { dom = null; } else { - dom = CacheImpl.instance.getDominionByLoc(loc); + dom = Cache.instance.getDominionByLoc(loc); } return checkFlag(dom, Flag.CONTAINER, player, null); } @@ -368,7 +368,7 @@ public void comparerChange(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getClickedBlock().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getClickedBlock().getLocation()); checkFlag(dom, Flag.COMPARER, player, event); } @@ -385,7 +385,7 @@ public void doorUse(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getClickedBlock().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getClickedBlock().getLocation()); checkFlag(dom, Flag.DOOR, player, event); } @@ -399,7 +399,7 @@ public void touchDragonEdd(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.DRAGON_EGG, player, event); } @@ -410,7 +410,7 @@ public void dyeEvent(PlayerInteractEntityEvent event) { if (!(entity instanceof Colorable)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.DYE, player, event); } @@ -427,7 +427,7 @@ public void onSignOpen(PlayerInteractEvent event) { if (!(Tag.SIGNS.isTagged(block.getType()))) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.EDIT_SIGN, player, event); } @@ -435,7 +435,7 @@ public void onSignOpen(PlayerInteractEvent event) { public void onSignEdit(SignChangeEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.EDIT_SIGN, player, event); } @@ -448,7 +448,7 @@ public void onThrowingEgg(ProjectileHitEvent event) { if (projectile.getType() != EntityType.EGG) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(projectile.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(projectile.getLocation()); checkFlag(dom, Flag.EGG, player, event); } @@ -473,7 +473,7 @@ public void onThrowingEndPearl(ProjectileHitEvent event) { if (projectile.getType() != EntityType.ENDER_PEARL) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(projectile.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(projectile.getLocation()); checkFlag(dom, Flag.ENDER_PEARL, player, event); } @@ -487,7 +487,7 @@ public void onFeedAnimal(PlayerInteractEntityEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getRightClicked().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getRightClicked().getLocation()); checkFlag(dom, Flag.FEED, player, event); } @@ -513,7 +513,7 @@ public void onHarvest(BlockBreakEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.HARVEST, player, event); } @@ -531,7 +531,7 @@ public void honeyInteractive(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.HONEY, player, event); } @@ -542,7 +542,7 @@ public void onHook(PlayerFishEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(caught.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(caught.getLocation()); checkFlag(dom, Flag.HOOK, player, event); } @@ -570,7 +570,7 @@ public void onPlayerIgnite(BlockIgniteEvent event) { if (player == null) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getBlock().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getBlock().getLocation()); checkFlag(dom, Flag.IGNITE, player, event); } @@ -585,7 +585,7 @@ public void onItemFrameInteractive(PlayerInteractEntityEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.ITEM_FRAME_INTERACTIVE, player, event); } @@ -603,7 +603,7 @@ public void onLever(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.LEVER, player, event); } @@ -617,14 +617,14 @@ public void onMonsterKilling(EntityDamageByEntityEvent event) { if (!(entity instanceof Monster)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.MONSTER_KILLING, bukkitPlayer, event); } @EventHandler(priority = EventPriority.HIGHEST) // move public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getPlayerCurrentDominion(player); + DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player); if (!checkFlag(dom, Flag.MOVE, player, null)) { Location to = player.getLocation(); int x1 = Math.abs(to.getBlockX() - dom.getX1()); @@ -674,7 +674,7 @@ public void onNoteBlockClicked(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.NOTE_BLOCK, player, event); } @@ -726,7 +726,7 @@ public void placeArmorStand(EntityPlaceEvent event) { } public static boolean onPlace(Player player, Location location) { - DominionDTO dom = CacheImpl.instance.getDominionByLoc(location); + DominionDTO dom = Cache.instance.getDominionByLoc(location); return checkFlag(dom, Flag.PLACE, player, null); } @@ -743,7 +743,7 @@ public void onPressure(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(block.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation()); checkFlag(dom, Flag.PRESSURE, player, event); } @@ -752,7 +752,7 @@ public void onRiding(EntityMountEvent event) { if (!(event.getEntity() instanceof Player player)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getMount().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getMount().getLocation()); checkFlag(dom, Flag.RIDING, player, event); } @@ -767,14 +767,14 @@ public void onRepeaterChange(PlayerInteractEvent event) { return; } Player player = event.getPlayer(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(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 = CacheImpl.instance.getDominionByLoc(event.getEntity().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.SHEAR, player, event); } @@ -787,7 +787,7 @@ public void onShootArrowSnowball(ProjectileHitEvent event) { if (projectile.getType() == EntityType.ENDER_PEARL || projectile.getType() == EntityType.EGG) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(projectile.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(projectile.getLocation()); checkFlag(dom, Flag.SHOOT, player, event); } @@ -800,7 +800,7 @@ public void onWindChargeKnockBack(EntityKnockbackByEntityEvent event) { if (!(windCharge.getShooter() instanceof Player player)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(windCharge.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(windCharge.getLocation()); checkFlag(dom, Flag.SHOOT, player, event); } @@ -821,7 +821,7 @@ public void onVehicleDestroy(VehicleDestroyEvent event) { if (!(event.getAttacker() instanceof Player player)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getVehicle().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getVehicle().getLocation()); checkFlag(dom, Flag.VEHICLE_DESTROY, player, event); } @@ -835,7 +835,7 @@ public void onVehicleSpawn(EntityPlaceEvent event) { if (!(entity instanceof Vehicle)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(entity.getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation()); checkFlag(dom, Flag.VEHICLE_SPAWN, player, event); } @@ -847,7 +847,7 @@ public void onVillagerKilling(EntityDamageByEntityEvent event) { if (!(event.getEntity() instanceof Villager)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getEntity().getLocation()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation()); checkFlag(dom, Flag.VILLAGER_KILLING, player, event); } } diff --git a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/special/Paper.java b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/special/Paper.java index 390a5e4c..8664960b 100644 --- a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/special/Paper.java +++ b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/special/Paper.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.events_v1_21.special; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; import com.destroystokyo.paper.event.entity.EntityPathfindEvent; @@ -21,7 +21,7 @@ public void onMonsterPathfinding(EntityPathfindEvent event) { if (!(entity instanceof Monster)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getLoc()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getLoc()); checkFlag(dom, Flag.MONSTER_MOVE, event); } @@ -31,7 +31,7 @@ public void onAnimalPathfinding(EntityPathfindEvent event) { if (!(entity instanceof Animals)) { return; } - DominionDTO dom = CacheImpl.instance.getDominionByLoc(event.getLoc()); + DominionDTO dom = Cache.instance.getDominionByLoc(event.getLoc()); checkFlag(dom, Flag.ANIMAL_MOVE, event); } diff --git a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/special/Spigot.java b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/special/Spigot.java index 6444a0d4..2fc8f5e0 100644 --- a/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/special/Spigot.java +++ b/v1_21/src/main/java/cn/lunadeer/dominion/events_v1_21/special/Spigot.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.events_v1_21.special; -import cn.lunadeer.dominion.CacheImpl; +import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.Flag; @@ -33,7 +33,7 @@ public class Spigot implements Listener { } else { Location lastLoc = entityMap.get(entity.getUniqueId()); Location currentLoc = entity.getLocation(); - DominionDTO dom = CacheImpl.instance.getDominionByLoc(currentLoc); + DominionDTO dom = Cache.instance.getDominionByLoc(currentLoc); if (!checkFlag(dom, Flag.ANIMAL_MOVE, null) && entity instanceof Animals) { entity.teleport(lastLoc); } else if (!checkFlag(dom, Flag.MONSTER_MOVE, null) && entity instanceof Monster) {