use of com.sk89q.worldedit.math.BlockVector2 in project WorldGuard by EngineHub.
the class ChunkHashTable method rebuild.
/**
* Clear the current hash table and rebuild it in the background.
*/
private void rebuild() {
synchronized (lock) {
ListeningExecutorService previousExecutor = executor;
LongHashTable<ChunkState> previousStates = states;
previousExecutor.shutdownNow();
states = new LongHashTable<>();
executor = createExecutor();
List<BlockVector2> positions = new ArrayList<>();
for (ChunkState state : previousStates.values()) {
BlockVector2 position = state.getPosition();
positions.add(position);
states.put(position.getBlockX(), position.getBlockZ(), new ChunkState(position));
}
if (!positions.isEmpty()) {
executor.submit(new EnumerateRegions(positions));
}
lastState = null;
}
}
use of com.sk89q.worldedit.math.BlockVector2 in project WorldGuard by EngineHub.
the class ProtectedPolygonalRegion method setMinMaxPoints.
/**
* Sets the min and max points from all the 2d points and the min/max Y values
*
* @param points2D A {@link List} of points that this region should contain
* @param minY The minimum y coordinate
* @param maxY The maximum y coordinate
*/
private void setMinMaxPoints(List<BlockVector2> points2D, int minY, int maxY) {
checkNotNull(points2D);
List<BlockVector3> points = new ArrayList<>();
int y = minY;
for (BlockVector2 point2D : points2D) {
points.add(BlockVector3.at(point2D.getBlockX(), y, point2D.getBlockZ()));
y = maxY;
}
setMinMaxPoints(points);
}
use of com.sk89q.worldedit.math.BlockVector2 in project WorldGuard by EngineHub.
the class DataLoader method loadPolygons.
private void loadPolygons() throws SQLException {
ListMultimap<String, BlockVector2> pointsCache = ArrayListMultimap.create();
// First get all the vertices and store them in memory
Closer closer = Closer.create();
try {
PreparedStatement stmt = closer.register(conn.prepareStatement("SELECT region_id, x, z " + "FROM " + config.getTablePrefix() + "region_poly2d_point " + "WHERE world_id = " + worldId));
ResultSet rs = closer.register(stmt.executeQuery());
while (rs.next()) {
pointsCache.put(rs.getString("region_id"), BlockVector2.at(rs.getInt("x"), rs.getInt("z")));
}
} finally {
closer.closeQuietly();
}
// Now we pull the regions themselves
closer = Closer.create();
try {
PreparedStatement stmt = closer.register(conn.prepareStatement("SELECT g.min_y, g.max_y, r.id, r.priority, p.id AS parent " + "FROM " + config.getTablePrefix() + "region_poly2d AS g " + "LEFT JOIN " + config.getTablePrefix() + "region AS r " + " ON (g.region_id = r.id AND g.world_id = r.world_id) " + "LEFT JOIN " + config.getTablePrefix() + "region AS p " + " ON (r.parent = p.id AND r.world_id = p.world_id) " + "WHERE r.world_id = " + worldId));
ResultSet rs = closer.register(stmt.executeQuery());
while (rs.next()) {
String id = rs.getString("id");
// Get the points from the cache
List<BlockVector2> points = pointsCache.get(id);
if (points.size() < 3) {
log.log(Level.WARNING, "Invalid polygonal region '" + id + "': region has " + points.size() + " point(s) (less than the required 3). Skipping this region.");
continue;
}
Integer minY = rs.getInt("min_y");
Integer maxY = rs.getInt("max_y");
ProtectedRegion region = new ProtectedPolygonalRegion(id, points, minY, maxY);
region.setPriority(rs.getInt("priority"));
loaded.put(id, region);
String parentId = rs.getString("parent");
if (parentId != null) {
parentSets.put(region, parentId);
}
}
} finally {
closer.closeQuietly();
}
}
use of com.sk89q.worldedit.math.BlockVector2 in project WorldGuard by EngineHub.
the class RegionOverlapTest 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);
region.setPriority(5);
manager.addRegion(region);
courtyard = region;
}
use of com.sk89q.worldedit.math.BlockVector2 in project WorldGuard by EngineHub.
the class RegionIntersectTest method testIntersection.
@Test
public void testIntersection() throws Exception {
final ProtectedCuboidRegion cuboidRegion = new ProtectedCuboidRegion("cuboidRegion", BlockVector3.at(-3, -3, -3), BlockVector3.at(3, 3, 3));
for (int angle = 0; angle < 360; angle += 90) {
final BlockVector2[] rotatedPolygon = new BlockVector2[polygon.length];
for (int i = 0; i < polygon.length; i++) {
final BlockVector2 vertex = polygon[i];
rotatedPolygon[i] = vertex.transform2D(angle, 0, 0, 0, 0);
}
final ProtectedPolygonalRegion polygonalRegion = new ProtectedPolygonalRegion("polygonalRegion", Arrays.asList(rotatedPolygon), -3, 3);
assertTrue(cuboidRegion.intersectsEdges(polygonalRegion), String.format("%s does not intersect (cuboid.intersectsEdges(polygonal)", Arrays.asList(rotatedPolygon)));
assertTrue(polygonalRegion.intersectsEdges(cuboidRegion), String.format("%s does not intersect (polygonal.intersectsEdges(cuboid)", Arrays.asList(rotatedPolygon)));
}
}
Aggregations