Solved Issue with .yml file

Discussion in 'Plugin Development' started by Matroxko, Oct 18, 2017.

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

    Matroxko

    So, I am creating money plugin and need to save money values in files. But when plugin creates the file it doesn't write value in it...
    Here is my code:
    Code:
    Public static void createFile(UUID ID) {
           
            File directory = new File("plugins/ServerBank/PlayerAccounts/"+ ID +".yml");
            YamlConfiguration config = YamlConfiguration.loadConfiguration(directory);
           
            int money = 0;
            config.set("money", money);
            saveMoneyFile(ID);
        }
    Can some1 help me with this ? Thanks in advance :)
     
  2. Offline

    ItsComits

    @Matroxko What is 'saveMoneyFile(ID);'? Also can you post the code for it so I can take a look.
     
  3. Offline

    Matroxko

    Code:
    public static void saveMoneyFile(UUID ID) {
          
            File directory = new File("plugins/ServerBank/PlayerAccounts/"+ ID +".yml");
            YamlConfiguration config = YamlConfiguration.loadConfiguration(directory);
      
            try {
                config.save(directory);
            } catch (Exception e) {
                Bukkit.getLogger().info("There was an error saving the file of player " + Bukkit.getPlayer(ID).getName());
            }
          
        }
     
  4. Offline

    ItsComits

    @Matroxko
    Change this line:
    Code:
    YamlConfiguration config = YamlConfiguration.loadConfiguration(directory);
    
    to:
    Code:
    FileConfiguration config = YamlConfiguration.loadConfiguration(directory);
     
  5. Offline

    Matroxko

    It is not working... :(
     
  6. Offline

    ItsComits

    @Matroxko Is anything printed to console?
     
  7. Offline

    Matroxko

    Nothing. No errors.
     
  8. Offline

    Caderape2

    @Matroxko You create a new isntance based on the file for save it. It cannot work.
    use 'config.save(file)' after set the money
     
  9. Offline

    Matroxko

    Ok now its working. Thanks a lot :)
     
Thread Status:
Not open for further replies.

Share This Page