Search in sources :

Example 26 with StorageException

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

Example 27 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 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());
    }
}
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 28 with StorageException

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();
    }
}
Also used : Closer(com.sk89q.worldguard.util.io.Closer) SQLException(java.sql.SQLException) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Example 29 with StorageException

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();
    }
}
Also used : Closer(com.sk89q.worldguard.util.io.Closer) SQLException(java.sql.SQLException) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Example 30 with StorageException

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);
    }
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) World(com.sk89q.worldedit.world.World) 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