Interface IConfigMigrator

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface IConfigMigrator
Imports a config file from the format a mod used before adopting MezzConfig.

Register a migrator with IConfigSchemaBuilder.setLegacyMigration(List, IConfigMigrator). Parse the old file in migrate(Path, IConfigMigrationContext) and pass converted values to the migration context. MezzConfig handles backup, validation, and writing the new config, so migrators never need to understand MezzConfig's file format.

Since:
0.3.0
  • Method Details

    • migrate

      void migrate(Path legacyPath, IConfigMigrationContext context) throws Exception
      Import values from the selected legacy file.

      Read the old format from legacyPath and call the context's typed update methods for every setting to import. Throw an exception when the old file cannot be interpreted; MezzConfig will leave the new config unchanged.

      Parameters:
      legacyPath - normalized absolute path to the selected legacy file
      context - context for typed config value and sorting updates
      Throws:
      Exception - if the legacy file cannot be read or migrated
      Since:
      0.3.0
    • onMigrationComplete

      default void onMigrationComplete(IConfigMigrationResult result)
      Receive the final migration outcome for logging, diagnostics, or user-facing feedback.

      Override this when the mod needs to handle skipped migrations or failures that happen after migrate(java.nio.file.Path, net.mezzdev.config.api.migration.IConfigMigrationContext) returns. Lambdas may ignore it. MezzConfig calls it once for every registered migration after reaching a final outcome. World-scoped schemas wait until their first local destination becomes active; waiting for a world or receiving a remote server snapshot does not complete the migration. Permanently inactive declarations report ConfigMigrationStatus.SKIPPED_INACTIVE. An exception from this method is logged and does not change that outcome.

      Parameters:
      result - final structured migration result
      Since:
      0.3.0