Skip to content

Containers and Groups

Lortseam edited this page Sep 3, 2023 · 7 revisions

To create a container or group, create a class and implement either the ConfigContainer or ConfigGroup interface.

public class MyContainer implements ConfigContainer {

    @ConfigEntry
    private int sampleSetting = 1;

}
public class MyGroup implements ConfigGroup {

    @ConfigEntry
    private int sampleSetting = 1;

}

By default, the group's class name is used as identifier (in this case myGroup). If you want a custom ID, override the getId method.

Registration of subgroups and child containers

Subgroups and child containers must be registered inside their parent ConfigContainer, ConfigGroup or Config. There are different options to do that:

public class MyParentGroup implements ConfigGroup {

    // Using the @Transitive annotation on a field
    @Transitive
    private final MyContainer myContainer = new MyContainer();
    @Transitive
    private final MyGroup myGroup = new MyGroup();

    // Using the getTransitives method
    @Override
    public Collection<ConfigContainer> getTransitives() {
        return List.of(new MyContainer(), new MyGroup());
    }

    // Using the @Transitive annotation on a nested class
    @Transitive
    public static class MyNestedGroup implements ConfigGroup {
        
        @ConfigEntry
        private boolean nestedSetting;

    }

}

NEXT: Entries

Clone this wiki locally