-
Notifications
You must be signed in to change notification settings - Fork 0
Optional sections
Please, read the validator wiki page first, before proceeding. Sometimes you may want your user to add their own configuration sections, eg world-specific settings for any custom world:
world_settings:
overworld:
enable_plugin: true
num_needed: 16
nether:
enable_plugin: true
num_needed: 2
another_overworld:
enable_plugin: true
num_needed: 25
When they want to add another world, BetterYaml would previously not allow this. In this version, an experimental feature was added: optional paths!
With a ValidationHandler instance, we can handle the optional config above as follows:
ValidationHandler validationHandler = new ValidationHandler()
// Mark the whole section as optional, anything added by the user will not be validated
.addOptionalSection("world_settings")
// We can specify default values for sub paths (only used when copying a new config)
.setOptionalValue("world_settings.overworld.enable_plugin", true)
.setOptionalValue("world_settings.overworld.num_needed", 5);
Next use this ValidationHandler as you would for any regular validation and the optional config section will be handled.
However, there is a caveat: Do not add any optional paths to your template, or it will always be copied. Default optional paths will appear at the bottom of the config file and do not have to be manually added to your template.
Please use OptionalBetterYaml instead.
Auto-correct faulty configuration values! You can create your own, custom validators.