NBT data with ItemStacks?

Discussion in 'Plugin Development' started by RingOfStorms, Nov 7, 2012.

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

    RingOfStorms

    So I have a plugin that saves an inventory in player.yml. All it does is saves an ItemStack list. However, it keeps everything ItemStack wise, but I loose any custom names/NBT data edits. Am I going to have to save the NBT data for each item and the ItemStack info, or is there an easier way?
     
  2. Offline

    superpeanut911

  3. Offline

    RingOfStorms

    data.set("Inventory", util.itemArrayToList(tempInv.getContents()));

    I just converted the ItemStack[] from Inventory.getContents to a list. ItemStack will save things like enchantments, dura, dmg, etc. But NBT data is not part of it yet.
     
  4. Offline

    one4me

    RingOfStorms
    You could try InventoryIO, it lets you save an inventory as a yml file, and load the file back as an inventory.
    To you it you would do something like this:
    Code:
    /*returns true if successfully saved or false otherwise*/
    boolean saved = InventoryIO.savePlayerInventoryTo("PlayerName", new java.io.File(getDataFolder(), "FileName"));
     
    /*returns a new instance of org.bukkit.inventory.PlayerInventory or null if there was an error*/
    org.bukkit.inventory.PlayerInventory inv = InventoryIO.loadPlayerInventoryFrom(new java.io.File(getDataFolder(), "FileName"));
    
     
Thread Status:
Not open for further replies.

Share This Page