[Text-Based] Quick YML Tutorial for Lazy Readers

Discussion in 'Resources' started by GeekPlaya, Oct 9, 2011.

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

    GeekPlaya

    What is a YML file?
    A YML file is a configuration file (holds information in a structured order). Bukkit's JavaPlugin class implements an easy way to work with YML files, which is probably why it is so popular in Bukkit plugins.

    How do I make my own YML configuration?
    It's very easy and many plugin developers fail to realize that it doesn't require more than one line of code to create the file (as Bone008 pointed out).

    First, just place this at the top of your plugin (right where you state your public variables):
    Code:
    public class MyPlugin extends JavaPlugin {
        public Configuration config;
    Now we have stated our Configuration variable. In order to access the file, we place this line of code into our onEnable(): (this also creates the file if it does not exist)
    Code:
    config = getConfiguration();
    How do I add properties and values to it?
    Get ready to be mind blown...

    Adding a property:
    Code:
    config.setProperty("users.geekplaya.god", "");
    Giving a property a value:
    Code:
    config.setProperty("users.geekplaya.god", "true");
    Deleting a property (deletes contents of property too):
    Code:
    config.removeProperty("users.geekplaya");
    Reading a property:
    Code:
    config.getProperty("users.geekplaya.god");
     
  2. Offline

    Supertt007

    But, is it possible to change the name? I don't want it to be named as config.yml
     
  3. Offline

    GeekPlaya

    Code:
    config = new Configuration(new File(getDataFolder().getPath() + "/NAMEHERE.yml"));
     
  4. Offline

    Supertt007

    I love you, thanks :p
     
  5. Offline

    codename_B

    Update this for the new Configuration object.
     
    Zaros and iPhysX like this.
  6. Offline

    Zaros

    Please do, I'm having more issues that I would like...
     
  7. Offline

    Aza24

    Yeah do... mine still works but all of the warnings are annoying!
     
Thread Status:
Not open for further replies.

Share This Page