refresh player data?

Discussion in 'Plugin Development' started by Meatiex, Oct 29, 2014.

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

    Meatiex

    Is it possible to reload player's data file in world/playerdata/uuid.dat?

    I'm trying to have different player data files for each world. I all realty made the server copy and paste it to plugins/invs/worldname/uuid.dat and when the player switches worlds that data file is put into world/playerdata, but it will not load...
    current code: http://pastebin.com/7sqLGK65

    i tried save-all, nothing...

    Any help is awesome :D
     
  2. Offline

    _Cookie_

    Why not just save all of there Inventorys and such into a hashmap and load it back when they're in the new world?
     
  3. Offline

    Meatiex

    every item with its enchantments, durability, name, lore, exp, health, foodlevel, stamina...
    all that for every player in every world?

    my server is quite small, but that would be loading about 500 different people in about 500 different worlds... (Every player has their own world), wouldn't that hashmap lag the server a little...?
    //The world system works great, don't worry about it.(World unload when they empty)
     
  4. Offline

    OffLuffy

    Probably not as much as 500 different worlds. Then again, trying to load and handle just as much data per person from file may not be much better.

    (Note: The pounds (#) in the following text is referring to a method in the class name prior to the pound, not a typo. Think JavaDocs)

    If you're just handling inventories, you can write/load to yml files a bit easier than you may think:

    ItemStack can be serialized (meaning you can use FileConfiguration#set(String path, Object obj) method to write it to file). FileConfigurations also have a getItemStack(String path) method. So in effect, you can get the user's inventory, get it's contents, iterate over it and write each item to file, then when loading, iterate over the config and reload each ItemStack into an array. And do the same for Player#getInventory().getArmorContents(). Bit of code

    Code:java
    1. FileConfiguration data; // Pretend this is initialized
    2. Player someone; // This as well
    3. for (int slot = 0; slot < someone.getInventory().getContents().length; slot++)
    4. data.set("items." + slot, someone.getInventory().getContents()[slot]);
    5.  
    6. // Save the data

    Likely a better way to do this, but this would set the contents (likely excluding armor) to file. Player#getInventory() is Iterable<ItemStack>, so you can do:
    for (ItemStack is : player.getInventory()) {}
    But I'm not sure then how you'd get a key to set the item to in the data

    Other data, such as experience, can be set as an int to the yml file ( be sure to use Player#getTotalExperience() and Player#setTotalExperience() )
     
Thread Status:
Not open for further replies.

Share This Page