0

I'm trying to create a file in a specfic folder holding the players data. However, I've ran into two issues.

  1. The file doesn't get created.
  2. The parent file doesn't get created.

Any ideas would be great, I'm new to the file handling stuff :S

public void saveData() {
    // SAVE THE DATA WHEN THE PLAYER QUITS!
   // if (!shouldCreateFile()) return;
    new BukkitRunnable() {
        @Override
        public void run() {
            System.out.println("DEBUG : " + f.getParentFile().exists());
            System.out.println("DEBUG : " + f.getParentFile());
            if (!f.exists()) {
                System.out.println("DEBUG : 2");
                try {
                    System.out.println("DEBUG : 3");
                    if(!f.getParentFile().exists()) f.getParentFile().mkdirs();
                    System.out.println("DEBUG : 4");
                    f.createNewFile();
                    System.out.println("DEBUG : 5");
                } catch (IOException e) {
                    Bukkit.getServer().getLogger().severe(ChatColor.RED + "******** Could not CREATE the PLAYERDATA file for " + uuid + "! ********");
                }
            }
            d.set("Settings", settings);
            d.set("Kills", kills);
            d.set("Duel_Wins", duelWins);
            d.set("Duel_Losses", duelLosses);
            d.set("Top_KS", topKillstreak);
            try {
                d.save(f);
            } catch (IOException e) {
                Bukkit.getServer().getLogger().severe(ChatColor.RED + "******** Could not SAVE the PLAYERDATA file for " + uuid + "! ********");
            }
        }
    }.runTaskAsynchronously(Main.getInstance());
}

What outputs into the console:

[21:10:36 INFO]: DEBUG : true
[21:10:36 INFO]: DEBUG : plugins/Main:playerdata

How f is defined:

    f = new File(Main.getInstance().getDataFolder() + File.pathSeparator + "playerdata", uuid.toString() + ".yml");
    d = YamlConfiguration.loadConfiguration(f);

Thanks again!

EDIT : It looks like the file WAS created, however not in the specified path. Here is how it turned out.

Arun Xavier
  • 763
  • 8
  • 47
TheCoder24
  • 37
  • 1
  • 1
  • 9

1 Answers1

0

Declare your File object like this.

f = new File(Main.getInstance().getDataFolder() + File.pathSeparator + "playerdata", uuid.toString() + ".yml");

For more reference :

Community
  • 1
  • 1
Arun Xavier
  • 763
  • 8
  • 47