XConfiguration - Universal library for work with yml configurations

Tested on many plugins for Paper / Spigot / BungeeCord
Supported Java version: 8+

Download: GitHub

XConfiguration - is a universal annotation-based library for interacting with yml configurations. With it, you can automatically create / reload your configurations, make comments in them, and most importantly, save and receive your Java objects from the configuration automatically!

Basic usage

Consider the following example:

@Getter
public class MessagesConfiguration
extends Configuration
{
   public MessagesConfiguration(File folder)
   {
       super(folder.getAbsolutePath() + File.separator + "messages.yml");
   }
 
   @ConfigurationField("Hello-world")
   public String helloWorld = "Hello, world!";
}

First of all, we need to create our configuration class. This class must be inherited from ru.xezard.configurations.Configuration. In the superclass constructor, you need to pass the full path to file with name for the configuration. Inside a class, all declared fields annotated with @ConfigurationField are considered configuration fields. The @ConfigurationField annotation value is the path for the field value in the configuration.

In the main class of the plugin:

public class Main
extends JavaPlugin
{
    /*
     * Creating an instance of our configuration class
     */
    private MessagesConfiguration messagesConfiguration = new MessagesConfiguration(this.getDataFolder());

    @Override
    public void onEnable()
    {
        /*
         * This method automatically creates a configuration file
         * if it has not already been created. Also, it fills your class
         * with values from the configuration, or vice versa fills the
         * configuration with values from the class if there are no
         * corresponding fields in the configuration.
         *
         * You can also call this method when you want to reload
         * the configuration of your plugin.
         */
        this.messagesConfiguration.load();
 
        /*
         * After loading the configuration, we can easily get
         * the values of our fields from the class.
         */
        this.getLogger().info(this.messagesConfiguration.getHelloWorld());
    }
 
    @Override
    public void onDisable()
    {
        this.messagesConfiguration = null;
    }
}

You are done :sunglasses:

Comments

When you defining configuration fields, you can also add comments to them:

@Getter
public class MessagesConfiguration
extends Configuration
{
    public MessagesConfiguration(File folder)
    {
        super(folder.getAbsolutePath() + File.separator + "messages.yml");
    }

  @ConfigurationField("Hello-world.With-comment-above")
  @ConfigurationComments({"# First comment line", "# Second comment line"})
  public String helloWorld = "Hello, world!";
}

After calling the load() method, you can see the new configuration:

# First comment line
# Second comment line
Hello-world:
  With-comment-above: Hello, world!

If you use XConfiguration and you like it, please rate and leave a review about it!