mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-25 18:47:44 +01:00
Refactored and fixed getIntersectingRegions
This commit is contained in:
parent
4bb967ab4a
commit
27251dda2e
@ -23,6 +23,7 @@
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
|
import com.sk89q.worldedit.BlockVector2D;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
|
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
|
||||||
|
|
||||||
@ -30,16 +31,14 @@ public class GlobalProtectedRegion extends ProtectedRegion {
|
|||||||
|
|
||||||
public GlobalProtectedRegion(String id) {
|
public GlobalProtectedRegion(String id) {
|
||||||
super(id);
|
super(id);
|
||||||
|
min = new BlockVector(0, 0, 0);
|
||||||
|
max = new BlockVector(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public List<BlockVector2D> getPoints() {
|
||||||
public BlockVector getMinimumPoint() {
|
List<BlockVector2D> pts = new ArrayList<BlockVector2D>();
|
||||||
return new BlockVector(0, 0, 0);
|
pts.add(new BlockVector2D(min.getBlockX(),min.getBlockZ()));
|
||||||
}
|
return pts;
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockVector getMaximumPoint() {
|
|
||||||
return new BlockVector(0, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,36 +33,29 @@
|
|||||||
*/
|
*/
|
||||||
public class ProtectedCuboidRegion extends ProtectedRegion {
|
public class ProtectedCuboidRegion extends ProtectedRegion {
|
||||||
|
|
||||||
/**
|
|
||||||
* Store the first point.
|
|
||||||
*/
|
|
||||||
private BlockVector min;
|
|
||||||
/**
|
|
||||||
* Store the second point.
|
|
||||||
*/
|
|
||||||
private BlockVector max;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new instance of this cuboid region.
|
* Construct a new instance of this cuboid region.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @param min
|
* @param pt1
|
||||||
* @param max
|
* @param pt2
|
||||||
*/
|
*/
|
||||||
public ProtectedCuboidRegion(String id, BlockVector min, BlockVector max) {
|
public ProtectedCuboidRegion(String id, BlockVector pt1, BlockVector pt2) {
|
||||||
super(id);
|
super(id);
|
||||||
this.min = min;
|
setMinMaxPoints(pt1, pt2);
|
||||||
this.max = max;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the lower point of the cuboid.
|
* Given any two points, sets the minimum and maximum points
|
||||||
*
|
*
|
||||||
* @return min point
|
* @param pt1
|
||||||
|
* @param pt2
|
||||||
*/
|
*/
|
||||||
@Override
|
private void setMinMaxPoints(BlockVector pt1, BlockVector pt2) {
|
||||||
public BlockVector getMinimumPoint() {
|
List<Vector> points = new ArrayList<Vector>();
|
||||||
return min;
|
points.add(pt1);
|
||||||
|
points.add(pt2);
|
||||||
|
setMinMaxPoints(points);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,17 +64,7 @@ public BlockVector getMinimumPoint() {
|
|||||||
* @param pt
|
* @param pt
|
||||||
*/
|
*/
|
||||||
public void setMinimumPoint(BlockVector pt) {
|
public void setMinimumPoint(BlockVector pt) {
|
||||||
min = pt;
|
setMinMaxPoints(pt, max);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the upper point of the cuboid.
|
|
||||||
*
|
|
||||||
* @return max point
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public BlockVector getMaximumPoint() {
|
|
||||||
return max;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,7 +73,22 @@ public BlockVector getMaximumPoint() {
|
|||||||
* @param pt
|
* @param pt
|
||||||
*/
|
*/
|
||||||
public void setMaximumPoint(BlockVector pt) {
|
public void setMaximumPoint(BlockVector pt) {
|
||||||
max = pt;
|
setMinMaxPoints(min, pt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BlockVector2D> getPoints() {
|
||||||
|
List<BlockVector2D> pts = new ArrayList<BlockVector2D>();
|
||||||
|
int x1 = min.getBlockX();
|
||||||
|
int x2 = max.getBlockX();
|
||||||
|
int z1 = min.getBlockZ();
|
||||||
|
int z2 = max.getBlockZ();
|
||||||
|
|
||||||
|
pts.add(new BlockVector2D(x1, z1));
|
||||||
|
pts.add(new BlockVector2D(x2, z1));
|
||||||
|
pts.add(new BlockVector2D(x1, z2));
|
||||||
|
pts.add(new BlockVector2D(x2, z2));
|
||||||
|
|
||||||
|
return pts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,112 +132,29 @@ public boolean intersectsWith(ProtectedRegion region) throws UnsupportedIntersec
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> regions) throws UnsupportedIntersectionException {
|
public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> regions) throws UnsupportedIntersectionException {
|
||||||
int numRegions = regions.size();
|
|
||||||
List<ProtectedRegion> intersectingRegions = new ArrayList<ProtectedRegion>();
|
List<ProtectedRegion> intersectingRegions = new ArrayList<ProtectedRegion>();
|
||||||
int i, i2, i3;
|
|
||||||
|
|
||||||
for (i = 0; i < numRegions; i++) {
|
for (ProtectedRegion region : regions) {
|
||||||
ProtectedRegion region = regions.get(i);
|
if (!intersectsBoundingBox(region)) continue;
|
||||||
BlockVector rMinPoint = region.getMinimumPoint();
|
|
||||||
BlockVector rMaxPoint = region.getMaximumPoint();
|
|
||||||
|
|
||||||
// Check whether the region is outside the min and max vector
|
|
||||||
if ((rMinPoint.getBlockX() < min.getBlockX() && rMaxPoint.getBlockX() < min.getBlockX())
|
|
||||||
|| (rMinPoint.getBlockX() > max.getBlockX() && rMaxPoint.getBlockX() > max.getBlockX())
|
|
||||||
|| ((rMinPoint.getBlockY() < min.getBlockY() && rMaxPoint.getBlockY() < min.getBlockY())
|
|
||||||
|| (rMinPoint.getBlockY() > max.getBlockY() && rMaxPoint.getBlockY() > max.getBlockY()))
|
|
||||||
|| ((rMinPoint.getBlockZ() < min.getBlockZ() && rMaxPoint.getBlockZ() < min.getBlockZ())
|
|
||||||
|| (rMinPoint.getBlockZ() > max.getBlockZ() && rMaxPoint.getBlockZ() > max.getBlockZ())) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
|
// If both regions are Cuboids and their bounding boxes intersect, they intersect
|
||||||
if (region instanceof ProtectedCuboidRegion) {
|
if (region instanceof ProtectedCuboidRegion) {
|
||||||
intersectingRegions.add(regions.get(i));
|
intersectingRegions.add(region);
|
||||||
continue;
|
continue;
|
||||||
}
|
} else if (region instanceof ProtectedPolygonalRegion) {
|
||||||
|
// If either region contains the points of the other, they intersect
|
||||||
// Check whether the regions points are inside the other region
|
if (containsAny(region.getPoints())) {
|
||||||
if (region.contains(new Vector(min.getBlockX(), min.getBlockY(), min.getBlockZ()))
|
intersectingRegions.add(region);
|
||||||
|| region.contains(new Vector(min.getBlockX(), min.getBlockY(), max.getBlockZ()))
|
continue;
|
||||||
|| region.contains(new Vector(min.getBlockX(), max.getBlockY(), max.getBlockZ()))
|
}
|
||||||
|| region.contains(new Vector(min.getBlockX(), max.getBlockY(), min.getBlockZ()))
|
if (region.containsAny(getPoints())) {
|
||||||
|| region.contains(new Vector(max.getBlockX(), max.getBlockY(), max.getBlockZ()))
|
intersectingRegions.add(region);
|
||||||
|| region.contains(new Vector(max.getBlockX(), max.getBlockY(), min.getBlockZ()))
|
continue;
|
||||||
|| region.contains(new Vector(max.getBlockX(), min.getBlockY(), min.getBlockZ()))
|
|
||||||
|| region.contains(new Vector(max.getBlockX(), min.getBlockY(), max.getBlockZ())) ) {
|
|
||||||
intersectingRegions.add(regions.get(i));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether the other regions points are inside the current region
|
|
||||||
if (region instanceof ProtectedPolygonalRegion) {
|
|
||||||
for (i2 = 0; i2 < ((ProtectedPolygonalRegion)region).getPoints().size(); i2++) {
|
|
||||||
BlockVector2D pt2Dr = ((ProtectedPolygonalRegion)region).getPoints().get(i2);
|
|
||||||
int minYr = ((ProtectedPolygonalRegion)region).minY;
|
|
||||||
int maxYr = ((ProtectedPolygonalRegion)region).maxY;
|
|
||||||
Vector ptr = new Vector(pt2Dr.getBlockX(), minYr, pt2Dr.getBlockZ());
|
|
||||||
Vector ptr2 = new Vector(pt2Dr.getBlockX(), maxYr, pt2Dr.getBlockZ());
|
|
||||||
|
|
||||||
if (this.contains(ptr) || this.contains(ptr2)) {
|
|
||||||
intersectingRegions.add(regions.get(i));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the current regions edges collide with the regions edges
|
|
||||||
boolean regionIsIntersecting = false;
|
|
||||||
List<BlockVector2D> points = new ArrayList<BlockVector2D>();
|
|
||||||
points.add(new BlockVector2D(min.getBlockX(), min.getBlockZ()));
|
|
||||||
points.add(new BlockVector2D(min.getBlockX(), max.getBlockZ()));
|
|
||||||
points.add(new BlockVector2D(max.getBlockX(), max.getBlockZ()));
|
|
||||||
points.add(new BlockVector2D(max.getBlockX(), min.getBlockZ()));
|
|
||||||
|
|
||||||
for (i2 = 0; i2 < points.size(); i2++) {
|
|
||||||
boolean checkNextPoint = false;
|
|
||||||
BlockVector2D currPoint = points.get(i2);
|
|
||||||
BlockVector2D nextPoint;
|
|
||||||
|
|
||||||
if (i2 == (points.size() - 1)) {
|
|
||||||
nextPoint = points.get(0);
|
|
||||||
} else {
|
|
||||||
nextPoint = points.get(i2 + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int currX = currPoint.getBlockX();
|
|
||||||
int currZ = currPoint.getBlockZ();
|
|
||||||
while (!checkNextPoint) {
|
|
||||||
for(i3 = min.getBlockY(); i3 <= max.getBlockY(); i3++) {
|
|
||||||
if (region.contains(new Vector(currX, i3, currZ))) {
|
|
||||||
intersectingRegions.add(regions.get(i));
|
|
||||||
regionIsIntersecting = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currX == nextPoint.getBlockX() || currZ == nextPoint.getBlockZ() || regionIsIntersecting) {
|
|
||||||
checkNextPoint = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nextPoint.getBlockX() > currPoint.getBlockX()) {
|
|
||||||
currX++;
|
|
||||||
} else {
|
|
||||||
currX--;
|
|
||||||
}
|
|
||||||
if (nextPoint.getBlockZ() > currPoint.getBlockZ()) {
|
|
||||||
currZ++;
|
|
||||||
} else {
|
|
||||||
currZ--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (regionIsIntersecting) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return intersectingRegions;
|
return intersectingRegions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,6 +183,4 @@ public int volume() {
|
|||||||
int volume = xLength * yLength * zLength;
|
int volume = xLength * yLength * zLength;
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -21,7 +21,6 @@
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.sk89q.worldedit.BlockVector;
|
|
||||||
import com.sk89q.worldedit.BlockVector2D;
|
import com.sk89q.worldedit.BlockVector2D;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
|
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
|
||||||
@ -31,55 +30,36 @@ public class ProtectedPolygonalRegion extends ProtectedRegion {
|
|||||||
protected List<BlockVector2D> points;
|
protected List<BlockVector2D> points;
|
||||||
protected int minY;
|
protected int minY;
|
||||||
protected int maxY;
|
protected int maxY;
|
||||||
private BlockVector min;
|
|
||||||
private BlockVector max;
|
|
||||||
|
|
||||||
public ProtectedPolygonalRegion(String id, List<BlockVector2D> points, int minY, int maxY) {
|
public ProtectedPolygonalRegion(String id, List<BlockVector2D> points, int minY, int maxY) {
|
||||||
super(id);
|
super(id);
|
||||||
this.points = points;
|
this.points = points;
|
||||||
this.minY = minY;
|
setMinMaxPoints(points, minY, maxY);
|
||||||
this.maxY = maxY;
|
this.minY = min.getBlockY();
|
||||||
|
this.maxY = max.getBlockY();
|
||||||
|
}
|
||||||
|
|
||||||
int minX = points.get(0).getBlockX();
|
/**
|
||||||
int minZ = points.get(0).getBlockZ();
|
* Sets the min and max points from all the 2d points and the min/max Y values
|
||||||
int maxX = points.get(0).getBlockX();
|
*
|
||||||
int maxZ = points.get(0).getBlockZ();
|
* @param points2D
|
||||||
|
* @param minY
|
||||||
for (BlockVector2D v : points) {
|
* @param maxY
|
||||||
int x = v.getBlockX();
|
*/
|
||||||
int z = v.getBlockZ();
|
private void setMinMaxPoints(List<BlockVector2D> points2D, int minY, int maxY) {
|
||||||
if (x < minX) {
|
List<Vector> points = new ArrayList<Vector>();
|
||||||
minX = x;
|
int y = minY;
|
||||||
}
|
for (BlockVector2D point2D : points2D) {
|
||||||
if (z < minZ) {
|
points.add(new Vector(point2D.getBlockX(), y, point2D.getBlockZ()));
|
||||||
minZ = z;
|
y = maxY;
|
||||||
}
|
|
||||||
if (x > maxX) {
|
|
||||||
maxX = x;
|
|
||||||
}
|
|
||||||
if (z > maxZ) {
|
|
||||||
maxZ = z;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
setMinMaxPoints(points);
|
||||||
min = new BlockVector(minX, minY, minZ);
|
|
||||||
max = new BlockVector(maxX, maxY, maxZ);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BlockVector2D> getPoints() {
|
public List<BlockVector2D> getPoints() {
|
||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockVector getMinimumPoint() {
|
|
||||||
return min;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockVector getMaximumPoint() {
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see if a point is inside this region.
|
* Checks to see if a point is inside this region.
|
||||||
*/
|
*/
|
||||||
@ -144,117 +124,25 @@ public boolean contains(Vector pt) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> regions) throws UnsupportedIntersectionException {
|
public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> regions) throws UnsupportedIntersectionException {
|
||||||
int numRegions = regions.size();
|
|
||||||
int numPoints = points.size();
|
|
||||||
List<ProtectedRegion> intersectingRegions = new ArrayList<ProtectedRegion>();
|
List<ProtectedRegion> intersectingRegions = new ArrayList<ProtectedRegion>();
|
||||||
int i, i2, i3;
|
|
||||||
|
|
||||||
for (i = 0; i < numRegions; i++) {
|
for (ProtectedRegion region : regions) {
|
||||||
ProtectedRegion region = regions.get(i);
|
if (!intersectsBoundingBox(region)) continue;
|
||||||
BlockVector rMinPoint = region.getMinimumPoint();
|
|
||||||
BlockVector rMaxPoint = region.getMaximumPoint();
|
|
||||||
|
|
||||||
// Check whether the region is outside the min and max vector
|
if (region instanceof ProtectedPolygonalRegion || region instanceof ProtectedCuboidRegion) {
|
||||||
if ((rMinPoint.getBlockX() < min.getBlockX() && rMaxPoint.getBlockX() < min.getBlockX())
|
// If either region contains the points of the other, they intersect
|
||||||
|| (rMinPoint.getBlockX() > max.getBlockX() && rMaxPoint.getBlockX() > max.getBlockX())
|
if (containsAny(region.getPoints())) {
|
||||||
&& ((rMinPoint.getBlockY() < min.getBlockY() && rMaxPoint.getBlockY() < min.getBlockY())
|
intersectingRegions.add(region);
|
||||||
|| (rMinPoint.getBlockY() > max.getBlockY() && rMaxPoint.getBlockY() > max.getBlockY()))
|
|
||||||
&& ((rMinPoint.getBlockZ() < min.getBlockZ() && rMaxPoint.getBlockZ() < min.getBlockZ())
|
|
||||||
|| (rMinPoint.getBlockZ() > max.getBlockZ() && rMaxPoint.getBlockZ() > max.getBlockZ())) ) {
|
|
||||||
intersectingRegions.add(regions.get(i));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether the regions points are inside the other region
|
|
||||||
for (i2 = 0; i < numPoints; i++) {
|
|
||||||
Vector pt = new Vector(points.get(i2).getBlockX(), minY, points.get(i2).getBlockZ());
|
|
||||||
Vector pt2 = new Vector(points.get(i2).getBlockX(), maxY, points.get(i2).getBlockZ());
|
|
||||||
if (region.contains(pt) || region.contains(pt2)) {
|
|
||||||
intersectingRegions.add(regions.get(i));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
if (region.containsAny(getPoints())) {
|
||||||
|
intersectingRegions.add(region);
|
||||||
// Check whether the other regions points are inside the current region
|
|
||||||
if (region instanceof ProtectedPolygonalRegion) {
|
|
||||||
for (i2 = 0; i < ((ProtectedPolygonalRegion)region).getPoints().size(); i++) {
|
|
||||||
BlockVector2D pt2Dr = ((ProtectedPolygonalRegion)region).getPoints().get(i2);
|
|
||||||
int minYr = ((ProtectedPolygonalRegion)region).minY;
|
|
||||||
int maxYr = ((ProtectedPolygonalRegion)region).maxY;
|
|
||||||
Vector ptr = new Vector(pt2Dr.getBlockX(), minYr, pt2Dr.getBlockZ());
|
|
||||||
Vector ptr2 = new Vector(pt2Dr.getBlockX(), maxYr, pt2Dr.getBlockZ());
|
|
||||||
|
|
||||||
if (this.contains(ptr) || this.contains(ptr2)) {
|
|
||||||
intersectingRegions.add(regions.get(i));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (region instanceof ProtectedCuboidRegion) {
|
|
||||||
BlockVector ptcMin = region.getMinimumPoint();
|
|
||||||
BlockVector ptcMax = region.getMaximumPoint();
|
|
||||||
|
|
||||||
if (this.contains(new Vector(ptcMin.getBlockX(), ptcMin.getBlockY(), ptcMin.getBlockZ()))
|
|
||||||
|| this.contains(new Vector(ptcMin.getBlockX(), ptcMin.getBlockY(), ptcMax.getBlockZ()))
|
|
||||||
|| this.contains(new Vector(ptcMin.getBlockX(), ptcMax.getBlockY(), ptcMax.getBlockZ()))
|
|
||||||
|| this.contains(new Vector(ptcMin.getBlockX(), ptcMax.getBlockY(), ptcMin.getBlockZ()))
|
|
||||||
|| this.contains(new Vector(ptcMax.getBlockX(), ptcMax.getBlockY(), ptcMax.getBlockZ()))
|
|
||||||
|| this.contains(new Vector(ptcMax.getBlockX(), ptcMax.getBlockY(), ptcMin.getBlockZ()))
|
|
||||||
|| this.contains(new Vector(ptcMax.getBlockX(), ptcMin.getBlockY(), ptcMin.getBlockZ()))
|
|
||||||
|| this.contains(new Vector(ptcMax.getBlockX(), ptcMin.getBlockY(), ptcMax.getBlockZ())) ) {
|
|
||||||
intersectingRegions.add(regions.get(i));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the current regions edges collide with the regions edges
|
|
||||||
boolean regionIsIntersecting = false;
|
|
||||||
for (i2 = 0; i2 < numPoints; i2++) {
|
|
||||||
boolean checkNextPoint = false;
|
|
||||||
BlockVector2D currPoint = points.get(i2);
|
|
||||||
BlockVector2D nextPoint;
|
|
||||||
|
|
||||||
if (i2 == (numPoints - 1)) {
|
|
||||||
nextPoint = points.get(0);
|
|
||||||
} else {
|
|
||||||
nextPoint = points.get(i2 + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int currX = currPoint.getBlockX();
|
|
||||||
int currZ = currPoint.getBlockZ();
|
|
||||||
|
|
||||||
while (!checkNextPoint) {
|
|
||||||
for(i3 = this.minY; i3 <= this.maxY; i3++) {
|
|
||||||
if (region.contains(new Vector(currX, i3, currZ))) {
|
|
||||||
intersectingRegions.add(regions.get(i));
|
|
||||||
regionIsIntersecting = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currX == nextPoint.getBlockX() || currZ == nextPoint.getBlockZ() || regionIsIntersecting) {
|
|
||||||
checkNextPoint = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nextPoint.getBlockX() > currPoint.getBlockX()) {
|
|
||||||
currX++;
|
|
||||||
} else {
|
|
||||||
currX--;
|
|
||||||
}
|
|
||||||
if (nextPoint.getBlockZ() > currPoint.getBlockZ()) {
|
|
||||||
currZ++;
|
|
||||||
} else {
|
|
||||||
currZ--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (regionIsIntersecting) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return intersectingRegions;
|
return intersectingRegions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
|
import com.sk89q.worldedit.BlockVector2D;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||||
@ -38,6 +39,9 @@
|
|||||||
*/
|
*/
|
||||||
public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
||||||
|
|
||||||
|
protected BlockVector min;
|
||||||
|
protected BlockVector max;
|
||||||
|
|
||||||
private static final Pattern idPattern = Pattern.compile("^[A-Za-z0-9_,'\\-\\+/]{1,}$");
|
private static final Pattern idPattern = Pattern.compile("^[A-Za-z0-9_,'\\-\\+/]{1,}$");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,6 +83,37 @@ public ProtectedRegion(String id) {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the minimum and maximum points of the bounding box for a region
|
||||||
|
*
|
||||||
|
* @param points
|
||||||
|
*/
|
||||||
|
protected void setMinMaxPoints(List<Vector> points) {
|
||||||
|
int minX = points.get(0).getBlockX();
|
||||||
|
int minY = points.get(0).getBlockY();
|
||||||
|
int minZ = points.get(0).getBlockZ();
|
||||||
|
int maxX = minX;
|
||||||
|
int maxY = minY;
|
||||||
|
int maxZ = minZ;
|
||||||
|
|
||||||
|
for (Vector v : points) {
|
||||||
|
int x = v.getBlockX();
|
||||||
|
int y = v.getBlockY();
|
||||||
|
int z = v.getBlockZ();
|
||||||
|
|
||||||
|
if (x < minX) minX = x;
|
||||||
|
if (y < minY) minY = y;
|
||||||
|
if (z < minZ) minZ = z;
|
||||||
|
|
||||||
|
if (x > maxX) maxX = x;
|
||||||
|
if (y > maxY) maxY = y;
|
||||||
|
if (z > maxZ) maxZ = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
min = new BlockVector(minX, minY, minZ);
|
||||||
|
max = new BlockVector(maxX, maxY, maxZ);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the id
|
* @return the id
|
||||||
*/
|
*/
|
||||||
@ -91,14 +126,18 @@ public String getId() {
|
|||||||
*
|
*
|
||||||
* @return min point
|
* @return min point
|
||||||
*/
|
*/
|
||||||
public abstract BlockVector getMinimumPoint();
|
public BlockVector getMinimumPoint() {
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the upper point of the cuboid.
|
* Get the upper point of the cuboid.
|
||||||
*
|
*
|
||||||
* @return max point
|
* @return max point
|
||||||
*/
|
*/
|
||||||
public abstract BlockVector getMaximumPoint();
|
public BlockVector getMaximumPoint() {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the priority
|
* @return the priority
|
||||||
@ -314,6 +353,13 @@ public void setFlags(Map<Flag<?>, Object> flags) {
|
|||||||
this.flags = flags;
|
this.flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the 2D points for this region
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract List<BlockVector2D> getPoints();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of blocks in this region
|
* Get the number of blocks in this region
|
||||||
*
|
*
|
||||||
@ -329,6 +375,43 @@ public void setFlags(Map<Flag<?>, Object> flags) {
|
|||||||
*/
|
*/
|
||||||
public abstract boolean contains(Vector pt);
|
public abstract boolean contains(Vector pt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if a point is inside this region.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean contains(BlockVector2D pt) {
|
||||||
|
return contains(new Vector(pt.getBlockX(), min.getBlockY(), pt.getBlockZ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if a point is inside this region.
|
||||||
|
*
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
* @param z
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean contains(int x, int y, int z) {
|
||||||
|
return contains(new Vector(x, y, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if any of the 2D points are inside this region.
|
||||||
|
*
|
||||||
|
* @param pts
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean containsAny(List<BlockVector2D> pts) {
|
||||||
|
for (BlockVector2D pt : pts) {
|
||||||
|
if (contains(pt)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares to another region.
|
* Compares to another region.
|
||||||
*
|
*
|
||||||
@ -365,6 +448,30 @@ public abstract List<ProtectedRegion> getIntersectingRegions(
|
|||||||
List<ProtectedRegion> regions)
|
List<ProtectedRegion> regions)
|
||||||
throws UnsupportedIntersectionException;
|
throws UnsupportedIntersectionException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the bounding box of a region intersects with with the bounding
|
||||||
|
* box of this region
|
||||||
|
*
|
||||||
|
* @param region
|
||||||
|
*/
|
||||||
|
protected boolean intersectsBoundingBox(ProtectedRegion region) {
|
||||||
|
BlockVector rMaxPoint = region.getMaximumPoint();
|
||||||
|
BlockVector min = getMinimumPoint();
|
||||||
|
|
||||||
|
if (rMaxPoint.getBlockX() < min.getBlockX()) return false;
|
||||||
|
if (rMaxPoint.getBlockY() < min.getBlockY()) return false;
|
||||||
|
if (rMaxPoint.getBlockZ() < min.getBlockZ()) return false;
|
||||||
|
|
||||||
|
BlockVector rMinPoint = region.getMinimumPoint();
|
||||||
|
BlockVector max = getMaximumPoint();
|
||||||
|
|
||||||
|
if (rMinPoint.getBlockX() > max.getBlockX()) return false;
|
||||||
|
if (rMinPoint.getBlockY() > max.getBlockY()) return false;
|
||||||
|
if (rMinPoint.getBlockZ() > max.getBlockZ()) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see if the given ID is accurate.
|
* Checks to see if the given ID is accurate.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user