Config not saving.

Discussion in 'Plugin Development' started by jebbo, Apr 6, 2015.

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

    jebbo

    So I'm trying to make a system that saves each player in its own config.

    It's creating the Config but not saving any entries.

    But the problem I have is that its not saving:

    Code:
    public void save(){
            if(uuid == null){
                System.out.println("[SAVINGERROR] File could not be saved: 'uuid == null'");
                return;
            }
            File file = new File("plugins/"+folder+"/playerdata", uuid+".txt");
            if(!file.exists()){
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    System.out.println("[SAVINGERROR] File could not be saved: '"+e.getMessage()+"'");
                    return;
                }
            }
            FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
            try {
                cfg.save(file);
                cfg.load(file);
            } catch (IOException | InvalidConfigurationException e) {
                System.out.println("[SAVINGERROR] File could not be saved: '"+e.getMessage()+"'");
                return;
            }
        }
    Thanks!
     
  2. Offline

    dlange

    @jebbo You are creating a text document not a yaml document, that could be why, i haven't worked much with individual configs lol
     
  3. Offline

    jebbo

    Same result, the file gets created but the entries not saved. :/
     
  4. Offline

    Gater12

    @jebbo
    How are you saving the entries to the config?
     
  5. Offline

    jebbo

    @Gater12

    The 'setName' method:
    Code:
    public void setName(String s){
            FileConfiguration cfg = getFileConfig(uuid);
            cfg.set("name", s);
            save();
        }
    The 'getFileConfig' method:
    Code:
    public FileConfiguration getFileConfig(String uuid){
            File file = new File("plugins/"+folder+"/playerdata", uuid+".yml");
            if(!file.exists()){
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    System.out.println("[SAVINGERROR] File could not be created: '"+e.getMessage()+"'");
                    return null;
                }
            }
            return YamlConfiguration.loadConfiguration(file);
        }
    I think im overseeing something.. xD

    Thanks.
     
  6. Offline

    nverdier

    @jebbo If you want to make player config files easily, you could use the Config class of EnviousAPI. Link in description.
     
Thread Status:
Not open for further replies.

Share This Page