Search in sources :

Example 1 with Normal

use of com.sk89q.worldguard.util.Normal in project WorldGuard by EngineHub.

the class RegionContainerImpl method load.

/**
 * Load the {@code RegionManager} for the world with the given name,
 * creating a new instance for the world if one does not exist yet.
 *
 * @param name the name of the world
 * @return a region manager, or {@code null} if loading failed
 */
@Nullable
public RegionManager load(String name) {
    checkNotNull(name);
    Normal normal = Normal.normal(name);
    synchronized (lock) {
        RegionManager manager = mapping.get(normal);
        if (manager != null) {
            return manager;
        } else {
            try {
                manager = createAndLoad(name);
                mapping.put(normal, manager);
                failingLoads.remove(normal);
                return manager;
            } catch (StorageException e) {
                log.log(Level.WARNING, "Failed to load the region data for '" + name + "' (periodic attempts will be made to load the data until success)", e);
                failingLoads.add(normal);
                return null;
            }
        }
    }
}
Also used : Normal(com.sk89q.worldguard.util.Normal) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException) Nullable(javax.annotation.Nullable)

Example 2 with Normal

use of com.sk89q.worldguard.util.Normal in project WorldGuard by EngineHub.

the class RegionContainerImpl method unload.

/**
 * Unload the region manager associated with the given world name.
 *
 * <p>If no region manager has been loaded for the given name, then
 * nothing will happen.</p>
 *
 * @param name the name of the world
 */
public void unload(String name) {
    checkNotNull(name);
    Normal normal = Normal.normal(name);
    synchronized (lock) {
        RegionManager manager = mapping.get(normal);
        if (manager != null) {
            try {
                manager.save();
            } catch (StorageException e) {
                log.log(Level.WARNING, "Failed to save the region data for '" + name + "'", e);
            }
            mapping.remove(normal);
            failingSaves.remove(manager);
        }
        failingLoads.remove(normal);
    }
}
Also used : Normal(com.sk89q.worldguard.util.Normal) StorageException(com.sk89q.worldguard.protection.managers.storage.StorageException)

Aggregations

StorageException (com.sk89q.worldguard.protection.managers.storage.StorageException)2 Normal (com.sk89q.worldguard.util.Normal)2 Nullable (javax.annotation.Nullable)1