use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.
the class DataLoader method loadDomainGroups.
private void loadDomainGroups() throws SQLException {
Closer closer = Closer.create();
try {
PreparedStatement stmt = closer.register(conn.prepareStatement("SELECT rg.region_id, g.name, rg.owner " + "FROM `" + config.getTablePrefix() + "region_groups` AS rg " + "INNER JOIN `" + config.getTablePrefix() + "group` AS g ON (rg.group_id = g.id) " + // LEFT JOIN is returning NULLS for reasons unknown
"AND rg.world_id = " + this.worldId));
ResultSet rs = closer.register(stmt.executeQuery());
while (rs.next()) {
ProtectedRegion region = loaded.get(rs.getString("region_id"));
if (region != null) {
DefaultDomain domain;
if (rs.getBoolean("owner")) {
domain = region.getOwners();
} else {
domain = region.getMembers();
}
domain.addGroup(rs.getString("name"));
}
}
} finally {
closer.closeQuietly();
}
}
use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.
the class DataLoader method loadDomainUsers.
private void loadDomainUsers() throws SQLException {
Closer closer = Closer.create();
try {
PreparedStatement stmt = closer.register(conn.prepareStatement("SELECT p.region_id, u.name, u.uuid, p.owner " + "FROM " + config.getTablePrefix() + "region_players AS p " + "LEFT JOIN " + config.getTablePrefix() + "user AS u " + " ON (p.user_id = u.id) " + "WHERE p.world_id = " + worldId));
ResultSet rs = closer.register(stmt.executeQuery());
while (rs.next()) {
ProtectedRegion region = loaded.get(rs.getString("region_id"));
if (region != null) {
DefaultDomain domain;
if (rs.getBoolean("owner")) {
domain = region.getOwners();
} else {
domain = region.getMembers();
}
String name = rs.getString("name");
String uuid = rs.getString("uuid");
if (name != null) {
// noinspection deprecation
domain.addPlayer(name);
} else if (uuid != null) {
try {
domain.addPlayer(UUID.fromString(uuid));
} catch (IllegalArgumentException e) {
log.warning("Invalid UUID '" + uuid + "' for region '" + region.getId() + "'");
}
}
}
}
} finally {
closer.closeQuietly();
}
}
use of com.sk89q.worldguard.util.io.Closer 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.worldguard.util.io.Closer in project WorldGuard by EngineHub.
the class RegionInserter method insertCuboids.
private void insertCuboids() throws SQLException {
Closer closer = Closer.create();
try {
PreparedStatement stmt = closer.register(conn.prepareStatement("INSERT INTO " + config.getTablePrefix() + "region_cuboid " + "(region_id, world_id, min_z, min_y, min_x, max_z, max_y, max_x ) " + "VALUES " + "(?, " + worldId + ", ?, ?, ?, ?, ?, ?)"));
for (List<ProtectedCuboidRegion> partition : Lists.partition(cuboids, StatementBatch.MAX_BATCH_SIZE)) {
for (ProtectedCuboidRegion region : partition) {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
stmt.setString(1, region.getId());
stmt.setInt(2, min.getBlockZ());
stmt.setInt(3, min.getBlockY());
stmt.setInt(4, min.getBlockX());
stmt.setInt(5, max.getBlockZ());
stmt.setInt(6, max.getBlockY());
stmt.setInt(7, max.getBlockX());
stmt.addBatch();
}
stmt.executeBatch();
}
} finally {
closer.closeQuietly();
}
}
use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.
the class RegionUpdater method setParents.
private void setParents() throws SQLException {
Closer closer = Closer.create();
try {
PreparedStatement stmt = closer.register(conn.prepareStatement("UPDATE " + config.getTablePrefix() + "region " + "SET parent = ? " + "WHERE id = ? AND world_id = " + worldId));
for (List<ProtectedRegion> partition : Lists.partition(parentsToSet, StatementBatch.MAX_BATCH_SIZE)) {
for (ProtectedRegion region : partition) {
ProtectedRegion parent = region.getParent();
if (parent != null) {
// Parent would be null due to a race condition
stmt.setString(1, parent.getId());
stmt.setString(2, region.getId());
stmt.addBatch();
}
}
stmt.executeBatch();
}
} finally {
closer.closeQuietly();
}
}
Aggregations