Config Entries

Config entries are an essential part of Resourceful Config, these are what actually store data and how you retrieve data. A config entry can be of many types it first consists of a @ConfigEntry annotation that defines its id, type, and translation, and then a corresponding field.

Certain entry types can be optionally allowed in arrays, this means you can define an array of that type. Additionally certain entry types must be final instead of normally required to not be final.

Config Entry Restrictions

Entry TypeAllowed In ArraysMust Be Final

BYTE

SHORT

INTEGER

LONG

FLOAT

DOUBLE

BOOLEAN

STRING

ENUM

OBJECT

Config Entry Options

In addition to the @ConfigEntry annotation there are several other annotations that signify settings that a config entry may have. Most are used for display purposes but others are used for validation. These options can be found in the ConfigOption class.

Range

The Range annotation is an option used by the number based annotations this restricts the value that can be imputed into a config entry.

// Range Example
// Shows a value that can go from 0-100
@ConfigOption.Range(min = 0, max = 100)

Slider

The Slider annotation is what is used to be paired with the Range annotation to change that look of the input in the config screen from a number input box to a slider. This annotation does not have any parameters and will only be used if there is a corresponding Range annotation on the same entry.

Multiline

The multiline annotation is what the string entry uses to the determine if in the config screen it should be displayed a multiline text modal instead of a single line text box.

Color

The color annotation is what an int entry uses to determine if in the config screen it should be displayed as a color, this annotation has 2 parameters, presets which is a list of colors to display, and alpha which is a boolean determining if you can use alpha in your color.

Regex

The regex annotation allows you to define a regex a string must match against to be valid.

Separator

Separator annotation is a config option that will change how the config screen looks, this is used to add more context and spacing between large config classes. It will add a new empty entry above the field it is added on in the class, this empty field can have a description and a title it can be used to separate similar like config entries.

Hidden

The hidden annotation defines if a config entry must be hidden the GUI, if this annotation is not present the entry will be shown in the GUI.

Select

The select annotation determines if a array of enums will be displayed as a selectable list, this is like a dropdown except you can select multiple. It contains 1 parameter, the title of the button.

Draggable

The draggable annotation is like select but it for reorderable enum arrays, this has 1 parameter, this parameter is the list of enums that can be duplicated (meaning it can be added to the list more than once). Additionally with draggable, range can be used along side it to limit the upper and lower bounds of the lists size.

Keybind

The keybind annotation is used on an int entry as to store a keybind which is too specified that it should be in the config instead of the keybind list.

SearchTerm

The search term annotation is used on any entry to add additional terms that can be used for the search bar.

Comments

Comments are a great way to get across to the user what a config entry is used for, Resourceful Config adds default comments for things such as a range, enum, and number as those allow the user to know what is valid for that entry in the config file. But additionally you can add your own comments using the @Comment annotation this annotation will take whatever you put into it and add it to the file, as well it will use these comments for descriptions of your config entry in the config screen. These can also be optionally translated by adding a translation key to the annotation.

Example

@ConfigEntry(
    type = EntryType.ENUM,
    id = "demoEnum",
    translation = "demo.config.demoEnum.name"
)
public static ChatFormatting demoEnum = ChatFormatting.RED;

Note

Config entries have certain restrictions they must follow. The following are the restrictions.

  • The entry must have the public access modifier

  • The entry must be static if not stated otherwise

  • The entry must not be final if not stated otherwise

  • The entry if an array its type must be allowed in an array

  • The entry may not have periods in its id

Last updated