From c7b6bd6e0b807c7b6c730971313b50ade351536d Mon Sep 17 00:00:00 2001 From: Moulberry Date: Sun, 14 Apr 2024 11:13:05 +0800 Subject: [PATCH] Fix some WorldGuard regions not being considered --- .../worldguard/WorldGuardIntegrationImpl.java | 72 ++++++++++--------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/moulberry/axiom/integration/worldguard/WorldGuardIntegrationImpl.java b/src/main/java/com/moulberry/axiom/integration/worldguard/WorldGuardIntegrationImpl.java index 2457f4b..3110655 100644 --- a/src/main/java/com/moulberry/axiom/integration/worldguard/WorldGuardIntegrationImpl.java +++ b/src/main/java/com/moulberry/axiom/integration/worldguard/WorldGuardIntegrationImpl.java @@ -17,6 +17,7 @@ import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.*; import org.bukkit.World; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -86,44 +87,14 @@ public class WorldGuardIntegrationImpl { List finalRegions = new ArrayList<>(); - region_loop: for (ProtectedRegion region : regions) { int priority = FlagValueCalculator.getPriorityOf(region); if (priority != lastPriority) { lastPriority = priority; - if (!denyRegions.isEmpty()) { - Box.combineAll(denyRegions); - - boolean finalRegionsWasEmpty = finalRegions.isEmpty(); - - for (Box denyRegion : denyRegions) { - finalRegions.add(new BoxWithBoolean(denyRegion, false)); - - if (denyRegion.completelyOverlaps(sectionBox)) { - if (finalRegionsWasEmpty) { - return SectionPermissionChecker.NONE_ALLOWED; - } else { - break region_loop; - } - } - } - } - if (!allowRegions.isEmpty()) { - Box.combineAll(allowRegions); - - for (Box allowRegion : allowRegions) { - finalRegions.add(new BoxWithBoolean(allowRegion, true)); - - if (allowRegion.completelyOverlaps(sectionBox)) { - if (finalRegions.size() == 1) { - return SectionPermissionChecker.ALL_ALLOWED; - } else { - break region_loop; - } - } - } + if (addRegions(sectionBox, denyRegions, allowRegions, finalRegions)) { + break; } } @@ -164,6 +135,8 @@ public class WorldGuardIntegrationImpl { continue; } + // todo: handle membership + // The BUILD flag is implicitly set on every region where // PASSTHROUGH is not set to ALLOW // todo: handle passthrough @@ -171,9 +144,42 @@ public class WorldGuardIntegrationImpl { // } } - // todo: handle membership + addRegions(sectionBox, denyRegions, allowRegions, finalRegions); return SectionPermissionChecker.fromBoxWithBooleans(finalRegions, Flags.BUILD.getDefault() == StateFlag.State.ALLOW); } + private static boolean addRegions(Box sectionBox, List denyRegions, List allowRegions, List finalRegions) { + List denyRegionsCopy = new ArrayList<>(denyRegions); + denyRegions.clear(); + + List allowRegionsCopy = new ArrayList<>(allowRegions); + allowRegions.clear(); + + if (!denyRegionsCopy.isEmpty()) { + Box.combineAll(denyRegionsCopy); + + for (Box denyRegion : denyRegionsCopy) { + finalRegions.add(new BoxWithBoolean(denyRegion, false)); + + if (denyRegion.completelyOverlaps(sectionBox)) { + return true; + } + } + } + if (!allowRegionsCopy.isEmpty()) { + Box.combineAll(allowRegionsCopy); + + for (Box allowRegion : allowRegionsCopy) { + finalRegions.add(new BoxWithBoolean(allowRegion, true)); + + if (allowRegion.completelyOverlaps(sectionBox)) { + return true; + } + } + } + + return false; + } + }