Per-player YAML files

Discussion in 'Plugin Development' started by justcool393, Jan 5, 2013.

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

    justcool393

    Well, I've tried and tried and truth be told, I'm kind of stuck here.
    Basically, what I need to do is create a per-player yml file (example justcool393.yml) in a folder called players (inside the plugin's data folder)

    Now, when I create the code, it nothing to the file but the first few comments I put in the yml file.

    Code:
    public YamlConfiguration getConfig(String name) {
            File folder = new File(getDataFolder() + ("/players/"));
            File file = new File(getDataFolder() + "/players/" + name +".yml");
            if(!folder.exists()) {
                folder.mkdir();
            } else if(!file.exists()) {
                    try {
                        YamlConfiguration fileConfig = YamlConfiguration.loadConfiguration(file);
                        InputStream defConfigStream = this.getResource("playerDefaults.yml");
                        if (defConfigStream != null) {
                            //Main plugin;
                            YamlConfiguration defConfig =                   YamlConfiguration.loadConfiguration(defConfigStream);
                            fileConfig.setDefaults(defConfig);
     
                            fileConfig.save(file);
                        }
                    } catch (IOException e) {
                        log.severe("There was an error while trying to save a player's config file: " + e.getMessage());
                    }
                }
            return YamlConfiguration.loadConfiguration(file);
        }
    playerDefaults.yml: http://pastebin.com/jPb46MeU
    What I'm trying to do is create a reward system (that's add to-able by people who have permission) for voters. Any help would be appericated.

    The problem is that when I do the command, it calls the above function and copies only part of the comments:
    Code:
    #
    # The vanilla blocks for current release are done
    # Moving on to items
    
    Thanks!
     
  2. Offline

    hockeygoalie5

    I wouldn't use YAML for storage like this; it's quicker and better to use a database. SQL is really easy to learn, and if you use SQLite requires no extra installation and is already supported by Bukkit. PatPeter made a nice library that supports SQLite with Bukkit.
     
    justcool393 likes this.
  3. Offline

    justcool393

    Thanks! :)
     
Thread Status:
Not open for further replies.

Share This Page