Solved Custom YAML not copying defaults?

Discussion in 'Plugin Development' started by EgyptianKing, Dec 3, 2014.

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

    EgyptianKing

    Hi, I'm trying to make a custom YAML that will copy the defaults I have in the project's source.

    Here is the code I am using:
    Code:java
    1. public class Main extends JavaPlugin
    2. {
    3. private File f;
    4. public static FileConfiguration config;
    5.  
    6. @Override
    7. public void onEnable()
    8. {
    9. f = new File(getDataFolder() + File.separator + "messages.yml");
    10.  
    11. if(!f.exists())
    12. {
    13. try
    14. {
    15. f.createNewFile();
    16. } catch (IOException e)
    17. {
    18. e.printStackTrace();
    19. }
    20. config = YamlConfiguration.loadConfiguration(f);
    21.  
    22. config.getDefaults();
    23. config.options().copyDefaults(true);
    24. try
    25. {
    26. config.save(f);
    27. } catch (IOException e)
    28. {
    29. e.printStackTrace();
    30. }
    31. }
    32. }
    33. }


    The messages.yml in the source has text but when I run the plugin it only creates a blank yml. It is not copying the defaults, anyone know why?

    Thanks.
     
  2. Offline

    mythbusterma

    EgyptianKing

    You never retrieve the contents of the file that is in the .jar file. Also, stop abusing the static keyword.
     
  3. Offline

    EgyptianKing

    mythbusterma
    Alright I removed the static keyword from the FileConfiguration variable. I thought that this line:
    Code:java
    1. config.getDefaults();

    retrieves the contents of the file. If not, how do I retrieve the contents?
     
  4. Offline

    mythbusterma

    EgyptianKing

    You would have to get the file from inside your jarfile, look up online how to do it, I forget, but I remember it not being difficult.
     
    EgyptianKing likes this.
  5. Offline

    EgyptianKing

Thread Status:
Not open for further replies.

Share This Page