Solved Reloading a custom .yml file per command

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

  1. 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 Ninja on the waves Moderator

  3. 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. 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();
                }
            }
     

Share This Page