Skip to content
Mazen Kotb edited this page Jul 19, 2016 · 2 revisions

Welcome to the ConfigAPI wiki! To put it simply, this API will make managing configs for your plugins extremely simple. This project takes advantage of reflection in Java to best achieve this. This wiki will be a reference for all the features available in the API, where it's best not to touch, and what exactly certain errors mean and how to fix them.

The Basics

Installing using Maven

Add this to your maven project using the following:

<dependency>
  <groupId>xyz.mkotb</groupId>
  <artifactId>config-api</artifactId>
  <version>1.0</version>
</dependency>

Creating your first config

To start off, we must have the root of the config. With how this API works, you define the structure of it with just plain ol' Java. For the sake of simplicity, I'm going to call the the config "MyConfig" and have one field called startMessage which I will have print every time the plugin starts.

public class MyConfig {
    String startupMessage = "This is the default message!";
}

... and it's as simple as that! We defined the structure of our first config, now let's move on to file operations.

Reading/Writing from File

The API assumes that your input and output will always be towards a File, and wraps it's design around that. For normal usage, all interaction with the API will be done through the ConfigFactory. To do anything, you will first need to create the factory specific to your plugin. This can be done through the static newFactory method. You will want to keep this factory stored in an accessible place, where it can be called upon later in the runtime to be saved. Use the following as an example:

public class MyPlugin extends JavaPlugin {
    private MyConfig myConfig;
    private ConfigFactory configFactory = ConfigFactory.newFactory(this);

    @Override
    public void onEnable() {
        myConfig = configFactory.fromFile("config", MyConfig.class);
        getLogger().info(myConfig.startupMessage);
    }

    @Override
    public void onDisable() {
        // if we changed values in my config while the server is up
        // we should save it
        configFactory.save("config", myConfig);
    }
}

... and that's it for the basics! Refer to the README for a brief overview on how much the API can do. If you hit any walls or hit any undocumented exceptions or have a quick question, feel free to create an issue for me to reply to. Or, if you're on Telegram, you can contact me at @MazenK!