Creating a custom Yaml config

Discussion in 'Plugin Development' started by eleectricman226, Nov 15, 2014.

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

    eleectricman226

    Hey guys! Haven't been here in a while, but just a question for anyone who is willing to help! Say I want to create a custom Yaml configuration file, how could I specify a file/dir location? Is there a way to do this? I'm not sure if I'm going in the right path or not, but I'm pretty sure for this I should use YamlConfiguration class. Any help?
     
  2. Offline

    Totom3

    eleectricman226 That's totally possible (and simple). First, create a new File object and make sure it exists in the directory. Then you can load it using YamlConfiguration#loadConfiguration(File) and save it with FileConfiguration#save(File)
    Code:java
    1. File file = new File("path/to/my/directory", "myFile.yml");
    2.  
    3. // ** Check if file exists, if not create it **
    4. FileConfiguration config = YamlConfiguration.loadConfiguration(file);
    5.  
    6. // For saving the config, use FileConfiguration#save(File)
    7. config.save(file);
     
  3. Offline

    mine-care

    Totom3 good, but please dont spoonfeed people... its a bad idea for them, they are most of the time gonna copy the code and use it and learn nothing off of it :)
     
  4. Offline

    Totom3

    mine-care I apologize for showing him 3 instructions, explaining what each one of them does, and giving a link to the docs if he ever has a question
     
    Skionz likes this.
  5. Offline

    mine-care

    Totom3 Well i didnt mean to be offensive if i was :( i just wanted to point it out...
     
Thread Status:
Not open for further replies.

Share This Page