Creating a config for each player on join.

Discussion in 'Plugin Development' started by hubeb, May 12, 2013.

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

    hubeb

    I want to create a config file for each player that joins my server, so i can save some values within it.
    I tried to use SQL but i cant find any good tutorials that i can understand.
    Ive tried to make a config file for each player, but i cant get it to work.

    I want to save a file named (playersname.config) in a players folder. Any tutorials or help would be suggested.

    Thanks,
    Hubeb
     
  2. Offline

    ZeusAllMighty11

    Code:
    File playersDir = new File(getDataFolder() + File.separator + "players");
    if(!playersDir.exists()){
        playersDir.mkdir();
    }
     
    File playerFile = new File(getDataFolder() + File.separator + "players" + File.separator + somePlayer.getName() + ".config");
    if(!playerFile.exists()){
         playerFile.createNewFile(); // needs try catch block
    }
     
  3. Offline

    hubeb

    Ill give it a try and reply with the results
    Thanks for the speedy response.

    TheGreenGamerHD
    ok that works, but how would I read/write to the players file?

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

    ZeusAllMighty11

    Well a .CONFIG is not a readable filetype for the YAMLConfiguration, however changing the extension to .yml will allow for it

    Code:
    FileConfiguration fc = YamlConfiguration.loadConfiguration(myFile);
    fc.set("Message_1", "Hello World");
    fc.save(myFile);
    
     
  5. Offline

    Diamondminer77

    Because players will be allowed to change usernames in an update that's coming, you will need to use someplayer.getUniqueId() instead of someplayer.getName(), because players can change their name, but they can't change their unique id
     
  6. Offline

    beeselmane

    I would actually do UUID(Name).yml for the config files just to make it more of a readable option (player.getUniqueId().toString() + '(' + player.getName() + ')' + ".yml")
     
Thread Status:
Not open for further replies.

Share This Page