use of com.sk89q.worldguard.protection.managers.storage.StorageException in project TARDIS by eccentricdevotion.
the class TARDISWorldGuardUtils method removeMemberFromRegion.
/**
* Removes a player from a region's membership.
*
* @param world the world the region is located in
* @param owner the player whose region it is
* @param uuid the UUID of the player to remove
*/
public void removeMemberFromRegion(World world, String owner, UUID uuid) {
RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(world));
ProtectedRegion protectedRegion = null;
if (rm.hasRegion("TARDIS_" + owner)) {
protectedRegion = rm.getRegion("TARDIS_" + owner);
} else if (TARDISFloodgate.isFloodgateEnabled()) {
String sanitised = TARDISFloodgate.sanitisePlayerName(owner);
if (rm.hasRegion("TARDIS_" + sanitised)) {
protectedRegion = rm.getRegion("TARDIS_" + sanitised);
}
}
if (protectedRegion != null) {
DefaultDomain members = protectedRegion.getMembers();
members.removePlayer(uuid);
try {
rm.save();
} catch (StorageException e) {
plugin.getLogger().log(Level.INFO, "Could not update WorldGuard flags for everyone entry & exit! " + e.getMessage());
}
}
}
use of com.sk89q.worldguard.protection.managers.storage.StorageException in project TARDIS by eccentricdevotion.
the class TARDISWorldGuardUtils method addWGProtection.
/**
* Adds a WorldGuard protected region to the inner TARDIS location. This stops other players and mobs from griefing
* the TARDIS :)
*
* @param p the player to assign as the owner of the region
* @param one a start location of a cuboid region
* @param two an end location of a cuboid region
*/
public void addWGProtection(Player p, Location one, Location two) {
RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(one.getWorld()));
BlockVector3 b1;
BlockVector3 b2;
int cube = plugin.getConfig().getInt("creation.border_radius") * 16;
if (plugin.getConfig().getBoolean("creation.create_worlds")) {
// make a big cuboid region
b1 = BlockVector3.at(cube, 256, cube);
b2 = BlockVector3.at(-cube, 0, -cube);
} else {
// just get the TARDIS size
b1 = makeBlockVector(one);
b2 = makeBlockVector(two);
}
// check floodgate
String name = (TARDISFloodgate.isFloodgateEnabled() && TARDISFloodgate.isBedrockPlayer(p.getUniqueId())) ? TARDISFloodgate.sanitisePlayerName(p.getName()) : p.getName();
ProtectedCuboidRegion region = new ProtectedCuboidRegion("TARDIS_" + name, b1, b2);
DefaultDomain dd = new DefaultDomain();
dd.addPlayer(p.getName());
region.setOwners(dd);
HashMap<Flag<?>, Object> flags = new HashMap<>();
// flags.put(Flags.TNT, State.DENY);
flags.put(Flags.ENDER_BUILD, State.DENY);
flags.put(Flags.FIRE_SPREAD, State.DENY);
flags.put(Flags.LAVA_FIRE, State.DENY);
flags.put(Flags.LAVA_FLOW, State.DENY);
flags.put(Flags.LIGHTER, State.DENY);
flags.put(Flags.USE, State.ALLOW);
region.setFlags(flags);
rm.addRegion(region);
try {
rm.save();
} catch (StorageException e) {
plugin.getLogger().log(Level.INFO, "Could not create WorldGuard Protection for TARDIS! " + e.getMessage());
}
}
use of com.sk89q.worldguard.protection.managers.storage.StorageException in project WorldGuard by EngineHub.
the class SQLRegionDatabase method loadAll.
@Override
public Set<ProtectedRegion> loadAll(FlagRegistry flagRegistry) throws StorageException {
initialize();
Closer closer = Closer.create();
DataLoader loader;
try {
try {
loader = new DataLoader(this, closer.register(getConnection()), flagRegistry);
} catch (SQLException e) {
throw new StorageException("Failed to get a connection to the database", e);
}
try {
return loader.load();
} catch (SQLException e) {
throw new StorageException("Failed to save the region data to the database", e);
}
} finally {
closer.closeQuietly();
}
}
use of com.sk89q.worldguard.protection.managers.storage.StorageException in project WorldGuard by EngineHub.
the class SQLRegionDatabase method saveChanges.
@Override
public void saveChanges(RegionDifference difference) throws DifferenceSaveException, StorageException {
checkNotNull(difference);
initialize();
Closer closer = Closer.create();
DataUpdater updater;
try {
try {
updater = new DataUpdater(this, closer.register(getConnection()));
} catch (SQLException e) {
throw new StorageException("Failed to get a connection to the database", e);
}
try {
updater.saveChanges(difference.getChanged(), difference.getRemoved());
} catch (SQLException e) {
throw new StorageException("Failed to save the region data to the database", e);
}
} finally {
closer.closeQuietly();
}
}
use of com.sk89q.worldguard.protection.managers.storage.StorageException in project WorldGuard by EngineHub.
the class WorldHeightMigration method migrate.
@Override
protected void migrate(RegionDatabase store) throws MigrationException {
if (world != null && !store.getName().equals(world.getName()))
return;
log.log(Level.INFO, "Migrating regions in '" + store.getName() + "' to new height limits...");
Set<ProtectedRegion> regions;
try {
regions = store.loadAll(flagRegistry);
} catch (StorageException e) {
throw new MigrationException("Failed to load region data for the world '" + store.getName() + "'", e);
}
int min = -64;
int max = 319;
World world = WorldGuard.getInstance().getPlatform().getMatcher().getWorldByName(store.getName());
if (world != null) {
min = world.getMinY();
max = world.getMaxY();
// at the old defaults...? either way if this is the case there are no changes to make.
if (min == 0 && max == 255)
return;
}
for (ProtectedRegion region : regions) {
if (region.getMinimumPoint().getBlockY() <= 0 && region.getMaximumPoint().getBlockY() >= 255) {
expand(region, min, max);
changed++;
}
}
try {
store.saveAll(regions);
} catch (StorageException e) {
throw new MigrationException("Failed to save region data after migration of the world '" + store.getName() + "'", e);
}
}
Aggregations