Solved Custom YML File Question.

Discussion in 'Spigot Plugin Development' started by Nosmakos, Apr 13, 2017.

  1. How i can add the things i want from eclipse in the yml file than adding each thing by doing <getConfig>.set.
    I don't want that, i want to add things like from default config.yml file when u just open it from the eclipse and you save it and then when server starts the things are loading inside from that. Because by doing that with the .set thing, it will get forever and it won't be efficient.

    I think by doing => saveResource("<name>.yml", true); it will work.
     
    #1 Nosmakos, Apr 13, 2017
    Last edited: Apr 13, 2017
  2. getConfig().options().copyDefault() ?? or save the resource called config.yml?
     
  3. It's a custom config yml file and nope it didn't work.
     
  4. It works by doing this:
    Code (Text):
            if(!weaponsFile.exists()){
                try {
                    weaponsFile.createNewFile();  
                } catch (IOException e) {
                    e.printStackTrace();
                }
                saveResource("weapons.yml", true);  

            }
    and also having the copydefault in onEnable()
     
  5. i don't think you need to create the file if your saving the resource from the jar?
     
  6. If i do it like :
    Code (Text):
            if(!weaponsFile.exists()){
                    saveResource("weapons.yml", true);      
               
            }
    works too but what if the file does not get created?
     
  7. This will do the work.
    Code (Text):
            if(!weaponsFile.exists()){
                try {
                    weaponsFile.createNewFile();
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                saveResource("weapons.yml", true);  
                Bukkit.getConsoleSender().sendMessage("Creating weapons.yml file...");
                if(!weaponsFile.getParentFile().exists())
                {
                    try
                    {
                        if(!weaponsFile.createNewFile())
                        {
                            System.err.println("writeCheck error: Cannot create file " + weaponsFile.getAbsolutePath());
                        }
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
     
    #7 Nosmakos, Apr 13, 2017
    Last edited: Apr 13, 2017
    • Creative Creative x 2