Search in sources :

Example 21 with BlockVector2

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

Example 22 with BlockVector2

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;
}
Also used : BlockVector2(com.sk89q.worldedit.math.BlockVector2) Line2D(java.awt.geom.Line2D)

Example 23 with BlockVector2

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);
}
Also used : Area(java.awt.geom.Area) Polygon(java.awt.Polygon) BlockVector2(com.sk89q.worldedit.math.BlockVector2)

Example 24 with BlockVector2

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);
}
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 25 with BlockVector2

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;
}
Also used : WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ArrayList(java.util.ArrayList) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) Chunk(org.bukkit.Chunk) BlockVector2(com.sk89q.worldedit.math.BlockVector2) Nullable(javax.annotation.Nullable)

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