Config system

Loading the config values

You're able to load values from the config by using the JsonObject accessable via LabyModAddon#getConfig(). There is an abstract method called LabyModAddon#loadConfig() that you can use to initially load the config values at the start.

Modifying the config

You can modify the config values by just modifying the JsonObject accessable via LabyModAddon#getConfig() and saving the config afterwards.

Saving the config

Your config will be automatically saved when you close the GUI but you can also use the method LabyModAddon#saveConfig() to save the previously modified config values.

Example of using the config

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package net.labymod.addons.test;

import net.labymod.api.LabyModAddon;
import net.labymod.settings.elements.BooleanElement;
import net.labymod.settings.elements.SliderElement;
import net.labymod.utils.Material;

import java.util.List;

/**
 * Test addon
 */
public class TestAddon extends LabyModAddon {

    private boolean enabledCoolStuff;
    private int number;

    /**
     * Called when the addon gets enabled
     */
    @Override
    public void onEnable() {
    }

    /**
     * Called when the addon gets disabled
     */
    @Override
    public void onDisable() {

    }

    /**
     * Called when this addon's config was loaded and is ready to use
     */
    @Override
    public void loadConfig() {
        // Loading config value
        this.enabledCoolStuff = getConfig().has( "enabledCoolStuff" ) ? getConfig().get( "enabledCoolStuff" ).getAsBoolean() : true; // <- default value 'true'
        this.numberExample = getConfig().has( "number" ) ? getConfig().get( "number" ).getAsInt() : 5; // <- default value '5'
    }

    /**
     * Called when the addon's ingame settings should be filled
     *
     * @param subSettings a list containing the addon's settings' elements
     */
    @Override
    protected void fillSettings( List<SettingsElement> subSettings ) {
        // These are the ingame settings - you can learn how to use them by clicking "Create ingame settings" on the left hand side
        // It will automatically update the config

        // Toggle element
        subSettings.add( new BooleanElement( "Enabled", this, new IconData( Material.LEVER ), "enabledCoolStuff", this.enabledCoolStuff ) );

        // Slider element
        subSettings.add( new SliderElement( "Number", this, new IconData( Material.ITEM_FRAME ), "number", this.numberExample ).setRange( 0, 100 ) );
    }

}