Sueta

[API] ConfigCreator

1.2

Creating more config files was never this easy before!

·Config

Installation:

  1. Click on Download
  2. Create a Config.java file in your project
  3. Copy the contents from gist to your class
  4. Check the Usage for more informations.

Download link leads you to a gist. Alternatively, you can click here.
(https://gist.github.com/RobiFox/9101eecb34f4a5078342ec762d739898)

Usage:

  • Open your project and create a new Config file in the Main class
Config File
Config c = new Config("plugins/MyPlugin", "ExampleFile.yml", this);
  • Use the "create" method to create it.
Create Method
Config c = new Config("plugins/MyPlugin", "ExampleFile.yml", this);
c.create();
  • Create a file just like making "config.yml", and write your default paths there.
Example Picture

  • Do an if statement for existence
Exist Statement
Config c = new Config("plugins/MyPlugin", "ExampleFile.yml", this);
c.create();
if(!c.exists()) { }
  • If not, set the file's default, copy them, and save it.
Existing check
Config c = new Config("plugins/MyPlugin", "ExampleFile.yml", this); // ExampleFile.yml is the output file
c.create();
if(!c.exists()) {
c.setDefault("ExampleFile.yml"); // Your file name in your jar file
c.getConfig().options.copyDefaults(true);
c.saveConfig();
}
  • Create a variable to make it available from other classes, and assign it, too.
Making it public static
public Config example;
public void onEnable() {
   Config c = new Config("plugins/MyPlugin", "ExampleFile.yml", this);
   c.create();
   if(!c.exists()) {
      c.setDefault("ExampleFile.yml");
      c.getConfig().options.copyDefaults(true);
      c.saveConfig();
    }
    example = c;
}
  • You can convert it to a file by doing: Config.toFile();
  • You can convert it to YamlConfiguration by doing: Config.getConfig();

Similar projects

Config →