How do I make it Create Configuration File

Discussion in 'Plugin Development' started by jay275475, Aug 21, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    jay275475

    Hello Bukkit Users I was wondering how do i make it generate a configuration file to edit the config
    settings
     
  2. Do something like this:

    Code:java
    1. File config = new File(this.getDataFolder(), "config.yml");
    2. if (!config.exists()) {
    3. this.saveDefaultConfig(); //Tests if config exists. If it does it saves it. If not, it proceeds with generating it
    4. }
    5.  
    6. //Example
    7. getConfig().options().header("Plugin config file"); //Adds text to file. Will look like "# Plugin config file"
    8. getConfig().options().header("Modify the settings to your liking");
    9. getConfig().addDefault("Stuff", "some stuff here"); //Adds something to configure.
    10. getConfig().options().copyDefaults(true); //Copy defaults to file. Without this, the file will be blank
    11. getConfig().options().copyHeader(true);// same as previous
    12. saveConfig(); //Saves the file
    13.  


    jay275475 Make sure all that is in your onEnable().

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page