Report overlapping arena regions on load.
This commit introduces an `intersects()` method on ArenaRegion that allows us to check whether two regions intersect. The new method is employed in ArenaMasterImpl during arena load. If an arena's region intersects with any other arena's region (in the same world), we print a warning to the server log. Fixes #367
This commit is contained in:
1 parent
57c26b2faf
commit
77ead3de5c
3 files changed
+45
-1
No files matched your search
@@ -532,6 +532,8 @@ public class ArenaMasterImpl implements ArenaMaster
|
||||
if (arenaNames == null || arenaNames.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Arena> arenas = new ArrayList<>();
|
||||
for (String arenaName : arenaNames) {
|
||||
Arena arena = getArenaWithName(arenaName);
|
||||
if (arena != null) continue;
|
||||
@@ -539,7 +541,31 @@ public class ArenaMasterImpl implements ArenaMaster
|
||||
String arenaWorld = config.getString("arenas." + arenaName + ".settings.world", "");
|
||||
if (!arenaWorld.equals(worldName)) continue;
|
||||
|
||||
loadArena(arenaName);
|
||||
Arena loaded = loadArena(arenaName);
|
||||
if (loaded != null) {
|
||||
arenas.add(loaded);
|
||||
}
|
||||
}
|
||||
|
||||
reportOverlappingRegions(arenas);
|
||||
}
|
||||
|
||||
private void reportOverlappingRegions(List<Arena> arenas) {
|
||||
// If we iterate the upper/lower triangular matrix of the cartesian
|
||||
// product of the arena list, we avoid not only duplicate reports like
|
||||
// "a vs. b and b vs. a", but also "self comparisons" (j = i + 1).
|
||||
for (int i = 0; i < arenas.size(); i++) {
|
||||
Arena a = arenas.get(i);
|
||||
for (int j = i + 1; j < arenas.size(); j++) {
|
||||
Arena b = arenas.get(j);
|
||||
if (a.getRegion().intersects(b.getRegion())) {
|
||||
plugin.getLogger().warning(String.format(
|
||||
"Regions of arenas '%s' and '%s' overlap!",
|
||||
a.configName(),
|
||||
b.configName()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -242,6 +242,23 @@ public class ArenaRegion
|
||||
(y + radius >= p1.getBlockY() && y - radius <= p2.getBlockY()));
|
||||
}
|
||||
|
||||
public boolean intersects(ArenaRegion other) {
|
||||
if (lobbySetup && other.lobbySetup) {
|
||||
if (intersects(l1, l2, other.l1, other.l2)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return intersects(p1, p2, other.p1, other.p2);
|
||||
}
|
||||
|
||||
private boolean intersects(Location a1, Location a2, Location b1, Location b2) {
|
||||
return (
|
||||
b1.getBlockX() <= a2.getBlockX() && a1.getBlockX() <= b2.getBlockX() &&
|
||||
b1.getBlockZ() <= a2.getBlockZ() && a1.getBlockZ() <= b2.getBlockZ() &&
|
||||
b1.getBlockY() <= a2.getBlockY() && a1.getBlockY() <= b2.getBlockY()
|
||||
);
|
||||
}
|
||||
|
||||
// Region expand
|
||||
public void expandUp(int amount) {
|
||||
int x = p2.getBlockX();
|
||||
|
||||
Reference in new issue
Block a user