A library for generating beautiful, commented, type-safe YML through interfaces
- Create interfaces (blueprints) that define your configuration
- Create default values with default methods
- Supports comments for blueprints using
@Comment
🔥 - Recursively use blueprints as arrays, lists, values of maps, etc.
- Blueprints support setters
- ASM-generated implementations for lightning performance
- Uses Gson under the hood for deserializing (to be improved)
@Blueprint
public interface Arena {
@Key("arena-name")
@Comment("The arena name")
default String name() {
return "Default name";
}
@Comment("The arena capacity")
int capacity();
@Comment({
"The arena type. Values: 'teams' or 'single'",
"",
"Default value: teams"
})
default ArenaType type() {
return ArenaType.SINGLE;
}
enum ArenaType {
TEAMS,
SINGLE
}
}
public static void main(String[] args) {
// BlueprintClass allows us to examine blueprints and
// read their properties
BlueprintClass blueprintClass = Blueprints.from(Arena.class);
// Creates an instance of Arena with all default values
Arena arena = blueprintClass.createDefault();
System.out.println(arena);
// Use our specialized CommentedConfiguration class
CommentedConfiguration config = CommentedConfiguration.from(
Paths.get("config.yml")
);
// Set the content of the configuration to the arena
config.setTo(arena);
// Set the comments to the blueprint class comments
config.setComments(blueprintClass.comments());
// Save the configuration
config.save();
// Reads the content of the configuration as an Arena
Arena deserializedArena = config.getAs(Arena.class);
// Prints: Arena(name=default name, capacity=0, type=SINGLE)
System.out.println(deserializedArena);
}
Outputs:
# The arena name
arena-name: Default name
# The arena capacity
capacity: 0.0
# The arena type. Values: 'teams' or 'single'
#
# Default value: teams
type: single