Search in sources :

Example 51 with BlockVector2

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;
    }
}
Also used : ArrayList(java.util.ArrayList) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) BlockVector2(com.sk89q.worldedit.math.BlockVector2)

Example 52 with BlockVector2

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);
}
Also used : ArrayList(java.util.ArrayList) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockVector2(com.sk89q.worldedit.math.BlockVector2)

Example 53 with BlockVector2

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();
    }
}
Also used : Closer(com.sk89q.worldguard.util.io.Closer) ResultSet(java.sql.ResultSet) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) ProtectedPolygonalRegion(com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion) PreparedStatement(java.sql.PreparedStatement) BlockVector2(com.sk89q.worldedit.math.BlockVector2)

Example 54 with BlockVector2

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;
}
Also used : ArrayList(java.util.ArrayList) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) ProtectedPolygonalRegion(com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion) DefaultDomain(com.sk89q.worldguard.domains.DefaultDomain) BlockVector2(com.sk89q.worldedit.math.BlockVector2)

Example 55 with BlockVector2

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)));
    }
}
Also used : BlockVector2(com.sk89q.worldedit.math.BlockVector2) Test(org.junit.jupiter.api.Test)

Aggregations

BlockVector2 (com.sk89q.worldedit.math.BlockVector2)55 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)19 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)9 Map (java.util.Map)9 ProtectedPolygonalRegion (com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion)7 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)6 LinkedHashMap (java.util.LinkedHashMap)6 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)5 Path (java.nio.file.Path)5 Iterator (java.util.Iterator)5 Set (java.util.Set)5 JsonIOException (com.google.gson.JsonIOException)4 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)4 Location (com.sk89q.worldedit.util.Location)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)4 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)3 Region (com.sk89q.worldedit.regions.Region)3