Search in sources :

Example 1 with UUIDMigration

use of com.sk89q.worldguard.protection.managers.migration.UUIDMigration in project WorldGuard by EngineHub.

the class RegionContainer method autoMigrate.

/**
 * Execute auto-migration.
 */
protected void autoMigrate() {
    ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
    if (config.migrateRegionsToUuid) {
        RegionDriver driver = getDriver();
        UUIDMigration migrator = new UUIDMigration(driver, WorldGuard.getInstance().getProfileService(), WorldGuard.getInstance().getFlagRegistry());
        migrator.setKeepUnresolvedNames(config.keepUnresolvedNames);
        try {
            migrate(migrator);
            WorldGuard.logger.info("Regions saved after UUID migration! This won't happen again unless " + "you change the relevant configuration option in WorldGuard's config.");
            config.disableUuidMigration();
        } catch (MigrationException e) {
            WorldGuard.logger.log(Level.WARNING, "Failed to execute the migration", e);
        }
    }
}
Also used : MigrationException(com.sk89q.worldguard.protection.managers.migration.MigrationException) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) UUIDMigration(com.sk89q.worldguard.protection.managers.migration.UUIDMigration)

Example 2 with UUIDMigration

use of com.sk89q.worldguard.protection.managers.migration.UUIDMigration in project WorldGuard by EngineHub.

the class RegionCommands method migrateUuid.

/**
 * Migrate the region databases to use UUIDs rather than name.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "migrateuuid" }, desc = "Migrate loaded databases to use UUIDs", max = 0)
public void migrateUuid(CommandContext args, Actor sender) throws CommandException {
    // Check permissions
    if (!getPermissionModel(sender).mayMigrateRegionNames()) {
        throw new CommandPermissionsException();
    }
    LoggerToChatHandler handler = null;
    Logger minecraftLogger = null;
    if (sender instanceof LocalPlayer) {
        handler = new LoggerToChatHandler(sender);
        handler.setLevel(Level.ALL);
        minecraftLogger = Logger.getLogger("com.sk89q.worldguard");
        minecraftLogger.addHandler(handler);
    }
    try {
        ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
        RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
        RegionDriver driver = container.getDriver();
        UUIDMigration migration = new UUIDMigration(driver, WorldGuard.getInstance().getProfileService(), WorldGuard.getInstance().getFlagRegistry());
        migration.setKeepUnresolvedNames(config.keepUnresolvedNames);
        sender.print("Now performing migration... this may take a while.");
        container.migrate(migration);
        sender.print("Migration complete!");
    } catch (MigrationException e) {
        log.log(Level.WARNING, "Failed to migrate", e);
        throw new CommandException("Error encountered while migrating: " + e.getMessage());
    } finally {
        if (minecraftLogger != null) {
            minecraftLogger.removeHandler(handler);
        }
    }
}
Also used : MigrationException(com.sk89q.worldguard.protection.managers.migration.MigrationException) LoggerToChatHandler(com.sk89q.worldguard.util.logging.LoggerToChatHandler) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) RegionContainer(com.sk89q.worldguard.protection.regions.RegionContainer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandException(com.sk89q.minecraft.util.commands.CommandException) Logger(java.util.logging.Logger) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) UUIDMigration(com.sk89q.worldguard.protection.managers.migration.UUIDMigration) Command(com.sk89q.minecraft.util.commands.Command)

Aggregations

ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)2 MigrationException (com.sk89q.worldguard.protection.managers.migration.MigrationException)2 UUIDMigration (com.sk89q.worldguard.protection.managers.migration.UUIDMigration)2 RegionDriver (com.sk89q.worldguard.protection.managers.storage.RegionDriver)2 Command (com.sk89q.minecraft.util.commands.Command)1 CommandException (com.sk89q.minecraft.util.commands.CommandException)1 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)1 LocalPlayer (com.sk89q.worldguard.LocalPlayer)1 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)1 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)1 Logger (java.util.logging.Logger)1