Simple configuration setup tutorial

Discussion in 'Resources' started by thehutch, Oct 23, 2011.

?

How would you rate this tutorial on simplicity and usefulness from various levels of experience

  1. 5 - Very useful (Would keep refering back to it)

    35.7%
  2. 4 - Quite useful (Might improve upon this)

    14.3%
  3. 3 - Meh I would read it and use it

    0 vote(s)
    0.0%
  4. 2 - Would read it but not use it

    0 vote(s)
    0.0%
  5. 1 - Walked away from this page and never return

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

    thehutch

    Ok so I wrote this little tiny tutorial on how create a config.yml using the new CB1317+ API
    Bare in mind this took about 2-3 mins and I wrote it in Notepadd++ :) and is mainly aimed at new developers starting out and wanting to get into the configuration side of plugins.
    Code:
        // decleare this in your mainclass at the top
        FileConfiguration config;
     
        // call this method in your onEnable()
        public void setupConfig() {
    
            config = this.getConfig();
    
            // fill in these addDefaults with your config values
            config.addDefault("String value here" , "Default value");
            config.addDefault();
            config.addDefault();
            config.addDefault();
            config.addDefault();
    
            config.options().copyDefaults(true);
            saveConfig();
        }
    Please rate this tutorial using the poll thank you :)
     
    ArcheCane likes this.
  2. Offline

    Sagacious_Zed Bukkit Docs

    For most plugins, defaults should NOT be instantiated in the code explicitly. The defaults should in put into a default yaml file and included in the jar, where plugin.yml is. JavaPlugin's getConfig method will load config.yml from your plugin's data folder and load defaults from the jar.
     
  3. Offline

    thehutch

    Well it works perfectly fine and is simple enough for newcomes. and thanks for rating it a 1 :(
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    It should be even more simple, to put a default yaml with defaults in the same directory as plugin.yml
     
  5. Offline

    thehutch

    Nah learning how to code it is far better
     
  6. Offline

    Sagacious_Zed Bukkit Docs

    But it completely breaks separation of code and data
     
  7. Offline

    thehutch

    I did warn you I wrote it in 2-3 mins and on notepad ++ :p
     
  8. Offline

    Sagacious_Zed Bukkit Docs

    If, you are going to teach someone, do it right. Otherwise, you can do some permanent damage.
     
  9. Offline

    thehutch

    So how would you create a automatically generated config because this way works and I know it does so I dont see anything wrong yes there might be a different way please enlighten me.
     
  10. Offline

    boardinggamer

    When I do this it doesn't create a config file. How do i make it so it creates a file for the config?
     
  11. Offline

    TheFieldZy

  12. Offline

    boardinggamer

    nope but I got it now =P
     
  13. Offline

    thehutch

    I would also like to add that this method only works whilst using it within the main Class, you can retrieve this info from another class yes however if you try to create a reload command then you cannot use the variable "config" in your other classes you either have to make a new variable for that new class or just use getConfig()
     
Thread Status:
Not open for further replies.

Share This Page