Search in sources :

Example 1 with WorldHeightMigration

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

the class RegionCommands method migrateHeights.

/**
 * Migrate regions that went from 0-255 to new world heights.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "migrateheights" }, usage = "[world]", max = 1, flags = "yw:", desc = "Migrate regions from old height limits to new height limits")
public void migrateHeights(CommandContext args, Actor sender) throws CommandException {
    // Check permissions
    if (!getPermissionModel(sender).mayMigrateRegionHeights()) {
        throw new CommandPermissionsException();
    }
    if (!args.hasFlag('y')) {
        throw new CommandException("This command is potentially dangerous.\n" + "Please ensure you have made a backup of your data, and then re-enter the command with -y tacked on at the end to proceed.");
    }
    World world = null;
    try {
        world = checkWorld(args, sender, 'w');
    } catch (CommandException ignored) {
    }
    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 {
        RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
        RegionDriver driver = container.getDriver();
        WorldHeightMigration migration = new WorldHeightMigration(driver, WorldGuard.getInstance().getFlagRegistry(), world);
        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) WorldHeightMigration(com.sk89q.worldguard.protection.managers.migration.WorldHeightMigration) 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) World(com.sk89q.worldedit.world.World) Logger(java.util.logging.Logger) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) Command(com.sk89q.minecraft.util.commands.Command)

Aggregations

Command (com.sk89q.minecraft.util.commands.Command)1 CommandException (com.sk89q.minecraft.util.commands.CommandException)1 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)1 World (com.sk89q.worldedit.world.World)1 LocalPlayer (com.sk89q.worldguard.LocalPlayer)1 MigrationException (com.sk89q.worldguard.protection.managers.migration.MigrationException)1 WorldHeightMigration (com.sk89q.worldguard.protection.managers.migration.WorldHeightMigration)1 RegionDriver (com.sk89q.worldguard.protection.managers.storage.RegionDriver)1 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)1 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)1 Logger (java.util.logging.Logger)1