Search in sources :

Example 1 with ConfigMigrator

use of com.palmergames.bukkit.config.migration.ConfigMigrator in project Towny by TownyAdvanced.

the class Towny method handleLegacyConfigs.

/**
 * Handle any legacy config settings before we load the config and database.
 */
private void handleLegacyConfigs() {
    Path configPath = Towny.getPlugin().getDataFolder().toPath().resolve("settings").resolve("config.yml");
    if (!Files.exists(configPath))
        return;
    CommentedConfiguration config = new CommentedConfiguration(configPath);
    if (!config.load() || config.getString(ConfigNodes.LAST_RUN_VERSION.getRoot(), "0.0.0.0").equals(getVersion()))
        return;
    // Old configs stored various TownBlock settings throughout the config.
    // This will migrate the old settings into the TownBlockType config section.
    // Since 0.97.5.4.
    TownBlockTypeHandler.Migrator.checkForLegacyOptions(config);
    ConfigMigrator earlyMigrator = new ConfigMigrator(config, "config-migration.json", true);
    earlyMigrator.migrate();
}
Also used : Path(java.nio.file.Path) ConfigMigrator(com.palmergames.bukkit.config.migration.ConfigMigrator) CommentedConfiguration(com.palmergames.bukkit.config.CommentedConfiguration)

Example 2 with ConfigMigrator

use of com.palmergames.bukkit.config.migration.ConfigMigrator in project Towny by TownyAdvanced.

the class Towny method loadFoundation.

public void loadFoundation(boolean reload) {
    // Before anything can continue we must load the databaseconfig, config
    // file, language and permissions, setting the foundation for Towny.
    // Handle any legacy config settings.
    handleLegacyConfigs();
    // Load the database config first, so any conversion happens before the config is loaded.
    loadDatabaseConfig(reload);
    // Then load the config.
    loadConfig(reload);
    // Then load the language files.
    loadLocalization(reload);
    // Then load permissions
    loadPermissions(reload);
    // Initialize the type handler after the config is loaded and before the database is.
    TownBlockTypeHandler.initialize();
    // Initialize the special log4j hook logger.
    TownyLogger.getInstance();
    // Clear all objects from the TownyUniverse class.
    townyUniverse.clearAllObjects();
    // Try to load and save the database.
    townyUniverse.loadAndSaveDatabase(TownySettings.getLoadDatabase(), TownySettings.getSaveDatabase());
    // Schedule metadata to be loaded
    MetadataLoader.getInstance().scheduleDeserialization();
    // Try migrating the config and world files if the version has changed.
    if (!TownySettings.getLastRunVersion().equals(getVersion())) {
        ConfigMigrator migrator = new ConfigMigrator(TownySettings.getConfig(), "config-migration.json", false);
        migrator.migrate();
    }
    // Loads Town and Nation Levels after migration has occured.
    loadTownAndNationLevels();
    // Run both the cleanup and backup async.
    townyUniverse.performCleanupAndBackup();
}
Also used : ConfigMigrator(com.palmergames.bukkit.config.migration.ConfigMigrator)

Aggregations

ConfigMigrator (com.palmergames.bukkit.config.migration.ConfigMigrator)2 CommentedConfiguration (com.palmergames.bukkit.config.CommentedConfiguration)1 Path (java.nio.file.Path)1