Skip to content

Creating your first custom configuration file

Leonardo Luiz Gava edited this page Dec 26, 2022 · 10 revisions

As with the default config.yml file, you will need to create a new one in your project's resources folder. Neelix accepts YAML or JSON formats.

resources/custom_config.yml

# This custom config accept comments and will be copied when registered!

my-option: 'You can configure this file how you want'
my-plugin-is-amazing: true

Registering file

When the configuration file is created, it must be registered by the plugin.
There are two ways to register the created file:

Using static class

main plugin class

public class MyPlugin extends JavaPlugin {
  private static CustomYamlConfig exampleYAML;

  @Override
  public void onEnable() {
    // Use CustomConfig.JSON to register JSON files.
    exampleYAML = new CustomConfig.YAML(this, "example.yml", true).build();
  }

  public CustomConfig getExampleConfig() {
    return exampleYAML.getConfig();
  }
} 

Using normal class

main plugin class

public class MyPlugin extends JavaPlugin {
  private static CustomYamlConfig exampleYAML;

  @Override
  public void onEnable() {
    // Use CustomJsonConfig to register JSON files.
    exampleYAML = new CustomYamlConfig(this, "example.yml", true).build();
  }

  public CustomConfig getExampleConfig() {
    return exampleYAML.getConfig();
  }
} 

Should I include the extension of the file? Yes.