Settings

Making your bot configurable.

The DefaultUI will automatically generate JavaFX controls and add them to the UI on your behalf, all you have to do is create an interface telling RuneMate about the settings. These settings are stored in the bot StoredProperties automatically, and retrieved from the previous session.

When the bot starts, RuneMate will scan the bot main class for any fields annotated @SettingsProvider and inject a reference to an instance of that class, for example:

public class ExampleBot extends LoopingBot {

    @SettingsProvider(updatable = true)
    private ExampleSettings settings;

    @Override
    public void onLoop() {
        if (settings.logsToChop() > 1000) {
            //Do something!
        }
    }
}

The Settings Descriptor

Settings are declared using an interface that extends Settings, which must use the following format:

  • Must be an interface

  • Must be annotating with @SettingsGroup

  • Each individual settings is:

    • Described using a default method where the return value is the default value

    • Annotated with @Setting which contains the setting metadata

Here is a basic example:

@SettingsGroup
public interface ExampleSettings extends Settings {
        
    @Setting(key = "logsToChop", title = "Logs to Chop", description = "How many logs the bot should chop")
    default int logsToChop() {
        return 1000;
    }
        
}

@SettingsGroup

This class-level annotation tells RuneMate that this class describes settings. I has an optional parameter group will be useful in future, but it's only purpose currently is to provide version control.

@Setting

This annotation is used to declare various characteristics about the setting:

Special Annotations

There are various "special" annotations which are data-type specific.

  • @Range - for int settings, described the maximum, minimum and step values.

  • @Suffix - for int settings, appends a suffix to the value in the ui (eg. "gp")

  • @Multiline - for String settings, uses a TextArea instead of a TextField

Setting Values Programmatically

Setting values can be assigned programmatically by adding a single-argument setter method to your descriptor interface, with the same key as the getter:

@Setting(key = "logsToChop", title = "Logs to Chop", description = "How many logs the bot should chop")
default int logsToChop() {
    return 1000;
}

@Setting(key = "logsToChop", title = "")
void setLogsToChop(int logs);

Last updated