Solved Saving data using ItemMeta lore

Discussion in 'Plugin Development' started by MattTheBeast, Nov 15, 2018.

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

    MattTheBeast

    So I'm building a plugin where I'm storing an invisible string of data (Used to reconstruct an object) in a ItemStack's meta lore.

    The question is: How would I go about saving the data as a lore only when it NEEDS to be saved.

    Ofcours I could just reset the lore with the new data every tick or two, but that would require way to much work. I would only need to set the new lore when the itemstack is no longer in the players inventory. Is there a way for me to check the inventory the itemstack is in?
     
  2. Offline

    Zombie_Striker

    @MattTheBeast
    • If you're listening for when a player interacts with the itemstack, it would probably be best if you look into adding an NBT tag to the item and listening for that.
    • If you need to get the itemstack at any point (not just when a player interacts with it in any way), It would also be best to use NBT tags here, but you will also need to add listeners for when the item is picked up, thrown, moved from inventory to inventory, ect. so that you store where the item is.
     
  3. Offline

    MattTheBeast


    First of all, ty for answering. So if an ItemStack is dropped and I had a reference of it somewhere, will that itemstack that I get from the PlayerDropItemEvent be the same?
     
  4. Offline

    Zombie_Striker

    The itemstack will have the same properties as the object being stored, but it will nort point to the same instance. What that means is that you would need to use .equals to compare the object, so that you're comparing stored values instead of location in memory.
     
  5. Offline

    MattTheBeast

    Ok ty, il also be looking into NBT tags for storing data in itemstacks.
     
Thread Status:
Not open for further replies.

Share This Page