From 14ad15b15d9d453c3910833c46bec4f13aca40b2 Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Fri, 3 Jan 2020 01:39:41 +0100 Subject: [PATCH] Cross check arena/lobby regions in `intersects()`. This commit changes how the ArenaRegion `intersects()` method works: - The implicit null checks in the `setup` and `lobbySetup` flags have been replaced with actual null checks inside the auxiliary `intersects()` function. Not only does this make the auxiliary method more robust for potential future use, it also helps tidy up the code a bit. So neat! - The semantics have changed, since `setup` depends on more than just the `p1` and `p2` points. This fixes an (unreported) bug where the check would report a false negative in case an overlapping arena region was defined, but e.g. the arena warp was missing. - Instead of only checking arena vs. arena and lobby vs. lobby, we now also check arena vs. lobby and lobby vs. arena. That is, if the arena region is defined, we check it against both the arena region and lobby region of the other ArenaRegion (if they are defined). Same deal with the lobby region. This should ensure that no combination of overlaps pass through the check. --- changelog.md | 1 + .../MobArena/region/ArenaRegion.java | 22 +++++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/changelog.md b/changelog.md index efbd022..c0eb31f 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,7 @@ These changes will (most likely) be included in the next version. ## [Unreleased] +- The region overlap check now works across both arena and lobby regions, i.e. all four combinations of intersections between two regions (arena-arena, arena-lobby, lobby-arena, and lobby-lobby) are evaluated. - Arenas with missing regions no longer cause errors in the region overlap check. ## [0.104.1] - 2019-12-31 diff --git a/src/main/java/com/garbagemule/MobArena/region/ArenaRegion.java b/src/main/java/com/garbagemule/MobArena/region/ArenaRegion.java index a0b5ad1..8c2cc8b 100644 --- a/src/main/java/com/garbagemule/MobArena/region/ArenaRegion.java +++ b/src/main/java/com/garbagemule/MobArena/region/ArenaRegion.java @@ -243,23 +243,17 @@ public class ArenaRegion } public boolean intersects(ArenaRegion other) { - if (lobbySetup && other.lobbySetup) { - if (intersects(l1, l2, other.l1, other.l2)) { - return true; - } - } - if (setup && other.setup) { - return intersects(p1, p2, other.p1, other.p2); - } - return false; + return intersects(p1, p2, other.p1, other.p2) + || intersects(p1, p2, other.l1, other.l2) + || intersects(l1, l2, other.p1, other.p2) + || intersects(l1, l2, other.l1, other.l2); } 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() - ); + return (a1 != null && a2 != null && b1 != null && b2 != null) + && 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