making a YML file for each player

Discussion in 'Plugin Development' started by the_merciless, Oct 25, 2012.

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

    the_merciless

    I need help creating yml files for players, i have been googling it for a while now and to be honest i still dont understand it too well. Does anyone know of a good tutorial that can explain it all for me. Or any advice you can give would be appreciated. Thanks
     
  2. Offline

    thefiscster510

    Put this in your onPlayerJoin event..
    PHP:
    FileConfiguration config null;
    File file = new File("plugins"+File.separator+"YourPluginDirectory"+File.separator+"users"+File.separator+event.getPlayer().getName()+".yml");
    if(!
    file.exists()){
            
    file.createNewFile();
            
    config YamlConfiguration.loadConfiguration(file);
            
    config.set("Player.Name"event.getPlayer());
            
    config.save();
    }
    That will make it so that the first time the player joins, it creates a YML file named after them in /plugin/YourPluginDirectory/users/ and inside sets the node "Player.Name" to their name.. and then saves it.. Stufy that code up there.. It's pretty simple :) (I'm not sure if i got it all right, I'm on my phone..)
     
  3. Offline

    md_5

  4. Offline

    the_merciless

    Great this works fine, how can i now get and set data from other methods/classes?

    Bump

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

    SyTeck

    Just use this:
    Code:
    FileConfiguration config = null;
    File file = new File("plugins"+File.separator+"YourPluginDirectory"+File.separator+"users"+File.separator+event.getPlayer().getName()+".yml");
    config = YamlConfiguration.loadConfiguration(file);
     
    config.set(.....)
    config.save(...)
     
  6. Offline

    the_merciless

    eclipse tells me to surround config.save() with try/catch. Is that neccessary.
     
  7. Offline

    Sagacious_Zed Bukkit Docs

    Yes. Because save may throw an exception which you must handle.
     
  8. Offline

    the_merciless

    Thanks guys i have this working now, and have been playing around with it, getting it to work in different methods/classes etc and I understand it a little better now.
     
Thread Status:
Not open for further replies.

Share This Page