accessing custom yml file

Discussion in 'Plugin Development' started by vtg_the_kid, Dec 1, 2013.

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

    vtg_the_kid

    hi i made a yml file for each player on join, and i'm wondering how to add stuff to it, here is my unworking code:
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("newplayer")){
    2. if (!playerFile.contains(player.getName()+"used")){
    3. player.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD));
    4. player.getInventory().addItem(new ItemStack(Material.IRON_HELMET));
    5. player.getInventory().addItem(new ItemStack(Material.IRON_CHESTPLATE));
    6. player.getInventory().addItem(new ItemStack(Material.IRON_LEGGINGS));
    7. player.getInventory().addItem(new ItemStack(Material.IRON_BOOTS));
    8. player.getInventory().addItem(new ItemStack(Material.COOKED_FISH, 16));
    9. File playerFile = new File(newFolder +
    10. File.separator + player.getName() + ".yml");
    11. playerFile.addDefault("usedkit", player.getName()+"used");
    12. }
    13. }
     
  2. Offline

    M0n0clink

  3. Offline

    shawshark

    Code:java
    1. @EventHandler
    2. public void playerjoinevent(PlayerJoinEvent e) {
    3. Player p = e.getPlayer();
    4. if (!e.getPlayer().hasPlayedBefore()) {
    5. // Code
    6. } else {
    7. // else
    8. }
    9. }
     
  4. Offline

    vtg_the_kid

    Ok i think you guys misunderstood me​
    but here's my new code​
    Code:java
    1. @EventHandler
    2. public void joinTime(PlayerJoinEvent event){
    3. Player player = event.getPlayer();
    4. FileConfiguration config = null;
    5. File playerFile = new File(newFolder +
    6. File.separator + player.getName() + ".yml");
    7. config = YamlConfiguration.loadConfiguration(playerFile);
    8. if(!playerFile.exists()){
    9. try{
    10. config.save(playerFile);
    11. }
    12. catch(Exception e){
    13. System.out.println("A file could not be created for " + player.getName() + ".");
    14. }
    15. }
    16. }

    now how would i access these files and add stuff to them in different methods
     
  5. Offline

    vtg_the_kid

    bump
    how would i add defaults to these player files in a different method? like if a player types /add then "added" gets added to their file
     
Thread Status:
Not open for further replies.

Share This Page