From 4035f40c6249d5f60da9e6ea1b7efc74bd4afe0f Mon Sep 17 00:00:00 2001 From: RoboMWM Date: Fri, 4 Sep 2020 10:56:37 -0700 Subject: [PATCH] Revert "Refactor overlap check (#934)" (#995) This reverts commit 70b6574fe1e3bad11dede434871e642642a0b65d. --- .../ryanhamshire/GriefPrevention/Claim.java | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/Claim.java b/src/main/java/me/ryanhamshire/GriefPrevention/Claim.java index c7dd02e..196c443 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/Claim.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/Claim.java @@ -779,15 +779,48 @@ public class Claim //used internally to prevent overlaps when creating claims boolean overlaps(Claim otherClaim) { - // For help visualizing test cases, try https://silentmatt.com/rectangle-intersection/ + //NOTE: if trying to understand this makes your head hurt, don't feel bad - it hurts mine too. + //try drawing pictures to visualize test cases. if (!this.lesserBoundaryCorner.getWorld().equals(otherClaim.getLesserBoundaryCorner().getWorld())) return false; - return !(this.getGreaterBoundaryCorner().getX() < otherClaim.getLesserBoundaryCorner().getX() || - this.getLesserBoundaryCorner().getX() > otherClaim.getGreaterBoundaryCorner().getX() || - this.getGreaterBoundaryCorner().getZ() < otherClaim.getLesserBoundaryCorner().getZ() || - this.getLesserBoundaryCorner().getZ() > this.getGreaterBoundaryCorner().getZ()); + //first, check the corners of this claim aren't inside any existing claims + if (otherClaim.contains(this.lesserBoundaryCorner, true, false)) return true; + if (otherClaim.contains(this.greaterBoundaryCorner, true, false)) return true; + if (otherClaim.contains(new Location(this.lesserBoundaryCorner.getWorld(), this.lesserBoundaryCorner.getBlockX(), 0, this.greaterBoundaryCorner.getBlockZ()), true, false)) + return true; + if (otherClaim.contains(new Location(this.lesserBoundaryCorner.getWorld(), this.greaterBoundaryCorner.getBlockX(), 0, this.lesserBoundaryCorner.getBlockZ()), true, false)) + return true; + //verify that no claim's lesser boundary point is inside this new claim, to cover the "existing claim is entirely inside new claim" case + if (this.contains(otherClaim.getLesserBoundaryCorner(), true, false)) return true; + + //verify this claim doesn't band across an existing claim, either horizontally or vertically + if (this.getLesserBoundaryCorner().getBlockZ() <= otherClaim.getGreaterBoundaryCorner().getBlockZ() && + this.getLesserBoundaryCorner().getBlockZ() >= otherClaim.getLesserBoundaryCorner().getBlockZ() && + this.getLesserBoundaryCorner().getBlockX() < otherClaim.getLesserBoundaryCorner().getBlockX() && + this.getGreaterBoundaryCorner().getBlockX() > otherClaim.getGreaterBoundaryCorner().getBlockX()) + return true; + + if (this.getGreaterBoundaryCorner().getBlockZ() <= otherClaim.getGreaterBoundaryCorner().getBlockZ() && + this.getGreaterBoundaryCorner().getBlockZ() >= otherClaim.getLesserBoundaryCorner().getBlockZ() && + this.getLesserBoundaryCorner().getBlockX() < otherClaim.getLesserBoundaryCorner().getBlockX() && + this.getGreaterBoundaryCorner().getBlockX() > otherClaim.getGreaterBoundaryCorner().getBlockX()) + return true; + + if (this.getLesserBoundaryCorner().getBlockX() <= otherClaim.getGreaterBoundaryCorner().getBlockX() && + this.getLesserBoundaryCorner().getBlockX() >= otherClaim.getLesserBoundaryCorner().getBlockX() && + this.getLesserBoundaryCorner().getBlockZ() < otherClaim.getLesserBoundaryCorner().getBlockZ() && + this.getGreaterBoundaryCorner().getBlockZ() > otherClaim.getGreaterBoundaryCorner().getBlockZ()) + return true; + + if (this.getGreaterBoundaryCorner().getBlockX() <= otherClaim.getGreaterBoundaryCorner().getBlockX() && + this.getGreaterBoundaryCorner().getBlockX() >= otherClaim.getLesserBoundaryCorner().getBlockX() && + this.getLesserBoundaryCorner().getBlockZ() < otherClaim.getLesserBoundaryCorner().getBlockZ() && + this.getGreaterBoundaryCorner().getBlockZ() > otherClaim.getGreaterBoundaryCorner().getBlockZ()) + return true; + + return false; } //whether more entities may be added to a claim