Class VersionAwareConfiguration
java.lang.Object
net.blockhost.commons.config.VersionAwareConfiguration
Base class for configuration files that support versioned migrations.
Extend this class to enable automatic migration support for your configuration. The version field tracks the current schema version of the configuration file, allowing the migration system to determine which migrations need to be applied.
Usage
@Configuration
public class MyPluginConfig extends VersionAwareConfiguration {
// Current schema version - increment when making breaking changes
private static final int CURRENT_VERSION = 3;
private String serverName = "My Server";
private int maxPlayers = 100;
public MyPluginConfig() {
super(CURRENT_VERSION);
}
}
Version Field Behavior
- When a new config is created, it starts at the
defaultVersionpassed to the constructor - When an existing config is loaded, the version reflects the file's current schema version
- After migrations are applied, the version is automatically updated to the target version
- Users should never manually modify the version field in the YAML file
Migration Flow
- Config file is loaded with
invalid reference
RawYamlLoader
- Version is read from the raw YAML data
invalid reference
ConfigMigrator
- Updated YAML is saved back to disk
- Config is then loaded normally via
ConfigLoader
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedVersionAwareConfiguration(int defaultVersion) Creates a new version-aware configuration with the specified default version. -
Method Summary
Modifier and TypeMethodDescriptionintversion()Returns the current schema version of this configuration.
-
Constructor Details
-
VersionAwareConfiguration
protected VersionAwareConfiguration(int defaultVersion) Creates a new version-aware configuration with the specified default version.
The
defaultVersionparameter should be set to the current/newest schema version of your configuration. This ensures that newly created configuration files start with the latest schema version and don't require any migrations.- Parameters:
defaultVersion- the current schema version for new configurations
-
-
Method Details
-
version
public int version()Returns the current schema version of this configuration.
This value represents either:
- The default version (for newly created configs)
- The version read from an existing config file
- The updated version after migrations have been applied
- Returns:
- the current configuration schema version
-