Compare commits

..
11 changed files with 295 additions and 567 deletions

No files matched your search

+1 -21
View File
@@ -83,27 +83,7 @@
<scope>compile</scope>
<type>jar</type>
</dependency>
<!-- Used for running CraftBukkit from within your IDE
These are runtime-only dependencies -->
<dependency>
<groupId>org.sk89q.bukkit</groupId>
<artifactId>bukkit-classloader-check</artifactId>
<version>1.7.2-R0.3</version>
<scope>runtime</scope>
<type>jar</type>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.2-R0.3</version>
<scope>runtime</scope>
<type>jar</type>
<optional>true</optional>
</dependency>
<!-- End runtime only -->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
@@ -19,18 +19,19 @@
package com.sk89q.worldguard.bukkit;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.entity.Player;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import java.util.HashMap;
import java.util.Map;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
/**
* This processes per-player state information and is also meant to be used
@@ -181,12 +182,10 @@ public class FlagStateManager implements Runnable {
if (feedDelay <= 0) {
player.setFoodLevel(feedAmount > 0 ? maxHunger : minHunger);
player.setSaturation(player.getFoodLevel());
state.lastFeed = now;
} else if (now - state.lastFeed > feedDelay * 1000) {
// clamp health between minimum and maximum
player.setFoodLevel(Math.min(maxHunger, Math.max(minHunger, player.getFoodLevel() + feedAmount)));
player.setSaturation(player.getFoodLevel());
state.lastFeed = now;
}
}
@@ -122,15 +122,9 @@ public class ReportWriter {
Class<? extends ConfigurationManager> cls = config.getClass();
for (Field field : cls.getFields()) {
try {
String name = field.getName();
// store these elsewhere maybe?
if (name.equals("CONFIG_HEADER")
|| name.equals("hostKeys")
|| name.equals("sqlPassword")) {
continue;
}
if (field.getName().equalsIgnoreCase("CONFIG_HEADER")) continue;
Object val = field.get(config);
configLog.put(name, val);
configLog.put(field.getName(), val);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException ignore) {
@@ -266,9 +266,8 @@ public class WorldGuardBlockListener implements Listener {
}
if (wcfg.disableObsidianGenerators && (isAir || isLava)
&& (blockTo.getTypeId() == BlockID.REDSTONE_WIRE
|| blockTo.getTypeId() == BlockID.TRIPWIRE)) {
blockTo.setTypeId(BlockID.AIR);
&& blockTo.getTypeId() == 55) {
blockTo.setTypeId(0);
return;
}
}
@@ -20,14 +20,12 @@ package com.sk89q.worldguard.bukkit;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.EnderPearl;
@@ -39,7 +37,6 @@ import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Slime;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.ThrownPotion;
@@ -226,7 +223,6 @@ public class WorldGuardEntityListener implements Listener {
if (attacker instanceof Player) {
Player player = (Player) attacker;
LocalPlayer localPlayer = plugin.wrapPlayer(player);
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(player.getWorld());
@@ -243,29 +239,6 @@ public class WorldGuardEntityListener implements Listener {
}
}
}
// Bukkit doesn't consider Slimes to be Creatures for whatever reason
if (defender instanceof Creature || defender instanceof Slime) {
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
Vector pt2 = toVector(attacker.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
// Accumulate all entities that aren't allowed to be attacked here
Set<EntityType> entityTypes = new HashSet<EntityType>();
Set<EntityType> es = mgr.getApplicableRegions(pt).getFlag(DefaultFlag.DENY_PVM, localPlayer);
Set<EntityType> es2 = mgr.getApplicableRegions(pt2).getFlag(DefaultFlag.DENY_PVM, localPlayer);
if (es != null) entityTypes.addAll(es);
if (es2 != null) entityTypes.addAll(es2);
if (entityTypes.contains(defender.getType())) {
player.sendMessage(ChatColor.DARK_RED + "You may not attack that mob here.");
event.setCancelled(true);
return;
}
}
}
}
if (defender instanceof ItemFrame) {
@@ -308,30 +281,17 @@ public class WorldGuardEntityListener implements Listener {
}
if (attacker != null) {
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
Vector pt2 = toVector(attacker.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
if (attacker instanceof Player) {
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
Vector pt2 = toVector(attacker.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
if (attacker instanceof Player) {
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
tryCancelPVPEvent((Player) attacker, player, event, true);
} else if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP ,localPlayer)) {
tryCancelPVPEvent((Player) attacker, player, event, false);
}
} else {
// Accumulate all entities that aren't allowed to be attacked here
Set<EntityType> entityTypes = new HashSet<EntityType>();
Set<EntityType> es = mgr.getApplicableRegions(pt).getFlag(DefaultFlag.DENY_PVM, localPlayer);
Set<EntityType> es2 = mgr.getApplicableRegions(pt2).getFlag(DefaultFlag.DENY_PVM, localPlayer);
if (es != null) entityTypes.addAll(es);
if (es2 != null) entityTypes.addAll(es2);
if (entityTypes.contains(attacker.getType())) {
event.setCancelled(true);
return;
}
}
}
@@ -448,43 +408,6 @@ public class WorldGuardEntityListener implements Listener {
return;
}
if (attacker instanceof Player) {
Player player = (Player) attacker;
LocalPlayer localPlayer = plugin.wrapPlayer(player);
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(player.getWorld());
if (event.getDamager() instanceof EnderPearl && attacker.equals(defender)) return;
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
Vector pt2 = toVector(attacker.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
if (defender instanceof Player) {
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
tryCancelPVPEvent((Player) attacker, player, event, true);
} else if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)) {
tryCancelPVPEvent((Player) attacker, player, event, false);
}
} else {
// Accumulate all entities that aren't allowed to be attacked here
Set<EntityType> entityTypes = new HashSet<EntityType>();
Set<EntityType> es = mgr.getApplicableRegions(pt).getFlag(DefaultFlag.DENY_PVM, localPlayer);
Set<EntityType> es2 = mgr.getApplicableRegions(pt2).getFlag(DefaultFlag.DENY_PVM, localPlayer);
if (es != null) entityTypes.addAll(es);
if (es2 != null) entityTypes.addAll(es2);
if (entityTypes.contains(defender.getType())) {
player.sendMessage(ChatColor.DARK_RED + "You may not attack that mob here.");
event.setCancelled(true);
return;
}
}
}
}
if (defender instanceof Player) {
Player player = (Player) defender;
LocalPlayer localPlayer = plugin.wrapPlayer(player);
@@ -499,33 +422,35 @@ public class WorldGuardEntityListener implements Listener {
}
// Check Mob
if (!(attacker instanceof Player)) {
if (attacker != null && !(attacker instanceof Player)) {
if (wcfg.disableMobDamage) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
Vector pt2 = toVector(attacker.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.MOB_DAMAGE, localPlayer)) {
event.setCancelled(true);
return;
}
}
}
// Accumulate all entities that aren't allowed to be attacked here
Set<EntityType> entityTypes = new HashSet<EntityType>();
Set<EntityType> es = mgr.getApplicableRegions(pt).getFlag(DefaultFlag.DENY_PVM, localPlayer);
Set<EntityType> es2 = mgr.getApplicableRegions(pt2).getFlag(DefaultFlag.DENY_PVM, localPlayer);
// Check Player
// if (event.getDamager() instanceof EnderPearl || event.getDamager() instanceof Snowball) return;
if (attacker != null && attacker instanceof Player) {
if (event.getDamager() instanceof EnderPearl && attacker == player) return;
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
Vector pt2 = toVector(attacker.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
if (es != null) entityTypes.addAll(es);
if (es2 != null) entityTypes.addAll(es2);
if (entityTypes.contains(attacker.getType())) {
event.setCancelled(true);
return;
if (!mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
tryCancelPVPEvent((Player) attacker, player, event, true);
} else if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)) {
tryCancelPVPEvent((Player) attacker, player, event, false);
}
}
}
@@ -1482,9 +1482,6 @@ public class WorldGuardPlayerListener implements Listener {
continue;
}
}
} else {
// found non-matching part, stop checking this command
continue blocked;
}
}
}
@@ -66,40 +66,34 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
String world1 = world;
this.logger = logger;
PreparedStatement worldStmt = null;
ResultSet worldResult = null;
PreparedStatement insertWorldStatement = null;
try {
connect();
PreparedStatement verTest = null;
try {
// Test if the database is up to date, if not throw a critical error
verTest = this.conn.prepareStatement(
"SELECT `world_id` FROM `region_cuboid` LIMIT 0,1;"
);
verTest.execute();
// Test if the database is up to date, if not throw a critical error
PreparedStatement verTest = this.conn.prepareStatement(
"SELECT `world_id` FROM `region_cuboid` LIMIT 0,1;"
);
verTest.execute();
} catch (SQLException ex) {
throw new InvalidTableFormatException(
"region_storage_update_20110325.sql"
);
} finally {
closeResource(verTest);
throw new InvalidTableFormatException(
"region_storage_update_20110325.sql"
);
}
worldStmt = conn.prepareStatement(
PreparedStatement worldStmt = conn.prepareStatement(
"SELECT `id` FROM " +
"`world` " +
"WHERE `name` = ? LIMIT 0,1"
);
worldStmt.setString(1, world1);
worldResult = worldStmt.executeQuery();
ResultSet worldResult = worldStmt.executeQuery();
if (worldResult.first()) {
this.worldDbId = worldResult.getInt("id");
} else {
insertWorldStatement = this.conn.prepareStatement(
PreparedStatement insertWorldStatement = this.conn.prepareStatement(
"INSERT INTO " +
"`world` " +
"(`id`, `name`) VALUES (null, ?)",
@@ -118,10 +112,6 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
// We havn't connected to the databases, or there was an error
// initialising the world record, so there is no point continuing
return;
} finally {
closeResource(worldResult);
closeResource(worldStmt);
closeResource(insertWorldStatement);
}
if (this.worldDbId <= 0) {
@@ -142,20 +132,20 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
}
private void connect() throws SQLException {
if (conn != null) {
// Check if the connection is still alive/valid.
try {
conn.isValid(2);
} catch (SQLException ex) {
// Test if validation failed because the connection is dead,
if (conn != null) {
// Make a dummy query to check the connnection is alive.
try {
conn.prepareStatement("SELECT 1;").execute();
} catch (SQLException ex) {
// Test if the dummy query failed because the connection is dead,
// and if it is mark the connection as closed (the MySQL Driver
// does not ensure that the connection is marked as closed unless
// the close() method has been called.
if ("08S01".equals(ex.getSQLState())) {
conn.close();
}
}
}
if ("08S01".equals(ex.getSQLState())) {
conn.close();
}
}
}
if (conn == null || conn.isClosed()) {
conn = DriverManager.getConnection(config.sqlDsn, config.sqlUsername, config.sqlPassword);
}
@@ -163,10 +153,8 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
private void loadFlags(ProtectedRegion region) {
// @TODO: Iterate _ONCE_
PreparedStatement flagsStatement = null;
ResultSet flagsResultSet = null;
try {
flagsStatement = this.conn.prepareStatement(
PreparedStatement flagsStatement = this.conn.prepareStatement(
"SELECT " +
"`region_flag`.`flag`, " +
"`region_flag`.`value` " +
@@ -176,7 +164,7 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
);
flagsStatement.setString(1, region.getId().toLowerCase());
flagsResultSet = flagsStatement.executeQuery();
ResultSet flagsResultSet = flagsStatement.executeQuery();
Map<String,Object> regionFlags = new HashMap<String,Object>();
while (flagsResultSet.next()) {
@@ -198,9 +186,6 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
"Unable to load flags for region "
+ region.getId().toLowerCase() + ": " + ex.getMessage()
);
} finally {
closeResource(flagsResultSet);
closeResource(flagsStatement);
}
}
@@ -218,10 +203,8 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
DefaultDomain owners = new DefaultDomain();
DefaultDomain members = new DefaultDomain();
ResultSet userSet = null;
PreparedStatement usersStatement = null;
try {
usersStatement = this.conn.prepareStatement(
PreparedStatement usersStatement = this.conn.prepareStatement(
"SELECT " +
"`user`.`name`, " +
"`region_players`.`owner` " +
@@ -234,7 +217,7 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
);
usersStatement.setString(1, region.getId().toLowerCase());
userSet = usersStatement.executeQuery();
ResultSet userSet = usersStatement.executeQuery();
while(userSet.next()) {
if (userSet.getBoolean("owner")) {
owners.addPlayer(userSet.getString("name"));
@@ -244,15 +227,10 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
}
} catch (SQLException ex) {
logger.warning("Unable to load users for region " + region.getId().toLowerCase() + ": " + ex.getMessage());
} finally {
closeResource(userSet);
closeResource(usersStatement);
}
PreparedStatement groupsStatement = null;
ResultSet groupSet = null;
try {
groupsStatement = this.conn.prepareStatement(
PreparedStatement groupsStatement = this.conn.prepareStatement(
"SELECT " +
"`group`.`name`, " +
"`region_groups`.`owner` " +
@@ -265,7 +243,7 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
);
groupsStatement.setString(1, region.getId().toLowerCase());
groupSet = groupsStatement.executeQuery();
ResultSet groupSet = groupsStatement.executeQuery();
while(groupSet.next()) {
if (groupSet.getBoolean("owner")) {
owners.addGroup(groupSet.getString("name"));
@@ -275,9 +253,6 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
}
} catch (SQLException ex) {
logger.warning("Unable to load groups for region " + region.getId().toLowerCase() + ": " + ex.getMessage());
} finally {
closeResource(groupSet);
closeResource(groupsStatement);
}
region.setOwners(owners);
@@ -288,10 +263,8 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
Map<String,ProtectedRegion> regions =
new HashMap<String,ProtectedRegion>();
PreparedStatement globalRegionStatement = null;
ResultSet globalResultSet = null;
try {
globalRegionStatement = this.conn.prepareStatement(
PreparedStatement globalRegionStatement = this.conn.prepareStatement(
"SELECT " +
"`region`.`id`, " +
"`region`.`priority`, " +
@@ -305,7 +278,7 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
);
globalRegionStatement.setInt(1, this.worldDbId);
globalResultSet = globalRegionStatement.executeQuery();
ResultSet globalResultSet = globalRegionStatement.executeQuery();
while (globalResultSet.next()) {
ProtectedRegion region = new GlobalProtectedRegion(globalResultSet.getString("id"));
@@ -330,9 +303,6 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
logger.warning("\t\tCause: " + t.getMessage());
t = t.getCause();
}
} finally {
closeResource(globalResultSet);
closeResource(globalRegionStatement);
}
globalRegions = regions;
@@ -342,10 +312,8 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
Map<String,ProtectedRegion> regions =
new HashMap<String,ProtectedRegion>();
PreparedStatement cuboidRegionStatement = null;
ResultSet cuboidResultSet = null;
try {
cuboidRegionStatement = this.conn.prepareStatement(
PreparedStatement cuboidRegionStatement = this.conn.prepareStatement(
"SELECT " +
"`region_cuboid`.`min_z`, " +
"`region_cuboid`.`min_y`, " +
@@ -367,7 +335,7 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
);
cuboidRegionStatement.setInt(1, this.worldDbId);
cuboidResultSet = cuboidRegionStatement.executeQuery();
ResultSet cuboidResultSet = cuboidRegionStatement.executeQuery();
while (cuboidResultSet.next()) {
Vector pt1 = new Vector(
@@ -410,9 +378,6 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
logger.warning("\t\tCause: " + t.getMessage());
t = t.getCause();
}
} finally {
closeResource(cuboidResultSet);
closeResource(cuboidRegionStatement);
}
cuboidRegions = regions;
@@ -422,11 +387,8 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
Map<String,ProtectedRegion> regions =
new HashMap<String,ProtectedRegion>();
PreparedStatement poly2dRegionStatement = null;
ResultSet poly2dResultSet = null;
PreparedStatement poly2dVectorStatement = null;
try {
poly2dRegionStatement = this.conn.prepareStatement(
PreparedStatement poly2dRegionStatement = this.conn.prepareStatement(
"SELECT " +
"`region_poly2d`.`min_y`, " +
"`region_poly2d`.`max_y`, " +
@@ -444,9 +406,9 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
);
poly2dRegionStatement.setInt(1, this.worldDbId);
poly2dResultSet = poly2dRegionStatement.executeQuery();
ResultSet poly2dResultSet = poly2dRegionStatement.executeQuery();
poly2dVectorStatement = this.conn.prepareStatement(
PreparedStatement poly2dVectorStatement = this.conn.prepareStatement(
"SELECT " +
"`region_poly2d_point`.`x`, " +
"`region_poly2d_point`.`z` " +
@@ -471,14 +433,6 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
poly2dVectorResultSet.getInt("z")
));
}
if (points.size() < 3) {
logger.warning(String.format("Invalid polygonal region '%s': region only has %d point(s). Ignoring.", id, points.size()));
continue;
}
closeResource(poly2dVectorResultSet);
ProtectedRegion region = new ProtectedPolygonalRegion(id, points, minY, maxY);
region.setPriority(poly2dResultSet.getInt("priority"));
@@ -501,10 +455,6 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
logger.warning("\t\tCause: " + t.getMessage());
t = t.getCause();
}
} finally {
closeResource(poly2dResultSet);
closeResource(poly2dRegionStatement);
closeResource(poly2dVectorStatement);
}
poly2dRegions = regions;
@@ -562,11 +512,8 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
if (usernames.length < 1) return users;
ResultSet findUsersResults = null;
PreparedStatement insertUserStatement = null;
PreparedStatement findUsersStatement = null;
try {
findUsersStatement = this.conn.prepareStatement(
PreparedStatement findUsersStatement = this.conn.prepareStatement(
String.format(
"SELECT " +
"`user`.`id`, " +
@@ -579,13 +526,13 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
RegionDBUtil.setValues(findUsersStatement, usernames);
findUsersResults = findUsersStatement.executeQuery();
ResultSet findUsersResults = findUsersStatement.executeQuery();
while(findUsersResults.next()) {
users.put(findUsersResults.getString("name"), findUsersResults.getInt("id"));
}
insertUserStatement = this.conn.prepareStatement(
PreparedStatement insertUserStatement = this.conn.prepareStatement(
"INSERT INTO " +
"`user` ( " +
"`id`, " +
@@ -614,10 +561,6 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
logger.warning(t.getMessage());
t = t.getCause();
}
} finally {
closeResource(findUsersResults);
closeResource(findUsersStatement);
closeResource(insertUserStatement);
}
return users;
@@ -633,11 +576,8 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
if (groupnames.length < 1) return groups;
PreparedStatement findGroupsStatement = null;
ResultSet findGroupsResults = null;
PreparedStatement insertGroupStatement = null;
try {
findGroupsStatement = this.conn.prepareStatement(
PreparedStatement findGroupsStatement = this.conn.prepareStatement(
String.format(
"SELECT " +
"`group`.`id`, " +
@@ -650,13 +590,13 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
RegionDBUtil.setValues(findGroupsStatement, groupnames);
findGroupsResults = findGroupsStatement.executeQuery();
ResultSet findGroupsResults = findGroupsStatement.executeQuery();
while(findGroupsResults.next()) {
groups.put(findGroupsResults.getString("name"), findGroupsResults.getInt("id"));
}
insertGroupStatement = this.conn.prepareStatement(
PreparedStatement insertGroupStatement = this.conn.prepareStatement(
"INSERT INTO " +
"`group` ( " +
"`id`, " +
@@ -679,10 +619,6 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
}
} catch (SQLException ex) {
logger.warning("Could not get the database id for the groups " + groupnames.toString() + ex.getMessage());
} finally {
closeResource(findGroupsResults);
closeResource(findGroupsStatement);
closeResource(insertGroupStatement);
}
return groups;
@@ -713,26 +649,21 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
List<String> regionsInDatabase = new ArrayList<String>();
PreparedStatement getAllRegionsStatement = null;
ResultSet getAllRegionsResult = null;
try {
getAllRegionsStatement = this.conn.prepareStatement(
PreparedStatement getAllRegionsStatement = this.conn.prepareStatement(
"SELECT `region`.`id` FROM " +
"`region` " +
"WHERE `world_id` = ? "
);
getAllRegionsStatement.setInt(1, this.worldDbId);
getAllRegionsResult = getAllRegionsStatement.executeQuery();
ResultSet getAllRegionsResult = getAllRegionsStatement.executeQuery();
while(getAllRegionsResult.next()) {
regionsInDatabase.add(getAllRegionsResult.getString("id"));
}
} catch (SQLException ex) {
logger.warning("Could not get region list for save comparison: " + ex.getMessage());
} finally {
closeResource(getAllRegionsResult);
closeResource(getAllRegionsStatement);
}
for (Map.Entry<String, ProtectedRegion> entry : regions.entrySet()) {
@@ -770,11 +701,10 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
}
for (Map.Entry<String, ProtectedRegion> entry : regions.entrySet()) {
PreparedStatement setParentStatement = null;
try {
if (entry.getValue().getParent() == null) continue;
setParentStatement = this.conn.prepareStatement(
PreparedStatement setParentStatement = this.conn.prepareStatement(
"UPDATE `region` SET " +
"`parent` = ? " +
"WHERE `id` = ? AND `world_id` = " + this.worldDbId
@@ -787,15 +717,12 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
} catch (SQLException ex) {
logger.warning("Could not save region parents " + entry.getValue().getId().toLowerCase() + ": " + ex.getMessage());
throw new ProtectionDatabaseException(ex);
} finally {
closeResource(setParentStatement);
}
}
for (String name : regionsInDatabase) {
PreparedStatement removeRegion = null;
try {
removeRegion = this.conn.prepareStatement(
PreparedStatement removeRegion = this.conn.prepareStatement(
"DELETE FROM `region` WHERE `id` = ? "
);
@@ -803,53 +730,41 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
removeRegion.execute();
} catch (SQLException ex) {
logger.warning("Could not remove region from database " + name + ": " + ex.getMessage());
} finally {
closeResource(removeRegion);
}
}
}
private void updateFlags(ProtectedRegion region) throws SQLException {
PreparedStatement clearCurrentFlagStatement = null;
try {
clearCurrentFlagStatement = this.conn.prepareStatement(
"DELETE FROM `region_flag` " +
"WHERE `region_id` = ? " +
"AND `world_id` = " + this.worldDbId
PreparedStatement clearCurrentFlagStatement = this.conn.prepareStatement(
"DELETE FROM `region_flag` " +
"WHERE `region_id` = ? " +
"AND `world_id` = " + this.worldDbId
);
clearCurrentFlagStatement.setString(1, region.getId().toLowerCase());
clearCurrentFlagStatement.execute();
for (Map.Entry<Flag<?>, Object> entry : region.getFlags().entrySet()) {
if (entry.getValue() == null) continue;
Object flag = sqlMarshal(marshalFlag(entry.getKey(), entry.getValue()));
PreparedStatement insertFlagStatement = this.conn.prepareStatement(
"INSERT INTO `region_flag` ( " +
"`id`, " +
"`region_id`, " +
"`world_id`, " +
"`flag`, " +
"`value` " +
") VALUES (null, ?, " + this.worldDbId + ", ?, ?)"
);
clearCurrentFlagStatement.setString(1, region.getId().toLowerCase());
clearCurrentFlagStatement.execute();
insertFlagStatement.setString(1, region.getId().toLowerCase());
insertFlagStatement.setString(2, entry.getKey().getName());
insertFlagStatement.setObject(3, flag);
for (Map.Entry<Flag<?>, Object> entry : region.getFlags().entrySet()) {
if (entry.getValue() == null) continue;
Object flag = sqlMarshal(marshalFlag(entry.getKey(), entry.getValue()));
PreparedStatement insertFlagStatement = null;
try {
insertFlagStatement = this.conn.prepareStatement(
"INSERT INTO `region_flag` ( " +
"`id`, " +
"`region_id`, " +
"`world_id`, " +
"`flag`, " +
"`value` " +
") VALUES (null, ?, " + this.worldDbId + ", ?, ?)"
);
insertFlagStatement.setString(1, region.getId().toLowerCase());
insertFlagStatement.setString(2, entry.getKey().getName());
insertFlagStatement.setObject(3, flag);
insertFlagStatement.execute();
} finally {
closeResource(insertFlagStatement);
}
}
} finally {
closeResource(clearCurrentFlagStatement);
insertFlagStatement.execute();
}
}
@@ -862,69 +777,57 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
domain = region.getMembers();
}
PreparedStatement deleteUsersForRegion = null;
PreparedStatement insertUsersForRegion = null;
PreparedStatement deleteGroupsForRegion = null;
PreparedStatement insertGroupsForRegion = null;
PreparedStatement deleteUsersForRegion = this.conn.prepareStatement(
"DELETE FROM `region_players` " +
"WHERE `region_id` = ? " +
"AND `world_id` = " + this.worldDbId + " " +
"AND `owner` = ?"
);
try {
deleteUsersForRegion = this.conn.prepareStatement(
"DELETE FROM `region_players` " +
"WHERE `region_id` = ? " +
"AND `world_id` = " + this.worldDbId + " " +
"AND `owner` = ?"
);
deleteUsersForRegion.setString(1, region.getId().toLowerCase());
deleteUsersForRegion.setBoolean(2, owners);
deleteUsersForRegion.execute();
deleteUsersForRegion.setString(1, region.getId().toLowerCase());
deleteUsersForRegion.setBoolean(2, owners);
deleteUsersForRegion.execute();
PreparedStatement insertUsersForRegion = this.conn.prepareStatement(
"INSERT INTO `region_players` " +
"(`region_id`, `world_id`, `user_id`, `owner`) " +
"VALUES (?, " + this.worldDbId + ", ?, ?)"
);
insertUsersForRegion = this.conn.prepareStatement(
"INSERT INTO `region_players` " +
"(`region_id`, `world_id`, `user_id`, `owner`) " +
"VALUES (?, " + this.worldDbId + ", ?, ?)"
);
Set<String> var = domain.getPlayers();
Set<String> var = domain.getPlayers();
for (Integer player : getUserIds(var.toArray(new String[var.size()])).values()) {
insertUsersForRegion.setString(1, region.getId().toLowerCase());
insertUsersForRegion.setInt(2, player);
insertUsersForRegion.setBoolean(3, owners);
for (Integer player : getUserIds(var.toArray(new String[var.size()])).values()) {
insertUsersForRegion.setString(1, region.getId().toLowerCase());
insertUsersForRegion.setInt(2, player);
insertUsersForRegion.setBoolean(3, owners);
insertUsersForRegion.execute();
}
insertUsersForRegion.execute();
}
PreparedStatement deleteGroupsForRegion = this.conn.prepareStatement(
"DELETE FROM `region_groups` " +
"WHERE `region_id` = ? " +
"AND `world_id` = " + this.worldDbId + " " +
"AND `owner` = ?"
);
deleteGroupsForRegion = this.conn.prepareStatement(
"DELETE FROM `region_groups` " +
"WHERE `region_id` = ? " +
"AND `world_id` = " + this.worldDbId + " " +
"AND `owner` = ?"
);
deleteGroupsForRegion.setString(1, region.getId().toLowerCase());
deleteGroupsForRegion.setBoolean(2, owners);
deleteGroupsForRegion.execute();
deleteGroupsForRegion.setString(1, region.getId().toLowerCase());
deleteGroupsForRegion.setBoolean(2, owners);
deleteGroupsForRegion.execute();
PreparedStatement insertGroupsForRegion = this.conn.prepareStatement(
"INSERT INTO `region_groups` " +
"(`region_id`, `world_id`, `group_id`, `owner`) " +
"VALUES (?, " + this.worldDbId + ", ?, ?)"
);
insertGroupsForRegion = this.conn.prepareStatement(
"INSERT INTO `region_groups` " +
"(`region_id`, `world_id`, `group_id`, `owner`) " +
"VALUES (?, " + this.worldDbId + ", ?, ?)"
);
Set<String> groupVar = domain.getGroups();
for (Integer group : getGroupIds(groupVar.toArray(new String[groupVar.size()])).values()) {
insertGroupsForRegion.setString(1, region.getId().toLowerCase());
insertGroupsForRegion.setInt(2, group);
insertGroupsForRegion.setBoolean(3, owners);
Set<String> groupVar = domain.getGroups();
for (Integer group : getGroupIds(groupVar.toArray(new String[groupVar.size()])).values()) {
insertGroupsForRegion.setString(1, region.getId().toLowerCase());
insertGroupsForRegion.setInt(2, group);
insertGroupsForRegion.setBoolean(3, owners);
insertGroupsForRegion.execute();
}
} finally {
closeResource(deleteGroupsForRegion);
closeResource(deleteUsersForRegion);
closeResource(insertGroupsForRegion);
closeResource(insertUsersForRegion);
insertGroupsForRegion.execute();
}
}
@@ -934,27 +837,22 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
}
private void insertRegion(ProtectedRegion region, String type) throws SQLException {
PreparedStatement insertRegionStatement = null;
try {
insertRegionStatement = this.conn.prepareStatement(
"INSERT INTO `region` (" +
"`id`, " +
"`world_id`, " +
"`type`, " +
"`priority`, " +
"`parent` " +
") VALUES (?, ?, ?, ?, null)"
);
PreparedStatement insertRegionStatement = this.conn.prepareStatement(
"INSERT INTO `region` (" +
"`id`, " +
"`world_id`, " +
"`type`, " +
"`priority`, " +
"`parent` " +
") VALUES (?, ?, ?, ?, null)"
);
insertRegionStatement.setString(1, region.getId().toLowerCase());
insertRegionStatement.setInt(2, this.worldDbId);
insertRegionStatement.setString(3, type);
insertRegionStatement.setInt(4, region.getPriority());
insertRegionStatement.setString(1, region.getId().toLowerCase());
insertRegionStatement.setInt(2, this.worldDbId);
insertRegionStatement.setString(3, type);
insertRegionStatement.setInt(4, region.getPriority());
insertRegionStatement.execute();
} finally {
closeResource(insertRegionStatement);
}
insertRegionStatement.execute();
updateFlags(region);
@@ -965,100 +863,82 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
private void insertRegionCuboid(ProtectedCuboidRegion region) throws SQLException {
insertRegion(region, "cuboid");
PreparedStatement insertCuboidRegionStatement = null;
try {
insertCuboidRegionStatement = this.conn.prepareStatement(
"INSERT INTO `region_cuboid` (" +
"`region_id`, " +
"`world_id`, " +
"`min_z`, " +
"`min_y`, " +
"`min_x`, " +
"`max_z`, " +
"`max_y`, " +
"`max_x` " +
") VALUES (?, " + this.worldDbId + ", ?, ?, ?, ?, ?, ?)"
);
PreparedStatement insertCuboidRegionStatement = this.conn.prepareStatement(
"INSERT INTO `region_cuboid` (" +
"`region_id`, " +
"`world_id`, " +
"`min_z`, " +
"`min_y`, " +
"`min_x`, " +
"`max_z`, " +
"`max_y`, " +
"`max_x` " +
") VALUES (?, " + this.worldDbId + ", ?, ?, ?, ?, ?, ?)"
);
BlockVector min = region.getMinimumPoint();
BlockVector max = region.getMaximumPoint();
BlockVector min = region.getMinimumPoint();
BlockVector max = region.getMaximumPoint();
insertCuboidRegionStatement.setString(1, region.getId().toLowerCase());
insertCuboidRegionStatement.setInt(2, min.getBlockZ());
insertCuboidRegionStatement.setInt(3, min.getBlockY());
insertCuboidRegionStatement.setInt(4, min.getBlockX());
insertCuboidRegionStatement.setInt(5, max.getBlockZ());
insertCuboidRegionStatement.setInt(6, max.getBlockY());
insertCuboidRegionStatement.setInt(7, max.getBlockX());
insertCuboidRegionStatement.setString(1, region.getId().toLowerCase());
insertCuboidRegionStatement.setInt(2, min.getBlockZ());
insertCuboidRegionStatement.setInt(3, min.getBlockY());
insertCuboidRegionStatement.setInt(4, min.getBlockX());
insertCuboidRegionStatement.setInt(5, max.getBlockZ());
insertCuboidRegionStatement.setInt(6, max.getBlockY());
insertCuboidRegionStatement.setInt(7, max.getBlockX());
insertCuboidRegionStatement.execute();
} finally {
closeResource(insertCuboidRegionStatement);
}
insertCuboidRegionStatement.execute();
}
private void insertRegionPoly2D(ProtectedPolygonalRegion region) throws SQLException {
insertRegion(region, "poly2d");
PreparedStatement insertPoly2dRegionStatement = null;
try {
insertPoly2dRegionStatement = this.conn.prepareStatement(
"INSERT INTO `region_poly2d` (" +
"`region_id`, " +
"`world_id`, " +
"`max_y`, " +
"`min_y` " +
") VALUES (?, " + this.worldDbId + ", ?, ?)"
);
PreparedStatement insertPoly2dRegionStatement = this.conn.prepareStatement(
"INSERT INTO `region_poly2d` (" +
"`region_id`, " +
"`world_id`, " +
"`max_y`, " +
"`min_y` " +
") VALUES (?, " + this.worldDbId + ", ?, ?)"
);
insertPoly2dRegionStatement.setString(1, region.getId().toLowerCase());
insertPoly2dRegionStatement.setInt(2, region.getMaximumPoint().getBlockY());
insertPoly2dRegionStatement.setInt(3, region.getMinimumPoint().getBlockY());
insertPoly2dRegionStatement.setString(1, region.getId().toLowerCase());
insertPoly2dRegionStatement.setInt(2, region.getMaximumPoint().getBlockY());
insertPoly2dRegionStatement.setInt(3, region.getMinimumPoint().getBlockY());
insertPoly2dRegionStatement.execute();
} finally {
closeResource(insertPoly2dRegionStatement);
}
insertPoly2dRegionStatement.execute();
updatePoly2dPoints(region);
}
private void updatePoly2dPoints(ProtectedPolygonalRegion region) throws SQLException {
PreparedStatement clearPoly2dPointsForRegionStatement = null;
PreparedStatement insertPoly2dPointStatement = null;
PreparedStatement clearPoly2dPointsForRegionStatement = this.conn.prepareStatement(
"DELETE FROM `region_poly2d_point` " +
"WHERE `region_id` = ? " +
"AND `world_id` = " + this.worldDbId
);
try {
clearPoly2dPointsForRegionStatement = this.conn.prepareStatement(
"DELETE FROM `region_poly2d_point` " +
"WHERE `region_id` = ? " +
"AND `world_id` = " + this.worldDbId
);
clearPoly2dPointsForRegionStatement.setString(1, region.getId().toLowerCase());
clearPoly2dPointsForRegionStatement.setString(1, region.getId().toLowerCase());
clearPoly2dPointsForRegionStatement.execute();
clearPoly2dPointsForRegionStatement.execute();
PreparedStatement insertPoly2dPointStatement = this.conn.prepareStatement(
"INSERT INTO `region_poly2d_point` (" +
"`id`, " +
"`region_id`, " +
"`world_id`, " +
"`z`, " +
"`x` " +
") VALUES (null, ?, " + this.worldDbId + ", ?, ?)"
);
insertPoly2dPointStatement = this.conn.prepareStatement(
"INSERT INTO `region_poly2d_point` (" +
"`id`, " +
"`region_id`, " +
"`world_id`, " +
"`z`, " +
"`x` " +
") VALUES (null, ?, " + this.worldDbId + ", ?, ?)"
);
String lowerId = region.getId();
for (BlockVector2D point : region.getPoints()) {
insertPoly2dPointStatement.setString(1, lowerId);
insertPoly2dPointStatement.setInt(2, point.getBlockZ());
insertPoly2dPointStatement.setInt(3, point.getBlockX());
String lowerId = region.getId().toLowerCase();
for (BlockVector2D point : region.getPoints()) {
insertPoly2dPointStatement.setString(1, lowerId);
insertPoly2dPointStatement.setInt(2, point.getBlockZ());
insertPoly2dPointStatement.setInt(3, point.getBlockX());
insertPoly2dPointStatement.execute();
}
} finally {
closeResource(clearPoly2dPointsForRegionStatement);
closeResource(insertPoly2dPointStatement);
insertPoly2dPointStatement.execute();
}
}
@@ -1067,20 +947,15 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
}
private void updateRegion(ProtectedRegion region, String type) throws SQLException {
PreparedStatement updateRegionStatement = null;
try {
updateRegionStatement = this.conn.prepareStatement(
"UPDATE `region` SET " +
"`priority` = ? WHERE `id` = ? AND `world_id` = " + this.worldDbId
);
PreparedStatement updateRegionStatement = this.conn.prepareStatement(
"UPDATE `region` SET " +
"`priority` = ? WHERE `id` = ? AND `world_id` = " + this.worldDbId
);
updateRegionStatement.setInt(1, region.getPriority());
updateRegionStatement.setString(2, region.getId().toLowerCase());
updateRegionStatement.setInt(1, region.getPriority());
updateRegionStatement.setString(2, region.getId().toLowerCase());
updateRegionStatement.execute();
} finally {
closeResource(updateRegionStatement);
}
updateRegionStatement.execute();
updateFlags(region);
@@ -1091,58 +966,49 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
private void updateRegionCuboid(ProtectedCuboidRegion region) throws SQLException {
updateRegion(region, "cuboid");
PreparedStatement updateCuboidRegionStatement = null;
try {
updateCuboidRegionStatement = this.conn.prepareStatement(
"UPDATE `region_cuboid` SET " +
"`min_z` = ?, " +
"`min_y` = ?, " +
"`min_x` = ?, " +
"`max_z` = ?, " +
"`max_y` = ?, " +
"`max_x` = ? " +
"WHERE `region_id` = ? " +
"AND `world_id` = " + this.worldDbId
);
PreparedStatement updateCuboidRegionStatement = this.conn.prepareStatement(
"UPDATE `region_cuboid` SET " +
"`min_z` = ?, " +
"`min_y` = ?, " +
"`min_x` = ?, " +
"`max_z` = ?, " +
"`max_y` = ?, " +
"`max_x` = ? " +
"WHERE `region_id` = ? " +
"AND `world_id` = " + this.worldDbId
);
BlockVector min = region.getMinimumPoint();
BlockVector max = region.getMaximumPoint();
BlockVector min = region.getMinimumPoint();
BlockVector max = region.getMaximumPoint();
updateCuboidRegionStatement.setInt(1, min.getBlockZ());
updateCuboidRegionStatement.setInt(2, min.getBlockY());
updateCuboidRegionStatement.setInt(3, min.getBlockX());
updateCuboidRegionStatement.setInt(4, max.getBlockZ());
updateCuboidRegionStatement.setInt(5, max.getBlockY());
updateCuboidRegionStatement.setInt(6, max.getBlockX());
updateCuboidRegionStatement.setString(7, region.getId().toLowerCase());
updateCuboidRegionStatement.setInt(1, min.getBlockZ());
updateCuboidRegionStatement.setInt(2, min.getBlockY());
updateCuboidRegionStatement.setInt(3, min.getBlockX());
updateCuboidRegionStatement.setInt(4, max.getBlockZ());
updateCuboidRegionStatement.setInt(5, max.getBlockY());
updateCuboidRegionStatement.setInt(6, max.getBlockX());
updateCuboidRegionStatement.setString(7, region.getId().toLowerCase());
updateCuboidRegionStatement.execute();
} finally {
closeResource(updateCuboidRegionStatement);
}
updateCuboidRegionStatement.execute();
}
private void updateRegionPoly2D(ProtectedPolygonalRegion region) throws SQLException {
updateRegion(region, "poly2d");
PreparedStatement updatePoly2dRegionStatement = null;
try {
updatePoly2dRegionStatement = this.conn.prepareStatement(
"UPDATE `region_poly2d` SET " +
"`max_y` = ?, " +
"`min_y` = ? " +
"WHERE `region_id` = ? " +
"AND `world_id` = " + this.worldDbId
);
PreparedStatement updatePoly2dRegionStatement = this.conn.prepareStatement(
"UPDATE `region_poly2d` SET " +
"`max_y` = ?, " +
"`min_y` = ? " +
"WHERE `region_id` = ? " +
"AND `world_id` = " + this.worldDbId
);
updatePoly2dRegionStatement.setInt(1, region.getMaximumPoint().getBlockY());
updatePoly2dRegionStatement.setInt(2, region.getMinimumPoint().getBlockY());
updatePoly2dRegionStatement.setString(3, region.getId().toLowerCase());
updatePoly2dRegionStatement.setInt(1, region.getMaximumPoint().getBlockY());
updatePoly2dRegionStatement.setInt(2, region.getMinimumPoint().getBlockY());
updatePoly2dRegionStatement.setString(3, region.getId().toLowerCase());
updatePoly2dRegionStatement.execute();
updatePoly2dRegionStatement.execute();
} finally {
closeResource(updatePoly2dRegionStatement);
}
updatePoly2dPoints(region);
}
@@ -1150,22 +1016,6 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
updateRegion(region, "global");
}
private void closeResource(ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {}
}
}
private void closeResource(Statement st) {
if (st != null) {
try {
st.close();
} catch (SQLException e) {}
}
}
@Override
public Map<String, ProtectedRegion> getRegions() {
return regions;
@@ -1175,7 +1025,7 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
public void setRegions(Map<String, ProtectedRegion> regions) {
this.regions = regions;
}
protected Object sqlUnmarshal(String rawValue) {
try {
return yaml.load(rawValue);
@@ -1183,7 +1033,7 @@ public class MySQLDatabase extends AbstractProtectionDatabase {
return String.valueOf(rawValue);
}
}
protected String sqlMarshal(Object rawObject) {
return yaml.dump(rawObject);
}
@@ -78,7 +78,6 @@ public final class DefaultFlag {
public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter", RegionGroup.ALL);
public static final BooleanFlag NOTIFY_LEAVE = new BooleanFlag("notify-leave", RegionGroup.ALL);
public static final SetFlag<EntityType> DENY_SPAWN = new SetFlag<EntityType>("deny-spawn", RegionGroup.ALL, new EntityTypeFlag(null));
public static final SetFlag<EntityType> DENY_PVM = new SetFlag<EntityType>("deny-pvm", new EntityTypeFlag(null));
public static final EnumFlag<GameMode> GAME_MODE = new EnumFlag<GameMode>("game-mode", GameMode.class, RegionGroup.ALL);
public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay", RegionGroup.ALL);
public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount", RegionGroup.ALL);
@@ -101,7 +100,7 @@ public final class DefaultFlag {
public static final Flag<?>[] flagsList = new Flag<?>[] {
PASSTHROUGH, BUILD, CONSTRUCT, PVP, CHEST_ACCESS, PISTONS,
TNT, LIGHTER, USE, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP,
MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, DENY_PVM, INVINCIBILITY, EXP_DROPS,
MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS,
CREEPER_EXPLOSION, OTHER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD,
GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,
EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY, ENDERPEARL,
@@ -129,30 +129,14 @@ public class ProtectedCuboidRegion extends ProtectedRegion {
*/
@Override
public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> regions) throws UnsupportedIntersectionException {
List<ProtectedRegion> intersectingRegions = new ArrayList<ProtectedRegion>();
for (ProtectedRegion region : regions) {
if (!intersectsBoundingBox(region)) continue;
// If both regions are Cuboids and their bounding boxes intersect, they intersect
if (region instanceof ProtectedCuboidRegion) {
intersectingRegions.add(region);
continue;
} else if (region instanceof ProtectedPolygonalRegion) {
// If either region contains the points of the other,
// or if any edges intersect, the regions intersect
if (containsAny(region.getPoints())
|| region.containsAny(getPoints())
|| intersectsEdges(region)) {
intersectingRegions.add(region);
continue;
}
} else {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean intersectsRegion(ProtectedRegion region) {
if (region instanceof ProtectedPolygonalRegion) {
return intersectsRegionHelper(region);
} else if (region instanceof ProtectedCuboidRegion) {
return intersectsBoundingBox(region);
} else {
throw new UnsupportedOperationException("Not supported yet.");
}
return intersectingRegions;
}
@Override
@@ -23,7 +23,6 @@ import java.util.List;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
public class ProtectedPolygonalRegion extends ProtectedRegion {
@@ -122,30 +121,6 @@ public class ProtectedPolygonalRegion extends ProtectedRegion {
return inside;
}
@Override
public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> regions) throws UnsupportedIntersectionException {
List<ProtectedRegion> intersectingRegions = new ArrayList<ProtectedRegion>();
for (ProtectedRegion region : regions) {
if (!intersectsBoundingBox(region)) continue;
if (region instanceof ProtectedPolygonalRegion || region instanceof ProtectedCuboidRegion) {
// If either region contains the points of the other,
// or if any edges intersect, the regions intersect
if (containsAny(region.getPoints())
|| region.containsAny(getPoints())
|| intersectsEdges(region)) {
intersectingRegions.add(region);
continue;
}
} else {
throw new UnsupportedOperationException("Not supported yet.");
}
}
return intersectingRegions;
}
/**
* Return the type of region as a user-friendly name.
*
@@ -28,6 +28,7 @@ import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
import com.sk89q.worldguard.protection.flags.Flag;
import java.awt.geom.Line2D;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -487,6 +488,24 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
return id.compareTo(other.id);
}
protected boolean intersectsRegionHelper(ProtectedRegion region) {
if (!intersectsBoundingBox(region)) {
return false;
}
// If either region contains the points of the other,
// or if any edges intersect, the regions intersect
return containsAny(region.getPoints()) || region.containsAny(getPoints()) || intersectsEdges(region);
}
public boolean intersectsRegion(ProtectedRegion region) {
if (!(region instanceof ProtectedPolygonalRegion) && (!(region instanceof ProtectedCuboidRegion))) {
throw new UnsupportedOperationException("Not supported yet.");
}
return intersectsRegionHelper(region);
}
/**
* Return the type of region as a user-friendly, lowercase name.
*
@@ -501,9 +520,16 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
* @return The elements of {@code regions} that intersect with this region
* @throws UnsupportedIntersectionException if an invalid intersection is detected
*/
public abstract List<ProtectedRegion> getIntersectingRegions(
List<ProtectedRegion> regions)
throws UnsupportedIntersectionException;
public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> regions) throws UnsupportedIntersectionException {
List<ProtectedRegion> intersectingRegions = new ArrayList<ProtectedRegion>();
for (ProtectedRegion region : regions) {
if (intersectsRegion(region)) {
intersectingRegions.add(region);
}
}
return intersectingRegions;
}
/**
* Checks if the bounding box of a region intersects with with the bounding