use of com.sk89q.worldguard.protection.managers.storage.StorageException in project TARDIS by eccentricdevotion.
the class TARDISWorldGuardUtils method lockContainers.
/**
* Sets a player's CHEST_ACCESS flag to DENY in their TARDIS region.
*
* @param world the world the region is located in
* @param owner the player whose region it is
*/
public void lockContainers(World world, String owner) {
RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(world));
ProtectedRegion region = null;
if (rm.hasRegion("TARDIS_" + owner)) {
region = rm.getRegion("TARDIS_" + owner);
} else if (TARDISFloodgate.isFloodgateEnabled()) {
String sanitised = TARDISFloodgate.sanitisePlayerName(owner);
if (rm.hasRegion("TARDIS_" + sanitised)) {
region = rm.getRegion("TARDIS_" + sanitised);
}
}
if (region != null) {
region.setFlag(Flags.CHEST_ACCESS, State.DENY);
region.setFlag(Flags.CHEST_ACCESS.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
try {
rm.save();
} catch (StorageException e) {
plugin.getLogger().log(Level.INFO, "Could not set WorldGuard CHEST_ACCESS flag to DENY! " + e.getMessage());
}
}
}
use of com.sk89q.worldguard.protection.managers.storage.StorageException in project TARDIS by eccentricdevotion.
the class TARDISWorldGuardUtils method removeRoomRegion.
/**
* Removes the exterior rendering room region when the room is jettisoned or the TARDIS is deleted.
*
* @param world the world the region is located in
* @param name the player's name
* @param room the room region to remove
*/
public void removeRoomRegion(World world, String name, String room) {
boolean save = false;
RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(world));
if (rm.hasRegion(room + "_" + name)) {
rm.removeRegion(room + "_" + name);
save = true;
} else if (TARDISFloodgate.isFloodgateEnabled()) {
String sanitised = TARDISFloodgate.sanitisePlayerName(name);
if (rm.hasRegion(room + "_" + sanitised)) {
rm.removeRegion(room + "_" + sanitised);
save = true;
}
}
if (save) {
try {
rm.save();
} catch (StorageException e) {
plugin.getLogger().log(Level.INFO, "Could not remove WorldGuard Protection for " + room + " room! " + e.getMessage());
}
}
}
use of com.sk89q.worldguard.protection.managers.storage.StorageException in project TARDIS by eccentricdevotion.
the class TARDISWorldGuardUtils method updateRegionForClaim.
/**
* Updates the TARDIS WorldGuard region when the TARDIS has been claimed by a new player.
*
* @param location the TARDIS interior location
* @param uuid the UUID of the player
*/
public void updateRegionForClaim(Location location, UUID uuid) {
RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(location.getWorld()));
BlockVector3 vector = BlockVector3.at(location.getX(), location.getY(), location.getZ());
ApplicableRegionSet ars = rm.getApplicableRegions(vector);
if (ars.size() > 0) {
LinkedList<String> parentNames = new LinkedList<>();
LinkedList<String> regions = new LinkedList<>();
for (ProtectedRegion pr : ars) {
String id = pr.getId();
regions.add(id);
ProtectedRegion parent = pr.getParent();
while (parent != null) {
parentNames.add(parent.getId());
parent = parent.getParent();
}
}
parentNames.forEach(regions::remove);
String region = regions.getFirst();
ProtectedRegion pr = rm.getRegion(region);
pr.setFlag(Flags.ENTRY, State.DENY);
DefaultDomain dd = pr.getOwners();
dd.addPlayer(uuid);
pr.setOwners(dd);
try {
rm.save();
} catch (StorageException e) {
plugin.getLogger().log(Level.INFO, "Could not update WorldGuard Protection for abandoned TARDIS claim! " + e.getMessage());
}
}
}
use of com.sk89q.worldguard.protection.managers.storage.StorageException in project TARDIS by eccentricdevotion.
the class TARDISWorldGuardUtils method setEntryExitFlags.
/**
* Sets the entry and exit flags for a region.
*
* @param world the world in which the region is located
* @param owner the player who owns the region
* @param allow whether the flag state should be set to allow or deny
*/
public void setEntryExitFlags(String world, String owner, boolean allow) {
World w = TARDISAliasResolver.getWorldFromAlias(world);
ProtectedRegion region = null;
if (w != null) {
RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(w));
if (rm.hasRegion("TARDIS_" + owner)) {
region = rm.getRegion("TARDIS_" + owner);
} else if (TARDISFloodgate.isFloodgateEnabled()) {
String sanitised = TARDISFloodgate.sanitisePlayerName(owner);
if (rm.hasRegion("TARDIS_" + sanitised)) {
region = rm.getRegion("TARDIS_" + sanitised);
}
}
// always allow region entry if open door policy is true
State flag = (allow || plugin.getConfig().getBoolean("preferences.open_door_policy")) ? State.ALLOW : State.DENY;
if (region != null) {
Map<Flag<?>, Object> flags = region.getFlags();
flags.put(Flags.ENTRY, flag);
flags.put(Flags.EXIT, flag);
region.setFlags(flags);
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 updateRegionForNameChange.
/**
* Updates the TARDIS WorldGuard region when the player name has changed.
*
* @param world the world the region is located in
* @param owner the owner's name
* @param uuid the UUID of the player
* @param which the region type to update
*/
public void updateRegionForNameChange(World world, String owner, UUID uuid, String which) {
RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(world));
String region = which + "_" + owner;
if (rm.hasRegion(region)) {
ProtectedRegion pr = rm.getRegion(region);
DefaultDomain dd = pr.getOwners();
dd.addPlayer(uuid);
pr.setOwners(dd);
try {
rm.save();
} catch (StorageException e) {
plugin.getLogger().log(Level.INFO, "Could not update WorldGuard Protection for TARDIS owner name change! " + e.getMessage());
}
}
}
Aggregations