Skip to content

Optional sections

Dieter Nuytemans edited this page Jun 24, 2021 · 1 revision

EXPERIMENTAL FEATURE: Optional paths

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.

Wiki navigation

Wiki home

JavaDocs


BetterYaml (config files)

BetterYaml (deprecated, but supported)

Please use OptionalBetterYaml instead.

Setup

How to use BetterYaml

OptionalBetterYaml

Setup

How to use


BetterLang (language files)

Setup

How to use


Validation

Auto-correct faulty configuration values! You can create your own, custom validators.

How to use validators

EXPERIMENTAL: Optional sections

Clone this wiki locally