save players inventory to a path

Discussion in 'Plugin Development' started by Minesuchtiiii, Sep 9, 2014.

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

    Minesuchtiiii

    Hey guys, I actually got a problem,

    I'm coding a minigame, where at a certain place it saves a players inventory, to a path in the config.
    So to execute this I made a new command, then this code will be executed:

    Code:java
    1. public void saveInv(Player p) {
    2.  
    3. ArrayList<ItemStack> items = new ArrayList<ItemStack>();
    4.  
    5. File file = new File("plugins/pvp/Inventories/" + p.getName() + ".yml");
    6.  
    7.  
    8. if(!(file.exists())) {
    9.  
    10. try {
    11. file.createNewFile();
    12. } catch (IOException e) {
    13. e.printStackTrace();
    14. }
    15.  
    16. YamlConfiguration inv = YamlConfiguration.loadConfiguration(file);
    17.  
    18. ItemStack[] its = p.getInventory().getContents();
    19. for(int i = 0; i < its.length; i++) {
    20. ItemStack item = its[i];
    21. if(item != null) {
    22. items.add(item);
    23. }
    24. }
    25.  
    26. inv.set("Inventory", items);
    27. try {
    28. inv.save(file);
    29. } catch (IOException e) {
    30. e.printStackTrace();
    31. }
    32. p.getInventory().clear();
    33.  
    34. }
    35.  
    36.  
    37. }[/i]


    the thing is, it's only working for one player, so if the player is called "Boxer" there will be a new file which is called Boxer.yml.
    but if another players executes this command nothing happens...
    If someone could help me it would be really nice, a big thanks!
     
  2. Offline

    Minesuchtiiii

  3. Offline

    Minesuchtiiii

    AdamQpzm

    Code:java
    1. [16:45:14 WARN]: at java.io.WinNTFileSystem.createFileExclusively(Native
    2. [16:45:14 WARN]: at java.io.File.createNewFile(Unknown Source)
    3. [16:45:14 WARN]: at main.Main.saveInv(Main.java:132)
    4. [16:45:14 WARN]: at commands.Finished.onCommand(Finished.java:25)
    5. [16:45:14 WARN]: at org.bukkit.command.PluginCommand.execute(PluginComman
    6. d.java:44)
    7. [16:45:14 WARN]: at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    8. mmandMap.java:180)
    9. [16:45:14 WARN]: at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCo
    10. mmand(CraftServer.java:740)
    11. [16:45:14 WARN]: at net.minecraft.server.v1_7_R3.PlayerConnection.handleC
    12. ommand(PlayerConnection.java:956)
    13. [16:45:14 WARN]: at net.minecraft.server.v1_7_R3.PlayerConnection.a(Playe
    14. rConnection.java:817)
    15. [16:45:14 WARN]: at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(Packe
    16. tPlayInChat.java:28)
    17. [16:45:14 WARN]: at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(
    18. PacketPlayInChat.java:47)
    19. [16:45:14 WARN]: at net.minecraft.server.v1_7_R3.NetworkManager.a(Network
    20. Manager.java:157)
    21. [16:45:14 WARN]: at net.minecraft.server.v1_7_R3.ServerConnection.c(Sourc
    22. eFile:134)
    23. [16:45:14 WARN]: at net.minecraft.server.v1_7_R3.MinecraftServer.v(Minecr
    24. aftServer.java:667)
    25. [16:45:14 WARN]: at net.minecraft.server.v1_7_R3.DedicatedServer.v(Dedica
    26. tedServer.java:260)
    27. [16:45:14 WARN]: at net.minecraft.server.v1_7_R3.MinecraftServer.u(Minecr
    28. aftServer.java:558)
    29. [16:45:14 WARN]: at net.minecraft.server.v1_7_R3.MinecraftServer.run(Mine
    30. craftServer.java:469)
    31. [16:45:14 WARN]: at net.minecraft.server.v1_7_R3.ThreadServerApplication.
    32. run(SourceFile:628)



    at main.Main.saveInv(Main.java:132):

    Code:java
    1. file.createNewFile();


    at commands.Finished.onCommand(Finished.java:25)
    Code:java
    1. this.plugin.saveInv(p);


    Ps: now if another player does /finished the file also creates.. everythin's fine, i just need help to remove the error which you can see above.
    Thanks!
     
  4. Minesuchtiiii Well your stacktrace isn't helpful for that, you missed the key parts :p But according to the message you gave, the folder you are trying to create the file in doesn't exist.
     
  5. Offline

    Minesuchtiiii

    AdamQpzm ya I thought that too, but when I looked in the folder where the file should be created the file was there... strange thing
     
Thread Status:
Not open for further replies.

Share This Page