-
Notifications
You must be signed in to change notification settings - Fork 5
Entries
As already seen, to add a config entry to a container, create a non-final (optionally static) field and apply the @ConfigEntry annotation. The field's value acts as the entry's value, so just read or write the field to get or set the current value.
See the Types page for an overview of what types are supported for entries.
Furthermore, the @ConfigEntry annotation provides different parameters and child annotations to customize the entry:
@ConfigEntry(comment = "This is a comment")
@ConfigEntry.BoundedInteger(min = 0, max = 10)
@ConfigEntry.Slider
private int sampleSetting = 1;This field for example represents an entry of type int with a default value of 1. Its value must be between 0 and 10. In the config screen it will be rendered as slider. The config file will have a comment above the entry saying This is a comment.
As you can see, multiple annotations can and should be combined. See the source file for an overview of all existing options.
If (almost) all fields of a class are config entries, you can also apply the @ConfigEntries annotation to the class and set includeAll to true. Then, all fields will be resolved as entries. To exclude a field, use the @ConfigEntries.Exclude annotation or the transient keyword.
@ConfigEntries(includeAll = true)
public class MyGroup implements ConfigGroup {
private boolean firstSetting;
private boolean secondSetting;
@ConfigEntries.Exclude
private boolean noSetting;
}