From 08ce2076368e5b67e729f1935e343d715376cc14 Mon Sep 17 00:00:00 2001 From: Dark Arc Date: Wed, 24 Oct 2012 12:51:09 -0400 Subject: [PATCH] Fixed bugs in the PRTreeRegionManager class: * Point would not be returned if the player was at point which exceeded the flat decimal maximum of a region. * The getAplicableRegionIDs method would not return the parents of a region. * All test would fail --- .../managers/PRTreeRegionManager.java | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/protection/managers/PRTreeRegionManager.java b/src/main/java/com/sk89q/worldguard/protection/managers/PRTreeRegionManager.java index 471feca0..83eb7d78 100644 --- a/src/main/java/com/sk89q/worldguard/protection/managers/PRTreeRegionManager.java +++ b/src/main/java/com/sk89q/worldguard/protection/managers/PRTreeRegionManager.java @@ -18,24 +18,18 @@ */ package com.sk89q.worldguard.protection.managers; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.databases.ProtectionDatabase; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import com.sk89q.worldguard.protection.regions.ProtectedRegionMBRConverter; import org.khelekore.prtree.MBR; import org.khelekore.prtree.MBRConverter; import org.khelekore.prtree.PRTree; import org.khelekore.prtree.SimpleMBR; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException; -import com.sk89q.worldguard.protection.databases.ProtectionDatabase; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import com.sk89q.worldguard.protection.regions.ProtectedRegionMBRConverter; +import java.util.*; public class PRTreeRegionManager extends RegionManager { @@ -57,13 +51,11 @@ public class PRTreeRegionManager extends RegionManager { * Construct the manager. * * @param regionLoader The region loader to use - * @throws ProtectionDatabaseException when an error occurs while loading */ - public PRTreeRegionManager(ProtectionDatabase regionLoader) throws ProtectionDatabaseException { + public PRTreeRegionManager(ProtectionDatabase regionLoader) { super(regionLoader); regions = new TreeMap(); tree = new PRTree(converter, BRANCH_FACTOR); - this.load(); } @Override @@ -109,18 +101,21 @@ public void removeRegion(String id) { } } - tree = new PRTree(converter, BRANCH_FACTOR); + tree = new PRTree(converter, BRANCH_FACTOR); tree.load(regions.values()); } @Override public ApplicableRegionSet getApplicableRegions(Vector pt) { - List appRegions = - new ArrayList(); + + // Floor the vector to ensure we get accurate points + pt = pt.floor(); + + List appRegions = new ArrayList(); MBR pointMBR = new SimpleMBR(pt.getX(), pt.getX(), pt.getY(), pt.getY(), pt.getZ(), pt.getZ()); for (ProtectedRegion region : tree.find(pointMBR)) { - if (region.contains(pt)) { + if (region.contains(pt) && !appRegions.contains(region)) { appRegions.add(region); ProtectedRegion parent = region.getParent(); @@ -157,12 +152,26 @@ public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) { @Override public List getApplicableRegionsIDs(Vector pt) { + + // Floor the vector to ensure we get accurate points + pt = pt.floor(); + List applicable = new ArrayList(); MBR pointMBR = new SimpleMBR(pt.getX(), pt.getX(), pt.getY(), pt.getY(), pt.getZ(), pt.getZ()); for (ProtectedRegion region : tree.find(pointMBR)) { - if (region.contains(pt)) { + if (region.contains(pt) && !applicable.contains(region.getId())) { applicable.add(region.getId()); + + ProtectedRegion parent = region.getParent(); + + while (parent != null) { + if (!applicable.contains(parent.getId())) { + applicable.add(parent.getId()); + } + + parent = parent.getParent(); + } } } @@ -208,4 +217,4 @@ public int getRegionCountOfPlayer(LocalPlayer player) { return count; } -} +} \ No newline at end of file