Per Player Flatfile Database

Discussion in 'Plugin Development' started by FlawlezZ, Oct 23, 2013.

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

    FlawlezZ

    Hey,

    I want to save playerdata in my plugin. Does anyone of you know any resource / tutorial for that?
    I already made a config.yml file, but I don't know how to make a file per player. Please help ? :p
     
  2. Offline

    Pizza371

    File f = new File(getDataFile(), "/path/" + player.getName() + ".yml");
    f.createNewFile() //surrounded with try / catch
    YamlConfiguration playeryaml = YamlConfiguration.loadConfiguration(f);
    then..
    you can
    playeryaml.set("isTree", true);
    playeryaml.getBoolean("isTree");
    FlawlezZ
     
  3. Offline

    FlawlezZ

    Pizza371 Where should I put the first 3 lines?
     
  4. Offline

    Pizza371

    FlawlezZ well it would be smart to put it in as a local variable since variables will change every time (with player names).
    Although you could create a methhod such as
    private YamlConfiguration getPlayerYaml(Player p) {
    File f = new File(getDataFolder(), "/" + path + p.getName() + ".yml");
    if(!(f.exists())) f.createNewFile();
    YamlConfiguration y = YamlConfiguration.loadConfiguration(f);
    return y;
    }
    So then you could make someone a yaml file w/ getPlayerYaml(p).callMethod();
     
  5. Offline

    FlawlezZ

    Pizza371 Thx so far. Does path mean plugins/Prostitutionplugin/ or just Prostituionplugin/ ?

    What's wrong with this?The boolean always returns false even though the player is existing.

    public String playerfolder = "players/";

    Code:java
    1.  
    2. public boolean existsPlayer(String name){
    3. List<File> l = Arrays.asList(new File(playerfolder).listFiles());
    4. for(File f : l){
    5. if(f.getName().equalsIgnoreCase(name + ".yml")){
    6. return true;
    7. }
    8. }
    9. return false;
    10. }
    11.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  6. Offline

    The_Doctor_123

    Pizza371
    Code/syntax tags please..

    Uhhhh...
     
    1Rogue likes this.
  7. Offline

    FlawlezZ

    Fuck it I got it. I just forgot getDataFolder(), playerfolder.

    Thx guys.
     
  8. Offline

    Pizza371

    The_Doctor_123
    yeah i forgot sry but it was only short code and i wrote it on here
     
Thread Status:
Not open for further replies.

Share This Page