Contribution - Mark-225/BlueBridge GitHub Wiki

Changing Existing Code

If you want to fix a small bug or make a similar small change, you obviously just have to figure out how the existing code works. In the following sections, I'll provide some step-by-step examples of how to create some more common, bigger additions to the code.

Creating a new Config Option

On a technical level, the config System works like this: There's BlueBridgeConfig which contains core config options and region config options that may be overwritten by addons. If your config option is supposed to be configurable in BlueBridgeCore's main config.yml, start by adding a static method here. Always provide a hardcoded default value, so it doesn't cause errors when the user deletes the option from the config file. Example:

public class BlueBridgeConfig {
  //leaving out all the other methods and attributes...
  public static boolean myConfigOption(){
    return config.getBoolean("myConfigOption", false);
  }
}

Now, if your config option is supposed to be overwritable by other addons, go to the abstract AddonConfig class and add a getter. This time, set the default to the static getter you just created in BlueBridgeConfig:

public abstract class AddonConfig {
  //again, leaving out the other stuff for readability

  //Note that this time you DON'T want to make this static!
  public boolean myConfigOption(){
    return config.getBoolean("myConfigOption", BlueBridgeConfig.myConfigOption());
  }
}

And that's it. You now have a config option that can be set for all addons in the core config and overwritten for each addon individually in the addon's config. Be sure to include a default setting in the core's config.yml so the user knows your config option exists. An addon specific config option can be added by doing the same as before, just in the addon's implementation of AddonConfig. Obviously the default value here has to be hardcoded since it doesn't exist in the core config.
Accessing your config option is as easy as calling your getter in the addon's AddonConfig implementation. E.g. BlueBridgeWGConfig.getInstance().myConfigOption();