Compare commits

...
4 changed files with 56 additions and 79 deletions

No files matched your search

@@ -25,6 +25,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
@@ -698,6 +699,8 @@ public final class RegionCommands {
existing = findExistingRegion(regionManager, args.getString(0), true);
}
Bukkit.getLogger().info(String.valueOf(existing.volume()));
// Check permissions
if (!permModel.mayLookup(existing)) {
throw new CommandPermissionsException();
@@ -129,30 +129,14 @@ public class ProtectedCuboidRegion extends ProtectedRegion {
*/
@Override
public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> regions) throws UnsupportedIntersectionException {
List<ProtectedRegion> intersectingRegions = new ArrayList<ProtectedRegion>();
for (ProtectedRegion region : regions) {
if (!intersectsBoundingBox(region)) continue;
// If both regions are Cuboids and their bounding boxes intersect, they intersect
if (region instanceof ProtectedCuboidRegion) {
intersectingRegions.add(region);
continue;
} else if (region instanceof ProtectedPolygonalRegion) {
// If either region contains the points of the other,
// or if any edges intersect, the regions intersect
if (containsAny(region.getPoints())
|| region.containsAny(getPoints())
|| intersectsEdges(region)) {
intersectingRegions.add(region);
continue;
}
} else {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean intersectsRegion(ProtectedRegion region) {
if (region instanceof ProtectedPolygonalRegion) {
return intersectsRegionHelper(region);
} else if (region instanceof ProtectedCuboidRegion) {
return intersectsBoundingBox(region);
} else {
throw new UnsupportedOperationException("Not supported yet.");
}
return intersectingRegions;
}
@Override
@@ -23,7 +23,6 @@ import java.util.List;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
public class ProtectedPolygonalRegion extends ProtectedRegion {
@@ -122,30 +121,6 @@ public class ProtectedPolygonalRegion extends ProtectedRegion {
return inside;
}
@Override
public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> regions) throws UnsupportedIntersectionException {
List<ProtectedRegion> intersectingRegions = new ArrayList<ProtectedRegion>();
for (ProtectedRegion region : regions) {
if (!intersectsBoundingBox(region)) continue;
if (region instanceof ProtectedPolygonalRegion || region instanceof ProtectedCuboidRegion) {
// If either region contains the points of the other,
// or if any edges intersect, the regions intersect
if (containsAny(region.getPoints())
|| region.containsAny(getPoints())
|| intersectsEdges(region)) {
intersectingRegions.add(region);
continue;
}
} else {
throw new UnsupportedOperationException("Not supported yet.");
}
}
return intersectingRegions;
}
/**
* Return the type of region as a user-friendly name.
*
@@ -158,41 +133,30 @@ public class ProtectedPolygonalRegion extends ProtectedRegion {
@Override
public int volume() {
int volume = 0;
// TODO: Fix this
/*int numPoints = points.size();
int yLength = max.getBlockY() - min.getBlockY() + 1;
int numPoints = points.size();
if (numPoints < 3) {
return 0;
int xLength = max.getBlockX() - min.getBlockX() + 1;
int zLength = max.getBlockZ() - min.getBlockZ() + 1;
return xLength * yLength * zLength;
}
double area = 0;
int xa, z1, z2;
int area = 0;
BlockVector2D p1, p2;
int s = numPoints - 1;
for (int i = 0; i < numPoints; i++) {
xa = points.get(i).getBlockX();
//za = points.get(i).getBlockZ();
if (points.get(i + 1) == null) {
z1 = points.get(0).getBlockZ();
} else {
z1 = points.get(i + 1).getBlockZ();
}
if (points.get(i - 1) == null) {
z2 = points.get(numPoints - 1).getBlockZ();
} else {
z2 = points.get(i - 1).getBlockZ();
}
// Update/define p1 & p2
p1 = points.get(i);
p2 = points.get(s);
area = area + (xa * (z1 - z2));
// Do the math, then reassign s
area += (p2.getBlockX() + p1.getBlockX() + 1) * (p2.getBlockZ() - p1.getBlockZ());
s = i;
}
xa = points.get(0).getBlockX();
//za = points.get(0).getBlockZ();
area = area + (xa * (points.get(1).getBlockZ() - points.get(numPoints - 1).getBlockZ()));
volume = (Math.abs(maxY - minY) + 1) * (int) Math.ceil((Math.abs(area) / 2));*/
return volume;
return (int) Math.abs(Math.ceil(area / 2D) * yLength);
}
}
@@ -28,6 +28,7 @@ import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
import com.sk89q.worldguard.protection.flags.Flag;
import java.awt.geom.Line2D;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -487,6 +488,24 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
return id.compareTo(other.id);
}
protected boolean intersectsRegionHelper(ProtectedRegion region) {
if (!intersectsBoundingBox(region)) {
return false;
}
// If either region contains the points of the other,
// or if any edges intersect, the regions intersect
return containsAny(region.getPoints()) || region.containsAny(getPoints()) || intersectsEdges(region);
}
public boolean intersectsRegion(ProtectedRegion region) {
if (!(region instanceof ProtectedPolygonalRegion) && (!(region instanceof ProtectedCuboidRegion))) {
throw new UnsupportedOperationException("Not supported yet.");
}
return intersectsRegionHelper(region);
}
/**
* Return the type of region as a user-friendly, lowercase name.
*
@@ -501,9 +520,16 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
* @return The elements of {@code regions} that intersect with this region
* @throws UnsupportedIntersectionException if an invalid intersection is detected
*/
public abstract List<ProtectedRegion> getIntersectingRegions(
List<ProtectedRegion> regions)
throws UnsupportedIntersectionException;
public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> regions) throws UnsupportedIntersectionException {
List<ProtectedRegion> intersectingRegions = new ArrayList<ProtectedRegion>();
for (ProtectedRegion region : regions) {
if (intersectsRegion(region)) {
intersectingRegions.add(region);
}
}
return intersectingRegions;
}
/**
* Checks if the bounding box of a region intersects with with the bounding