Configuration
Learn how to create plugin settings and preferences that users can configure.
Configuration lets users customize your plugin. Think of it like settings in a video game - users can turn features on/off, change colors, set thresholds, etc.
Config Interface
You create a config interface that extends Config. Each method represents a setting:
@ConfigGroup("yourplugin")
public interface YourPluginConfig extends Config {
@ConfigItem(
keyName = "enabled",
name = "Enable Feature",
description = "Turn this feature on or off"
)
default boolean enabled() {
return true;
}
}
Config Annotations
- **@ConfigGroup**: Groups related settings together
- **@ConfigItem**: Defines a single setting
- **@ConfigSection**: Creates a section header in the config panel
Using Config
Inject your config interface and use it:
@Inject
private YourPluginConfig config;
public void doSomething() {
if (config.enabled()) {
// Feature is enabled
}
}
Config Types
You can create configs for:
- **boolean**: Checkboxes (on/off)
- **int**: Number inputs
- **String**: Text inputs
- **Color**: Color pickers
- **Enum**: Dropdown selections
Best Practices
- Use clear, descriptive names
- Provide helpful descriptions
- Set sensible defaults
- Group related settings with @ConfigSection
Code Examples
Example 1
1// Create config interface
2@ConfigGroup("myplugin")
3public interface MyPluginConfig extends Config {
4 @ConfigItem(
5 keyName = "showOverlay",
6 name = "Show Overlay",
7 description = "Display the overlay on screen"
8 )
9 default boolean showOverlay() {
10 return true;
11 }
12
13 @ConfigItem(
14 keyName = "overlayColor",
15 name = "Overlay Color",
16 description = "Color of the overlay text"
17 )
18 default Color overlayColor() {
19 return Color.WHITE;
20 }
21}
22
23// Use in plugin
24@Inject
25private MyPluginConfig config;
26
27@Override
28public Dimension render(Graphics2D graphics) {
29 if (config.showOverlay()) {
30 PanelComponent panel = new PanelComponent();
31 panel.setPreferredSize(new Dimension(150, 30));
32 panel.getChildren().add(
33 LineComponent.builder()
34 .left("Hello")
35 .leftColor(config.overlayColor())
36 .build()
37 );
38 panel.render(graphics);
39 }
40 return new Dimension(150, 30);
41}