Update PRTree library to v1.5

Updated PRTreeRegionManager code to support 3D points and regions
Changed region manager to PRTreeRegionManager
This commit is contained in:
Darth Android 2012-08-19 13:51:41 -05:00 committed by sk89q
parent 9834c30e3a
commit 4f394b5668
4 changed files with 35 additions and 20 deletions

View File

@ -76,7 +76,7 @@
<dependency>
<groupId>org.khelekore</groupId>
<artifactId>prtree</artifactId>
<version>1.4</version>
<version>1.5</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -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()

View File

@ -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<ProtectedRegion> appRegions =
new ArrayList<ProtectedRegion>();
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<String> getApplicableRegionsIDs(Vector pt) {
List<String> applicable = new ArrayList<String>();
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());
}

View File

@ -22,19 +22,35 @@
import org.khelekore.prtree.MBRConverter;
public class ProtectedRegionMBRConverter implements MBRConverter<ProtectedRegion> {
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();
@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();
}
public double getMaxY(ProtectedRegion t) {
return t.getMaximumPoint().getBlockZ();
return 0;
}
}