Search in sources :

Example 11 with StorageException

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());
        }
    }
}
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 12 with StorageException

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());
        }
    }
}
Also used : RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Example 13 with StorageException

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());
        }
    }
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) BlockVector3(com.sk89q.worldedit.math.BlockVector3) DefaultDomain(com.sk89q.worldguard.domains.DefaultDomain) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet)

Example 14 with StorageException

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());
            }
        }
    }
}
Also used : State(com.sk89q.worldguard.protection.flags.StateFlag.State) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) World(org.bukkit.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) Flag(com.sk89q.worldguard.protection.flags.Flag) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Example 15 with StorageException

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());
        }
    }
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) DefaultDomain(com.sk89q.worldguard.domains.DefaultDomain) 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