A comprehensive and thread-safe configuration system built on top of SimplixStorage. This module adds extra capabilities such as automatic serializer registration, factory-based builders, and robust serialization annotations, simplifying how you manage and persist configuration data.
This configuration module allows you to:
- Build local or directory-based configuration files using SimplixBuilder without having to manually customize advanced settings each time.
- Securely read and write configuration values (e.g., JSON, YAML, TOML) in a thread-safe manner.
- Leverage annotation-based serialization via @SimplixSerializerSerializableAutoRegister, automatically registering custom classes for simplified data persistence.
It integrates seamlessly with the rest of the LegacyLands ecosystem, such as the annotation module and Fairy IoC, ensuring an efficient and cohesive workflow.
Add the built artifact for the configuration module to your project. For example, in your Gradle (Kotlin DSL) file:
dependencies {
compileOnly(files("libs/configuration-1.0-SNAPSHOT.jar"))
}
Adjust this to suit your preferred build system, repository placements, or versioning approach.
Below is an outline of how to use the configuration module effectively within a Fairy-based plugin or other Java environment.
You can utilize the SimplixBuilderFactory to create a SimplixBuilder in various ways (e.g., from a single File, a directory, or a path string). Once you have the builder, you can pick what format you'd like (YAML, JSON, etc.):
SimplixBuilder builder = SimplixBuilderFactory.createSimplixBuilder("example", "D:/");
// Typically you will choose one (YAML/JSON/TOML).
Yaml yamlFile = builder.createYaml();
yamlFile.set("someConfigKey", "someValue");
The underlying data structures in SimplixStorage, combined with automatic synchronization in this
configuration module, allow safe concurrent reads/writes:
• No need to implement additional locks or concurrency layers manually.
• Minimizes the risk of data corruption when multiple threads attempt to modify the same configuration.
With annotation scanning enabled (through the annotation module), any class annotated with @SimplixSerializerSerializableAutoRegister will automatically be registered as a SimplixSerializable implementation by the SimplixSerializerSerializableAutoRegisterProcessor. This ensures your custom types can be serialized/deserialized without extra manual steps.
Example:
@SimplixSerializerSerializableAutoRegister
public class PlantSerializable implements SimplixSerializable<Plant> {
@Override
public Plant deserialize(@NonNull Object serializedObject) {
// Implement your logic to turn "serializedObject" into a Plant instance
return plantInstance;
}
@Override
public Object serialize(@NonNull Plant plant) {
// Convert your Plant object into a structure (Map, String, etc.) for storage
return serializedData;
}
@Override
public Class<Plant> getClazz() {
return Plant.class;
}
}
This is especially valuable for advanced domain objects or complex data structures that need storage in your configuration files.
Located at configuration/factory/SimplixBuilderFactory.java.
• Bundles common settings (DataType, config comments, reload behavior) into any newly created
SimplixBuilder.
• Provides various static methods to quickly generate builder instances from Files, directories, or paths.
Annotated with @AnnotationProcessor to detect your custom classes that implement SimplixSerializable.
• Once triggered, it instantiates an object of that class and calls SimplixSerializer.registerSerializable(...).
• Ensures you can skip manual registration steps for every new serializable class.
• Multi-Format Support (YAML, JSON, TOML): Switch easily to any format supported by SimplixStorage.
• Automatic Reload Settings: By default, the SimplixBuilder uses ReloadSettings.AUTOMATICALLY, ensuring
changes are picked up promptly.
• Fine-Tuned Data Sorting (DataType.SORTED): Keeps your configuration files organized for better readability.
• Integration with IoC, letting you create or manage configuration objects via injection if desired.
This project is licensed under the MIT License. Please see the LICENSE file for more details.
We appreciate all contributions via pull requests, issue reports, and feature suggestions. Whether it's improving documentation, optimizing builder settings, or introducing new advanced serialization options, your help makes the module stronger for everyone!
Made with ❤️ by LegacyLands Team