Skip to content

Config system

Warning

This page is for the LabyMod 3 Addon API, which is no longer maintained nor supported. Visit https://wiki.labymod.net/pages/addon/ for the LabyMod 4 Addon API Wiki.

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

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 ) );
    }

}