Search in sources :

Example 1 with DriverType

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

the class RegionCommands method migrateDB.

/**
 * Migrate the region database.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "migratedb" }, usage = "<from> <to>", flags = "y", desc = "Migrate from one Protection Database to another.", min = 2, max = 2)
public void migrateDB(CommandContext args, Actor sender) throws CommandException {
    // Check permissions
    if (!getPermissionModel(sender).mayMigrateRegionStore()) {
        throw new CommandPermissionsException();
    }
    DriverType from = Enums.findFuzzyByValue(DriverType.class, args.getString(0));
    DriverType to = Enums.findFuzzyByValue(DriverType.class, args.getString(1));
    if (from == null) {
        throw new CommandException("The value of 'from' is not a recognized type of region data database.");
    }
    if (to == null) {
        throw new CommandException("The value of 'to' is not a recognized type of region region data database.");
    }
    if (from == to) {
        throw new CommandException("It is not possible to migrate between the same types of region data databases.");
    }
    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.");
    }
    ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
    RegionDriver fromDriver = config.regionStoreDriverMap.get(from);
    RegionDriver toDriver = config.regionStoreDriverMap.get(to);
    if (fromDriver == null) {
        throw new CommandException("The driver specified as 'from' does not seem to be supported in your version of WorldGuard.");
    }
    if (toDriver == null) {
        throw new CommandException("The driver specified as 'to' does not seem to be supported in your version of WorldGuard.");
    }
    DriverMigration migration = new DriverMigration(fromDriver, toDriver, WorldGuard.getInstance().getFlagRegistry());
    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();
        sender.print("Now performing migration... this may take a while.");
        container.migrate(migration);
        sender.print("Migration complete! This only migrated the data. If you already changed your settings to use " + "the target driver, then WorldGuard is now using the new data. If not, you have to adjust your " + "configuration to use the new driver and then restart your server.");
    } 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) DriverMigration(com.sk89q.worldguard.protection.managers.migration.DriverMigration) RegionContainer(com.sk89q.worldguard.protection.regions.RegionContainer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandException(com.sk89q.minecraft.util.commands.CommandException) DriverType(com.sk89q.worldguard.protection.managers.storage.DriverType) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) Logger(java.util.logging.Logger) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) Command(com.sk89q.minecraft.util.commands.Command)

Example 2 with DriverType

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

the class YamlConfigurationManager method load.

@Override
public void load() {
    copyDefaults();
    config = new YAMLProcessor(new File(getDataFolder(), "config.yml"), true, YAMLFormat.EXTENDED);
    try {
        config.load();
    } catch (IOException e) {
        log.severe("Error reading configuration for global config: ");
        e.printStackTrace();
    }
    config.removeProperty("suppress-tick-sync-warnings");
    migrateRegionsToUuid = config.getBoolean("regions.uuid-migration.perform-on-next-start", true);
    keepUnresolvedNames = config.getBoolean("regions.uuid-migration.keep-names-that-lack-uuids", true);
    useRegionsCreatureSpawnEvent = config.getBoolean("regions.use-creature-spawn-event", true);
    disableDefaultBypass = config.getBoolean("regions.disable-bypass-by-default", false);
    announceBypassStatus = config.getBoolean("regions.announce-bypass-status", false);
    useGodPermission = config.getBoolean("auto-invincible", config.getBoolean("auto-invincible-permission", false));
    useGodGroup = config.getBoolean("auto-invincible-group", false);
    useAmphibiousGroup = config.getBoolean("auto-no-drowning-group", false);
    config.removeProperty("auto-invincible-permission");
    usePlayerMove = config.getBoolean("use-player-move-event", true);
    usePlayerTeleports = config.getBoolean("use-player-teleports", true);
    particleEffects = config.getBoolean("use-particle-effects", true);
    disablePermissionCache = config.getBoolean("disable-permission-cache", false);
    deopOnJoin = config.getBoolean("security.deop-everyone-on-join", false);
    blockInGameOp = config.getBoolean("security.block-in-game-op-command", false);
    hostKeys = new HashMap<>();
    Object hostKeysRaw = config.getProperty("host-keys");
    if (!(hostKeysRaw instanceof Map)) {
        config.setProperty("host-keys", new HashMap<String, String>());
    } else {
        for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) hostKeysRaw).entrySet()) {
            String key = String.valueOf(entry.getKey());
            String value = String.valueOf(entry.getValue());
            hostKeys.put(key.toLowerCase(), value);
        }
    }
    hostKeysAllowFMLClients = config.getBoolean("security.host-keys-allow-forge-clients", false);
    // ====================================================================
    // Region store drivers
    // ====================================================================
    boolean useSqlDatabase = config.getBoolean("regions.sql.use", false);
    String sqlDsn = config.getString("regions.sql.dsn", "jdbc:mysql://localhost/worldguard");
    String sqlUsername = config.getString("regions.sql.username", "worldguard");
    String sqlPassword = config.getString("regions.sql.password", "worldguard");
    String sqlTablePrefix = config.getString("regions.sql.table-prefix", "");
    if (!useSqlDatabase) {
        config.removeProperty("regions.sql");
    } else {
        log.warning("SQL support for WorldGuard region storage is deprecated for removal in a future version. Please migrate to YAML storage.");
        log.warning("For details, see https://worldguard.enginehub.org/en/latest/regions/storage/");
    }
    DataSourceConfig dataSourceConfig = new DataSourceConfig(sqlDsn, sqlUsername, sqlPassword, sqlTablePrefix);
    SQLDriver sqlDriver = new SQLDriver(dataSourceConfig);
    DirectoryYamlDriver yamlDriver = new DirectoryYamlDriver(getWorldsDataFolder(), "regions.yml");
    this.regionStoreDriverMap = ImmutableMap.<DriverType, RegionDriver>builder().put(DriverType.MYSQL, sqlDriver).put(DriverType.YAML, yamlDriver).build();
    this.selectedRegionStoreDriver = useSqlDatabase ? sqlDriver : yamlDriver;
    postLoad();
    config.setHeader(CONFIG_HEADER);
}
Also used : DirectoryYamlDriver(com.sk89q.worldguard.protection.managers.storage.file.DirectoryYamlDriver) DataSourceConfig(com.sk89q.worldguard.util.sql.DataSourceConfig) IOException(java.io.IOException) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) YAMLProcessor(com.sk89q.util.yaml.YAMLProcessor) SQLDriver(com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver) DriverType(com.sk89q.worldguard.protection.managers.storage.DriverType) File(java.io.File) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DriverType (com.sk89q.worldguard.protection.managers.storage.DriverType)2 RegionDriver (com.sk89q.worldguard.protection.managers.storage.RegionDriver)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Command (com.sk89q.minecraft.util.commands.Command)1 CommandException (com.sk89q.minecraft.util.commands.CommandException)1 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)1 YAMLProcessor (com.sk89q.util.yaml.YAMLProcessor)1 LocalPlayer (com.sk89q.worldguard.LocalPlayer)1 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)1 DriverMigration (com.sk89q.worldguard.protection.managers.migration.DriverMigration)1 MigrationException (com.sk89q.worldguard.protection.managers.migration.MigrationException)1 DirectoryYamlDriver (com.sk89q.worldguard.protection.managers.storage.file.DirectoryYamlDriver)1 SQLDriver (com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver)1 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)1 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)1 DataSourceConfig (com.sk89q.worldguard.util.sql.DataSourceConfig)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1