Saving and loading a players inventory

Discussion in 'Plugin Development' started by Coobro_FTW, Jun 3, 2014.

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

    Coobro_FTW

    Hey guys.

    So I have worked on multiple methods to do this and I still haven't found a solution.

    I want to have a method to save and load players inventory with a yml file.

    All help is appreciated.
     
  2. Coobro_FTW The work you're looking for is "serialized". It's a pretty key word, and so is inventory and maybe bukkit. Key words are good for finding things.
     
  3. Offline

    lycano

    Coobro_FTW Have a look at the source of ItemStack.java and lookup serialize method http://jd.bukkit.org/rb/doxygen/d9/...mStack.html#a93cd42b62bfa604b11abef3b62921317

    Since this structure is constant (type, damage, amount, meta) you can use the same names as keys in your yml file if you want to build your own structure.

    I do not know if metadata also gets "automatically" serialized in that method but if not you might need to do that on your own.

    There seems to be also a way to use ConfigurationSection object to store the whole inventory to YmlConfiguration.
    https://gist.github.com/aadnk/4593947

    Another way to store ItemStacks is via NBT if the previous way via Bukkit API does not work lookup his gist. He has another version online that uses NBT.
    https://gist.github.com/aadnk/11343062

    If you want to store Inventories inside a db one way would be to use BukkitObject(Input|Output)Stream https://forums.bukkit.org/threads/mysql-store-player-inventory-in-database.186344/#post-1931763
     
Thread Status:
Not open for further replies.

Share This Page