Search in sources :

Example 1 with RegionDatabase

use of com.sk89q.worldguard.protection.managers.storage.RegionDatabase in project WorldGuard by EngineHub.

the class DirectoryYamlDriver method getAll.

@Override
public List<RegionDatabase> getAll() throws StorageException {
    List<RegionDatabase> stores = new ArrayList<>();
    File[] files = rootDir.listFiles();
    if (files != null) {
        for (File dir : files) {
            if (dir.isDirectory() && new File(dir, "regions.yml").isFile()) {
                stores.add(new YamlRegionFile(dir.getName(), getPath(dir.getName())));
            }
        }
    }
    return stores;
}
Also used : ArrayList(java.util.ArrayList) RegionDatabase(com.sk89q.worldguard.protection.managers.storage.RegionDatabase) File(java.io.File)

Example 2 with RegionDatabase

use of com.sk89q.worldguard.protection.managers.storage.RegionDatabase in project WorldGuard by EngineHub.

the class DriverMigration method write.

private void write(String name, Set<ProtectedRegion> regions) throws MigrationException {
    log.info("Saving the data for '" + name + "' with the new driver...");
    RegionDatabase store = target.get(name);
    try {
        store.saveAll(regions);
    } catch (StorageException e) {
        throw new MigrationException("Failed to save region data for '" + store.getName() + "' to the new driver", e);
    }
}
Also used : RegionDatabase(com.sk89q.worldguard.protection.managers.storage.RegionDatabase) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Example 3 with RegionDatabase

use of com.sk89q.worldguard.protection.managers.storage.RegionDatabase in project WorldGuard by EngineHub.

the class RegionContainerImpl method createAndLoad.

/**
 * Create a new region manager and load the data.
 *
 * @param name the name of the world
 * @return a region manager
 * @throws StorageException thrown if loading fals
 */
private RegionManager createAndLoad(String name) throws StorageException {
    RegionDatabase store = driver.get(name);
    RegionManager manager = new RegionManager(store, indexFactory, flagRegistry);
    // Try loading, although it may fail
    manager.load();
    return manager;
}
Also used : RegionDatabase(com.sk89q.worldguard.protection.managers.storage.RegionDatabase)

Example 4 with RegionDatabase

use of com.sk89q.worldguard.protection.managers.storage.RegionDatabase in project WorldGuard by EngineHub.

the class SQLDriver method getAll.

@Override
public List<RegionDatabase> getAll() throws StorageException {
    Closer closer = Closer.create();
    try {
        List<RegionDatabase> stores = new ArrayList<>();
        Connection connection = closer.register(getConnection());
        Statement stmt = connection.createStatement();
        ResultSet rs = closer.register(stmt.executeQuery("SELECT name FROM " + config.getTablePrefix() + "world"));
        while (rs.next()) {
            stores.add(get(rs.getString(1)));
        }
        return stores;
    } catch (SQLException e) {
        throw new StorageException("Failed to fetch list of worlds", e);
    } finally {
        closer.closeQuietly();
    }
}
Also used : Closer(com.sk89q.worldguard.util.io.Closer) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) RegionDatabase(com.sk89q.worldguard.protection.managers.storage.RegionDatabase) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Aggregations

RegionDatabase (com.sk89q.worldguard.protection.managers.storage.RegionDatabase)4 StorageException (com.sk89q.worldguard.protection.managers.storage.StorageException)2 ArrayList (java.util.ArrayList)2 Closer (com.sk89q.worldguard.util.io.Closer)1 File (java.io.File)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1