Solved Reloading a custom .yml file per command

Discussion in 'Plugin Development' started by Minesuchtiiii, Jun 7, 2019.

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

    Minesuchtiiii

    So I have some data stores in a custom made .yml file. I the values get changed I want them to take effect ingame after reloading the custom .yml file. I searched the net and tried some different stuff but it didn't seem to work. (Maybe there's a new way in 1.14+?)

    Help would be much appreciated.

    Thanks!
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Minesuchtiiii

    Code:
        public File data = new File(getDataFolder() + "/Data.yml");
        public FileConfiguration datacfg = YamlConfiguration.loadConfiguration(data);
    
        public void check4DataFile() {
           
            if(!(data.exists())) {
               
                try {
                    data.createNewFile();
                    saveDataFile();
    
                } catch (IOException e) {
                    e.printStackTrace();
                   
                }
               
            }
            else {
               
                saveDataFile();
               
            }
           
        }
    
    
        public void saveDataFile() {
           
            try {
                datacfg.save(data);
            } catch (IOException e) {
                e.printStackTrace();
            }
           
        }
     
  4. Offline

    KarimAKL

  5. Offline

    Minesuchtiiii

    The following code fixed it for me, incase anyone has the same problem:

    Code:
      public void reloadDataFile() {
                try {
                    datacfg = YamlConfiguration.loadConfiguration(data);
                } catch (IllegalArgumentException e) {
                    datacfg = new YamlConfiguration();
                }
            }
     
Thread Status:
Not open for further replies.

Share This Page