mirror of
https://github.com/ColdeZhang/Dominion.git
synced 2024-12-20 02:19:49 +08:00
优化缓存分区算法,实现了动态分区
This commit is contained in:
parent
fbb0b4a2f9
commit
f11d33b60c
12
.github/ISSUE_TEMPLATE/功能请求.md
vendored
12
.github/ISSUE_TEMPLATE/功能请求.md
vendored
@ -8,13 +8,17 @@ assignees: ''
|
||||
---
|
||||
|
||||
**新功能是否和BUG有关?**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
请描述新功能是否和BUG有关。
|
||||
|
||||
**新功能表述**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
请详细、清晰地描述新功能内容。以及为什么需要这个新功能。
|
||||
|
||||
**新功能实现方案**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
你觉得如何实现这个新功能?
|
||||
|
||||
**补充信息**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
|
||||
如有其他信息,请在此处补充。
|
||||
|
15
.github/ISSUE_TEMPLATE/报告bug.md
vendored
15
.github/ISSUE_TEMPLATE/报告bug.md
vendored
@ -8,10 +8,12 @@ assignees: ''
|
||||
---
|
||||
|
||||
**BUG描述**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
请详细、清晰地描述bug现象。
|
||||
|
||||
**复现方式**
|
||||
Steps to reproduce the behavior:
|
||||
|
||||
Bug复现步骤:
|
||||
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
@ -19,10 +21,12 @@ Steps to reproduce the behavior:
|
||||
4. See error
|
||||
|
||||
**正常情况的表现**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
正常情况下的表现应该是怎样的
|
||||
|
||||
**截图**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
(可选)。
|
||||
|
||||
**运行环境:**
|
||||
|
||||
@ -32,4 +36,5 @@ If applicable, add screenshots to help explain your problem.
|
||||
- 插件版本:
|
||||
|
||||
**补充信息**
|
||||
Add any other context about the problem here.
|
||||
|
||||
如错误日志等。
|
||||
|
@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "cn.lunadeer"
|
||||
version = "2.3.5-beta"
|
||||
version = "2.3.6-beta"
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||
|
@ -468,6 +468,8 @@ public class Cache {
|
||||
private ConcurrentHashMap<UUID, List<DominionNode>> world_dominion_tree_sector_b; // x <= 0, z >= 0
|
||||
private ConcurrentHashMap<UUID, List<DominionNode>> world_dominion_tree_sector_c; // x >= 0, z <= 0
|
||||
private ConcurrentHashMap<UUID, List<DominionNode>> 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())) {
|
||||
@ -489,15 +491,19 @@ public class Cache {
|
||||
}
|
||||
|
||||
public List<DominionNode> getNodes(UUID world, int x, int z) {
|
||||
if (x >= 0 && z >= 0) {
|
||||
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 <= 0 && z >= 0) {
|
||||
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 >= 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -516,6 +522,16 @@ public class Cache {
|
||||
Map<UUID, List<DominionDTO>> world_dominions_sector_b = new HashMap<>();
|
||||
Map<UUID, List<DominionDTO>> world_dominions_sector_c = new HashMap<>();
|
||||
Map<UUID, List<DominionDTO>> 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()) ||
|
||||
@ -527,32 +543,32 @@ public class Cache {
|
||||
world_dominions_sector_c.put(d.getWorldUid(), new ArrayList<>());
|
||||
world_dominions_sector_d.put(d.getWorldUid(), new ArrayList<>());
|
||||
}
|
||||
if (d.getX1() >= 0 && d.getZ1() >= 0) {
|
||||
if (d.getX1() >= section_origin_x && d.getZ1() >= section_origin_z) {
|
||||
world_dominions_sector_a.get(d.getWorldUid()).add(d);
|
||||
} else if (d.getX1() <= 0 && d.getZ1() >= 0) {
|
||||
if (d.getX2() >= 0) {
|
||||
} 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() >= 0 && d.getZ1() <= 0) {
|
||||
if (d.getZ2() >= 0) {
|
||||
} 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() >= 0 && d.getZ2() >= 0) {
|
||||
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() >= 0 && d.getZ2() <= 0) {
|
||||
} 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() >= 0 && d.getX2() <= 0) {
|
||||
} 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 {
|
||||
|
@ -95,7 +95,7 @@ public class PlayerDTO {
|
||||
|
||||
public static void delete(PlayerDTO player) {
|
||||
String sql = "DELETE FROM player_name WHERE uuid = ?;";
|
||||
query(sql, player.getUuid());
|
||||
query(sql, player.getUuid().toString());
|
||||
}
|
||||
|
||||
private static PlayerDTO insert(PlayerDTO player) {
|
||||
|
Loading…
Reference in New Issue
Block a user