Config.yml

Discussion in 'Plugin Development' started by edocsyl, Dec 15, 2011.

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

    edocsyl

  2. Offline

    Kierrow

    Alright, my specialty.
    Just kidding... What you need to have in order to change the configuration file is a
    reference to your JavaPlugin subclass. Like this:

    Code:
    JavaPlugin myPlugin = [...];
    Now in the JavaPlugin class, there's two methods you basically need to focus on.
    That is:

    Code:
    myPlugin.getConfig();
    myPlugin.saveConfig();
    saveConfig() obviously saves the config. You should call this either after you have
    made an adjustment or in general when the onDisable() method of your plugin is called.
    getConfig() returns a FileConfiguration (see http://jd.bukkit.org/apidocs/org/bukkit/configuration/file/FileConfiguration.html), which you can call methods on.
    That FileConfiguration is either loaded from your config.yml or if that doesn't exist, a new one is created.
    saveConfig() by the way saves to that exact same file, like you might have figured.

    It's actually quite simple. Check the API documentation (the link I posted above)
    for more information about the use of and methods within the FileConfiguration class.

    Have fun, and keep in mind that this should only be used for preferences and in general
    things the server admin should have direct access to. Not more. For example using this technique for saving blocks
    (which would also be very complicated) is a waste of your time and resources.

    Another way to save stuff would be a database, or this:
    http://wiki.bukkit.org/Plugin_Tutorial#HashMaps_and_How_to_Use_Them
    You should generally know this tutorial in it's entirety.

    I hope I could help.
    -Kierrow
     
Thread Status:
Not open for further replies.

Share This Page