use of com.sk89q.worldguard.protection.managers.storage.StorageException in project TARDIS by eccentricdevotion.
the class TARDISWorldGuardUtils method addRendererProtection.
/**
* Adds a WorldGuard protected region to exterior renderer room.
*
* @param name the name of the player growing the render room
* @param one a start location of a cuboid region
* @param two an end location of a cuboid region
*/
public void addRendererProtection(String name, Location one, Location two) {
RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(one.getWorld()));
BlockVector3 b1;
BlockVector3 b2;
b1 = makeBlockVector(one);
b2 = makeBlockVector(two);
if (TARDISFloodgate.isFloodgateEnabled()) {
name = TARDISFloodgate.sanitisePlayerName(name);
}
ProtectedCuboidRegion region = new ProtectedCuboidRegion("renderer_" + name, b1, b2);
HashMap<Flag<?>, Object> flags = new HashMap<>();
flags.put(Flags.TNT, State.DENY);
flags.put(Flags.CREEPER_EXPLOSION, 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.LEAF_DECAY, State.DENY);
region.setFlags(flags);
rm.addRegion(region);
try {
rm.save();
} catch (StorageException e) {
plugin.getLogger().log(Level.INFO, "Could not create WorldGuard Protection for exterior renderering room! " + e.getMessage());
}
}
use of com.sk89q.worldguard.protection.managers.storage.StorageException in project ProtectionStones by espidev.
the class LegacyUpgrade method upgradeRegionsWithNegativeYValues.
// upgrade to 1.17, upgrade regions with 0->256 to SHORT_MIN->SHORT_MAX
public static void upgradeRegionsWithNegativeYValues() {
ProtectionStones.getInstance().getLogger().info("Upgrading region y-values for 1.17...");
for (RegionManager rgm : WGUtils.getAllRegionManagers().values()) {
List<ProtectedRegion> newRegions = new ArrayList<>();
// loop through each region
for (var region : rgm.getRegions().values()) {
int minY = region.getMinimumPoint().getBlockY(), maxY = region.getMaximumPoint().getBlockY();
if (ProtectionStones.isPSRegion(region) && minY == 0 && maxY == 256) {
// clone region, and recreate with new min/max points
ProtectedRegion toAdd = null;
if (region instanceof ProtectedPolygonalRegion) {
// convert merged region
toAdd = new ProtectedPolygonalRegion(region.getId(), region.getPoints(), WGUtils.MIN_BUILD_HEIGHT, WGUtils.MAX_BUILD_HEIGHT);
} else if (region instanceof ProtectedCuboidRegion) {
// convert standard region
BlockVector3 minVec = BlockVector3.at(region.getMinimumPoint().getX(), WGUtils.MIN_BUILD_HEIGHT, region.getMinimumPoint().getZ()), maxVec = BlockVector3.at(region.getMaximumPoint().getX(), WGUtils.MAX_BUILD_HEIGHT, region.getMaximumPoint().getZ());
toAdd = new ProtectedCuboidRegion(region.getId(), minVec, maxVec);
}
if (toAdd != null) {
ProtectionStones.getInstance().getLogger().info("Updated region " + region.getId());
// copy region settings
toAdd.copyFrom(region);
newRegions.add(toAdd);
}
} else {
newRegions.add(region);
}
}
rgm.setRegions(newRegions);
try {
rgm.save();
} catch (StorageException e) {
e.printStackTrace();
}
}
// update config to mark that uuid upgrade has been done
ProtectionStones.config.set("region_negative_min_max_updated", true);
ProtectionStones.config.save();
ProtectionStones.getInstance().getLogger().info("Finished!");
}
use of com.sk89q.worldguard.protection.managers.storage.StorageException in project Plot-System by AlpsBTE.
the class AbstractPlotGenerator method createProtection.
/**
* Creates plot protection
*/
protected void createProtection() {
BlockVector min = BlockVector.toBlockPoint(0, 1, 0);
BlockVector max = BlockVector.toBlockPoint(PlotManager.PLOT_SIZE, 256, PlotManager.PLOT_SIZE);
RegionContainer container = PlotSystem.DependencyManager.getWorldGuard().getRegionContainer();
RegionManager regionManager = container.get(plot.getWorld().getBukkitWorld());
// Create protected region for world
GlobalProtectedRegion globalRegion = new GlobalProtectedRegion("__global__");
globalRegion.setFlag(DefaultFlag.ENTRY, StateFlag.State.DENY);
globalRegion.setFlag(DefaultFlag.ENTRY.getRegionGroupFlag(), RegionGroup.ALL);
// Create protected region for plot
ProtectedRegion protectedPlotRegion = new ProtectedCuboidRegion(plot.getWorld().getWorldName(), min, max);
protectedPlotRegion.setPriority(100);
// Add and save regions
try {
if (regionManager != null) {
regionManager.addRegion(globalRegion);
regionManager.addRegion(protectedPlotRegion);
regionManager.saveChanges();
} else {
throw new RuntimeException("Region Manager is null");
}
} catch (StorageException ex) {
Bukkit.getLogger().log(Level.SEVERE, "An error occurred while saving plot protection!", ex);
throw new RuntimeException("Plot protection creation completed exceptionally");
}
// Add plot owner
DefaultDomain owner = protectedPlotRegion.getOwners();
owner.addPlayer(builder.getUUID());
protectedPlotRegion.setOwners(owner);
// Set permissions
protectedPlotRegion.setFlag(DefaultFlag.PASSTHROUGH, StateFlag.State.ALLOW);
protectedPlotRegion.setFlag(DefaultFlag.PASSTHROUGH.getRegionGroupFlag(), RegionGroup.OWNERS);
protectedPlotRegion.setFlag(DefaultFlag.ENTRY, StateFlag.State.ALLOW);
protectedPlotRegion.setFlag(DefaultFlag.ENTRY.getRegionGroupFlag(), RegionGroup.ALL);
FileConfiguration config = PlotSystem.getPlugin().getConfigManager().getCommandsConfig();
List<String> allowedCommandsNonBuilder = config.getStringList(ConfigPaths.ALLOWED_COMMANDS_NON_BUILDERS);
allowedCommandsNonBuilder.removeIf(c -> c.equals("/cmd1"));
for (BaseCommand baseCommand : PlotSystem.getPlugin().getCommandManager().getBaseCommands()) {
allowedCommandsNonBuilder.addAll(Arrays.asList(baseCommand.getNames()));
for (String command : baseCommand.getNames()) {
allowedCommandsNonBuilder.add("/" + command);
}
}
List<String> blockedCommandsBuilders = config.getStringList(ConfigPaths.BLOCKED_COMMANDS_BUILDERS);
blockedCommandsBuilders.removeIf(c -> c.equals("/cmd1"));
protectedPlotRegion.setFlag(DefaultFlag.BLOCKED_CMDS, new HashSet<>(blockedCommandsBuilders));
protectedPlotRegion.setFlag(DefaultFlag.BLOCKED_CMDS.getRegionGroupFlag(), RegionGroup.OWNERS);
protectedPlotRegion.setFlag(DefaultFlag.ALLOWED_CMDS, new HashSet<>(allowedCommandsNonBuilder));
protectedPlotRegion.setFlag(DefaultFlag.ALLOWED_CMDS.getRegionGroupFlag(), RegionGroup.NON_OWNERS);
}
use of com.sk89q.worldguard.protection.managers.storage.StorageException in project TARDIS by eccentricdevotion.
the class TARDISWorldGuardUtils method addMemberToRegion.
/**
* Adds a player to a region's membership.
*
* @param w the world the region is located in
* @param owner the player whose region it is
* @param uuid the UUID of the player to add
*/
public void addMemberToRegion(World w, String owner, UUID uuid) {
RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(w));
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.addPlayer(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 removeRegion.
/**
* Removes the WorldGuard region when the TARDIS is deleted.
*
* @param l the TARDIS interior location
*/
public void removeRegion(Location l) {
RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(l.getWorld()));
BlockVector3 vector = BlockVector3.at(l.getX(), l.getY(), l.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);
rm.removeRegion(regions.getFirst());
try {
rm.save();
} catch (StorageException e) {
plugin.getLogger().log(Level.INFO, "Could not remove WorldGuard Protection for TARDIS! " + e.getMessage());
}
} else {
plugin.getLogger().log(Level.INFO, "Could not get WorldGuard region for TARDIS location!");
}
}
Aggregations