From 4f394b5668eb22a7c3e515afc87dc25a4f5367e8 Mon Sep 17 00:00:00 2001 From: Darth Android Date: Sun, 19 Aug 2012 13:51:41 -0500 Subject: [PATCH] Update PRTree library to v1.5 Updated PRTreeRegionManager code to support 3D points and regions Changed region manager to PRTreeRegionManager --- pom.xml | 2 +- .../protection/GlobalRegionManager.java | 3 +- .../managers/PRTreeRegionManager.java | 14 ++++---- .../regions/ProtectedRegionMBRConverter.java | 36 +++++++++++++------ 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 870e3b41..bba281e2 100644 --- a/pom.xml +++ b/pom.xml @@ -76,7 +76,7 @@ org.khelekore prtree - 1.4 + 1.5 compile diff --git a/src/main/java/com/sk89q/worldguard/protection/GlobalRegionManager.java b/src/main/java/com/sk89q/worldguard/protection/GlobalRegionManager.java index decd7821..94119464 100644 --- a/src/main/java/com/sk89q/worldguard/protection/GlobalRegionManager.java +++ b/src/main/java/com/sk89q/worldguard/protection/GlobalRegionManager.java @@ -42,6 +42,7 @@ import com.sk89q.worldguard.protection.databases.MySQLDatabase; import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.managers.FlatRegionManager; +import com.sk89q.worldguard.protection.managers.PRTreeRegionManager; import com.sk89q.worldguard.protection.managers.RegionManager; /** @@ -156,7 +157,7 @@ public RegionManager create(World world) { } // Create a manager - RegionManager manager = new FlatRegionManager(database); + RegionManager manager = new PRTreeRegionManager(database); manager.load(); plugin.getLogger().info(manager.getRegions().size() 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 7efc09ec..fe1c3736 100644 --- a/src/main/java/com/sk89q/worldguard/protection/managers/PRTreeRegionManager.java +++ b/src/main/java/com/sk89q/worldguard/protection/managers/PRTreeRegionManager.java @@ -24,8 +24,10 @@ import java.util.Map; import java.util.TreeMap; +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; @@ -115,11 +117,9 @@ public void removeRegion(String id) { public ApplicableRegionSet getApplicableRegions(Vector pt) { List appRegions = new ArrayList(); + MBR pointMBR = new SimpleMBR(pt.getX(), pt.getX(), pt.getY(), pt.getY(), pt.getZ(), pt.getZ()); - int x = pt.getBlockX(); - int z = pt.getBlockZ(); - - for (ProtectedRegion region : tree.find(x, z, x, z)) { + for (ProtectedRegion region : tree.find(pointMBR)) { if (region.contains(pt)) { appRegions.add(region); } @@ -148,11 +148,9 @@ public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) { @Override public List getApplicableRegionsIDs(Vector pt) { List applicable = new ArrayList(); + MBR pointMBR = new SimpleMBR(pt.getX(), pt.getX(), pt.getY(), pt.getY(), pt.getZ(), pt.getZ()); - int x = pt.getBlockX(); - int z = pt.getBlockZ(); - - for (ProtectedRegion region : tree.find(x, z, x, z)) { + for (ProtectedRegion region : tree.find(pointMBR)) { if (region.contains(pt)) { applicable.add(region.getId()); } diff --git a/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegionMBRConverter.java b/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegionMBRConverter.java index 83606f22..b56c76a5 100644 --- a/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegionMBRConverter.java +++ b/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegionMBRConverter.java @@ -22,19 +22,35 @@ import org.khelekore.prtree.MBRConverter; public class ProtectedRegionMBRConverter implements MBRConverter { - public double getMinX(ProtectedRegion t) { - return t.getMinimumPoint().getBlockX(); + + @Override + public int getDimensions() { + return 3; } - public double getMinY(ProtectedRegion t) { - return t.getMinimumPoint().getBlockZ(); + @Override + public double getMax(int dimension, ProtectedRegion region) { + switch (dimension) { + case 0: + return region.getMaximumPoint().getBlockX(); + case 1: + return region.getMaximumPoint().getBlockY(); + case 2: + return region.getMaximumPoint().getBlockZ(); + } + return 0; } - public double getMaxX(ProtectedRegion t) { - return t.getMaximumPoint().getBlockX(); - } - - public double getMaxY(ProtectedRegion t) { - return t.getMaximumPoint().getBlockZ(); + @Override + public double getMin(int dimension, ProtectedRegion region) { + switch (dimension) { + case 0: + return region.getMinimumPoint().getBlockX(); + case 1: + return region.getMinimumPoint().getBlockY(); + case 2: + return region.getMinimumPoint().getBlockZ(); + } + return 0; } }