use of com.sk89q.worldedit.math.BlockVector2 in project WorldGuard by EngineHub.
the class RegionInserter method insertPolygonVertices.
private void insertPolygonVertices() throws SQLException {
Closer closer = Closer.create();
try {
PreparedStatement stmt = closer.register(conn.prepareStatement("INSERT INTO " + config.getTablePrefix() + "region_poly2d_point" + "(region_id, world_id, z, x) " + "VALUES " + "(?, " + worldId + ", ?, ?)"));
StatementBatch batch = new StatementBatch(stmt, StatementBatch.MAX_BATCH_SIZE);
for (ProtectedPolygonalRegion region : polygons) {
for (BlockVector2 point : region.getPoints()) {
stmt.setString(1, region.getId());
stmt.setInt(2, point.getBlockZ());
stmt.setInt(3, point.getBlockX());
batch.addBatch();
}
}
batch.executeRemaining();
} finally {
closer.closeQuietly();
}
}
use of com.sk89q.worldedit.math.BlockVector2 in project WorldGuard by EngineHub.
the class ProtectedRegion method intersectsEdges.
/**
* Compares all edges of two regions to see if any of them intersect.
*
* @param region the region to check
* @return whether any edges of a region intersect
*/
protected boolean intersectsEdges(ProtectedRegion region) {
List<BlockVector2> pts1 = getPoints();
List<BlockVector2> pts2 = region.getPoints();
BlockVector2 lastPt1 = pts1.get(pts1.size() - 1);
BlockVector2 lastPt2 = pts2.get(pts2.size() - 1);
for (BlockVector2 aPts1 : pts1) {
for (BlockVector2 aPts2 : pts2) {
Line2D line1 = new Line2D.Double(lastPt1.getBlockX(), lastPt1.getBlockZ(), aPts1.getBlockX(), aPts1.getBlockZ());
if (line1.intersectsLine(lastPt2.getBlockX(), lastPt2.getBlockZ(), aPts2.getBlockX(), aPts2.getBlockZ())) {
return true;
}
lastPt2 = aPts2;
}
lastPt1 = aPts1;
}
return false;
}
use of com.sk89q.worldedit.math.BlockVector2 in project WorldGuard by EngineHub.
the class ProtectedPolygonalRegion method toArea.
@Override
Area toArea() {
List<BlockVector2> points = getPoints();
int numPoints = points.size();
int[] xCoords = new int[numPoints];
int[] yCoords = new int[numPoints];
int i = 0;
for (BlockVector2 point : points) {
xCoords[i] = point.getBlockX();
yCoords[i] = point.getBlockZ();
i++;
}
Polygon polygon = new Polygon(xCoords, yCoords, numPoints);
return new Area(polygon);
}
use of com.sk89q.worldedit.math.BlockVector2 in project WorldGuard by EngineHub.
the class RegionPriorityTest method setUpCourtyardRegion.
void setUpCourtyardRegion() {
DefaultDomain domain = new DefaultDomain();
domain.addGroup(COURTYARD_GROUP);
ArrayList<BlockVector2> points = new ArrayList<>();
points.add(BlockVector2.ZERO);
points.add(BlockVector2.at(10, 0));
points.add(BlockVector2.at(10, 10));
points.add(BlockVector2.at(0, 10));
// ProtectedRegion region = new ProtectedCuboidRegion(COURTYARD_ID, new BlockVector(0, 0, 0), new BlockVector(10, 10, 10));
ProtectedRegion region = new ProtectedPolygonalRegion(COURTYARD_ID, points, 0, 10);
region.setOwners(domain);
manager.addRegion(region);
courtyard = region;
courtyard.setFlag(Flags.MOB_SPAWNING, StateFlag.State.DENY);
}
use of com.sk89q.worldedit.math.BlockVector2 in project WorldGuard by EngineHub.
the class BukkitRegionContainer method load.
@Override
@Nullable
protected RegionManager load(World world) {
checkNotNull(world);
WorldConfiguration config = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
if (!config.useRegions) {
return null;
}
RegionManager manager;
synchronized (lock) {
manager = container.load(world.getName());
if (manager != null) {
// Bias the region data for loaded chunks
List<BlockVector2> positions = new ArrayList<>();
for (Chunk chunk : ((BukkitWorld) world).getWorld().getLoadedChunks()) {
positions.add(BlockVector2.at(chunk.getX(), chunk.getZ()));
}
manager.loadChunks(positions);
}
}
return manager;
}
Aggregations