Solved Saving an inventory to an itemstack

Discussion in 'Plugin Development' started by MrSpicedBacon, Jul 13, 2014.

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

    MrSpicedBacon

    Hi,

    Lately I've been searching for a way to attach an inventory to an itemstack and I've found out how to convert a inventory to a string, but how do I save the inventory so it's unique for every itemstack?

    I've seen that every itemstack has a 'hashcode' (Is this unique for each itemstack?), but if the itemstack gets renamed (by an anvil) the hashcode changes.. (Are there other ways that change an itemstack's hashcode?)
    If this works, should I write the inventory-string to a .yml file with the hashcode, or is there a better way to do this?

    Excuse me for my poor English,
    Bacon
     
  2. Offline

    masons123456

    MrSpicedBacon
    If you don't mind me asking, why are you "attatching" an Inventory to an ItemStack?
     
  3. Offline

    MrSpicedBacon

    I'm trying to make a plugin when you right click on an item it will open an inventory (every item has it's own inventory).
     
  4. Offline

    MrSpicedBacon

  5. Offline

    xize

    MrSpicedBacon

    what you could do but of course I believe its not the best practice:

    create an uuid based on the players name and followed by the timestamp, maybe is using only the timestamp more suitable though.

    create a file where you store all inventory contents where the UUID is just the file name, perhaps you wish to remove the dashes though.

    then convert the uuid string to a color string by interating at every char and by adding ChatColor.CHAR before every char, of course make sure the uuid does not have dashes anymore.

    put that string as an lore into the ItemStack, as result that line would be invisible but you could still read that lore.

    ChatColor.CHAR is just ยง, so with other words to read it you would have to do getLore().get(5).replaceAll(ChatColor.CHAR, "");


    no credits to me though about the lores, ive found it on a other thread but I geuss its pretty cool.
     
  6. Offline

    thomasb454

    You wouldn't convert an inventory into an ItemStack, you'd convert if into an ItemStack[] (ItemStack array).
     
  7. Offline

    MrSpicedBacon

    xize
    That's pretty clever, I'll try it out!

    thomasb454
    I don't think you understand what I'm trying to say...
     
  8. Offline

    thomasb454


    Probably not, just telling you that you cannot store a whole inventory contents within a single ItemStack.
     
    MrSpicedBacon likes this.
  9. Offline

    Wizehh

    Use a Map<ItemStack, Inventory>
     
Thread Status:
Not open for further replies.

Share This Page