Creating config.yml!

Discussion in 'Spigot Plugin Development' started by Zarlen, Apr 28, 2017.

  1. Hello, you there!
    I'm trying to create my own config file, but I tried all methods (and also learned from docs and tutorials). But sadly no one method does work (for me). It just doesn't create the config.yml file or it doesn't add default rules in it.

    If anyone would explain me how to make a config file and set a default rule in it?
    (I'm not asking for spoonfeed, but you can if you want :3)
     
  2. Why do you make a second thread about the same issue? We provided links,docs. Youtube and google exist. Stop being lazy and put some effort in it.
     
    • Funny Funny x 1
  3. The other one was for ArrayList, this one is for creating the config (someone explained me the ArrayList one, gonna make it solved).
     
  4. Very simple,

    1. Create config file in Source

    2. Use the methods to load/create the config
    aka
    getConfig().options().copyDefaults(true);
    and then

    saveDefaultConfig();

    And I suggest you learning java/docs
     
  5. You can use getConfig() vor create your own with a Yamlconfiguration.
     
  6. If you only want one config file, the config.yml, I recommend creating a file like the plugin.yml, but named config.yml in your IDE and with the default config values and calling the saveDefaultConfig method before you access the config (so, for example, the first method inside onEnable should be it).

    Check the Bukkit wiki, a thousand posts about this or browse open-source projects and you will find your answer...
     
  7. It does create the config file but not the rule I added (testlist:) in the config.yml in the source.
     
  8. 1. Add your data

    2. saveConfig();

    3. profit
     
  9. Still doesn't work:
    onEnable:
    Code (Text):
    public void onEnable() {
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    this.getConfig().options().copyDefaults(true);
    this.saveConfig();
    }
    config.yml in the source folder:
    Code (Text):
    testlist:
    And when I start the server, it creates the config.yml file but with nothing in it.
     
  10. Maybe because you don't add something to it?

    Edit: Misread, Try saveDefaultConfig();

    Edit2: Remove the 'this', It's useless
     
  11. Thanks, it works now.
     
  12. if(!(new File(getDataFolder()).exists()) getConfig().options().copyDefaults(true);
     
  13. By the way, I have a few other questions:
    How do I put the ArrayList (of players) in the config (at testlist like this)

    testlist: playerone, playertwo, playerthree

    I already have an ArrayList of players, how do I put them in the config like above.
     
  14. Code (Text):
    getConfig().set("testlist", listname);

     
    Make sure to save the config (saveConfig();)
     
  15. use toString() on your arraylist.
     
  16. It's a buggy, is there any way to contact you please?
     
  17. my discord is IPyromaniac[BOSS]#0231