Search in sources :

Example 21 with StorageException

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 world the world the region is located in
 * @param name  the player's name
 */
public void removeRegion(World world, String name) {
    RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(world));
    Set<ProtectedRegion> regions = rm.removeRegion("TARDIS_" + name);
    if (regions.size() == 0 && TARDISFloodgate.isFloodgateEnabled()) {
        // try sanitised name
        rm.removeRegion("TARDIS_" + TARDISFloodgate.sanitisePlayerName(name));
    }
    try {
        rm.save();
    } catch (StorageException e) {
        plugin.getLogger().log(Level.INFO, "Could not remove WorldGuard Protection for TARDIS! " + e.getMessage());
    }
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Example 22 with StorageException

use of com.sk89q.worldguard.protection.managers.storage.StorageException in project TARDIS by eccentricdevotion.

the class TARDISWorldGuardUtils method addWGProtection.

/**
 * Adds a WorldGuard protected region for a TIPS slot. This stops other players and mobs from griefing the TARDIS
 * :)
 *
 * @param name  the player to assign as the owner of the region
 * @param data  a TIPS Data container
 * @param world the world we are creating the region in
 */
public void addWGProtection(UUID uuid, String name, TARDISTIPSData data, World world) {
    RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(world));
    BlockVector3 b1 = BlockVector3.at(data.getMinX(), 0, data.getMinZ());
    BlockVector3 b2 = BlockVector3.at(data.getMaxX(), 256, data.getMaxZ());
    String region_id = "TARDIS_" + name;
    ProtectedCuboidRegion region = new ProtectedCuboidRegion(region_id, b1, b2);
    DefaultDomain dd = new DefaultDomain();
    dd.addPlayer(uuid);
    region.setOwners(dd);
    HashMap<Flag<?>, Object> flags = new HashMap<>();
    if (name.length() != 36 && !plugin.getConfig().getBoolean("preferences.open_door_policy")) {
        flags.put(Flags.ENTRY, 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);
    // deny exit to all
    // usage = "<id> <flag> [-w world] [-g group] [value]",
    plugin.getServer().dispatchCommand(plugin.getConsole(), "rg flag " + region_id + " exit -w " + world.getName() + " deny");
    try {
        rm.save();
    } catch (StorageException e) {
        plugin.getLogger().log(Level.INFO, "Could not create WorldGuard Protection for TARDIS! " + e.getMessage());
    }
}
Also used : RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) DefaultDomain(com.sk89q.worldguard.domains.DefaultDomain) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) Flag(com.sk89q.worldguard.protection.flags.Flag) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Example 23 with StorageException

use of com.sk89q.worldguard.protection.managers.storage.StorageException in project TARDIS by eccentricdevotion.

the class TARDISWorldGuardUtils method removeRechargerRegion.

/**
 * Removes the WorldGuard region when the recharger is removed.
 *
 * @param name the name of the recharger to remove
 */
public void removeRechargerRegion(String name) {
    World w = TARDISAliasResolver.getWorldFromAlias(plugin.getConfig().getString("rechargers." + name + ".world"));
    RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(w));
    rm.removeRegion("tardis_recharger_" + name);
    try {
        rm.save();
    } catch (StorageException e) {
        plugin.getLogger().log(Level.INFO, "Could not remove recharger WorldGuard Protection for recharger! " + e.getMessage());
    }
}
Also used : RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) World(org.bukkit.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Example 24 with StorageException

use of com.sk89q.worldguard.protection.managers.storage.StorageException in project TARDIS by eccentricdevotion.

the class TARDISWorldGuardUtils method unlockContainers.

/**
 * Sets a player's CHEST_ACCESS flag to ALLOW in their TARDIS region.
 *
 * @param world the world the region is located in
 * @param owner the player whose region it is
 */
public void unlockContainers(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.ALLOW);
        region.setFlag(Flags.CHEST_ACCESS.getRegionGroupFlag(), RegionGroup.ALL);
        try {
            rm.save();
        } catch (StorageException e) {
            plugin.getLogger().log(Level.INFO, "Could not set WorldGuard CHEST_ACCESS flag to ALLOW! " + e.getMessage());
        }
    }
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Example 25 with StorageException

use of com.sk89q.worldguard.protection.managers.storage.StorageException in project TARDIS by eccentricdevotion.

the class TARDISWorldGuardUtils method addWGProtection.

/**
 * Adds a WorldGuard protected region for a TIPS slot. This stops other players and mobs from griefing the TARDIS
 * :)
 *
 * @param player the player to assign as the owner of the region
 * @param data   a TIPS Data container
 * @param world  the world we are creating the region in
 */
public void addWGProtection(Player player, TARDISTIPSData data, World world, boolean junk) {
    RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(world));
    BlockVector3 b1 = BlockVector3.at(data.getMinX(), 0, data.getMinZ());
    BlockVector3 b2 = BlockVector3.at(data.getMaxX(), 256, data.getMaxZ());
    UUID uuid;
    String name;
    if (junk) {
        uuid = UUID.fromString("00000000-aaaa-bbbb-cccc-000000000000");
        name = "junk";
    } else {
        uuid = player.getUniqueId();
        // check floodgate for region name
        name = (TARDISFloodgate.isFloodgateEnabled() && TARDISFloodgate.isBedrockPlayer(player.getUniqueId())) ? TARDISFloodgate.sanitisePlayerName(player.getName()) : player.getName();
    }
    String region_id = "TARDIS_" + name;
    ProtectedCuboidRegion region = new ProtectedCuboidRegion(region_id, b1, b2);
    DefaultDomain dd = new DefaultDomain();
    dd.addPlayer(uuid);
    region.setOwners(dd);
    HashMap<Flag<?>, Object> flags = new HashMap<>();
    if (!junk && !plugin.getConfig().getBoolean("preferences.open_door_policy")) {
        flags.put(Flags.ENTRY, 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);
    if (!junk) {
        // deny exit to all
        // usage = "<id> <flag> [-w world] [-g group] [value]",
        plugin.getServer().dispatchCommand(plugin.getConsole(), "rg flag " + region_id + " exit -w " + world.getName() + " deny");
    }
    try {
        rm.save();
    } catch (StorageException e) {
        plugin.getLogger().log(Level.INFO, "Could not create WorldGuard Protection for TARDIS! " + e.getMessage());
    }
}
Also used : RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) DefaultDomain(com.sk89q.worldguard.domains.DefaultDomain) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) Flag(com.sk89q.worldguard.protection.flags.Flag) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Aggregations

StorageException (com.sk89q.worldguard.protection.managers.storage.StorageException)31 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)19 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)16 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)15 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)9 DefaultDomain (com.sk89q.worldguard.domains.DefaultDomain)9 ProtectedCuboidRegion (com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion)9 Flag (com.sk89q.worldguard.protection.flags.Flag)6 StateFlag (com.sk89q.worldguard.protection.flags.StateFlag)6 Closer (com.sk89q.worldguard.util.io.Closer)5 SQLException (java.sql.SQLException)5 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)3 ProtectedPolygonalRegion (com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion)3 HashMap (java.util.HashMap)3 World (org.bukkit.World)3 YAMLNode (com.sk89q.util.yaml.YAMLNode)2 YAMLProcessor (com.sk89q.util.yaml.YAMLProcessor)2 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)2 ApplicableRegionSet (com.sk89q.worldguard.protection.ApplicableRegionSet)2 RegionDatabase (com.sk89q.worldguard.protection.managers.storage.RegionDatabase)2