Update ItemMeta/lore without refreshing player inv

Discussion in 'Spigot Plugin Development' started by KingFaris10, May 27, 2017.

  1. Hi, is there a way to update the ItemMeta of an ItemStack without updating the player's inventory (refreshing it).
    i.e. The new item meta should be shown to the server but not to the player.

    Specifically in the item meta, I want to update an item's lore without refreshing it to the player.
    Reason behind this is: Every time a player shoots an arrow, I'm updating the item's lore. This means when they draw the bow again, midway through drawing it cancels since it updates the inventory, so the player has to redraw again which is annoying for players.

    My solution is to update the lore for the server to see as updated but for the player not to see, and manually calling player.updateInventory() when they open an inventory.
  2. Eh, just get the inventory, get the item, get the ItemMeta, set new Lore or whatever, get inventory viewers, updateInv..?
  3. Setting the new lore may not update inv, but setting item meta of the itemstack automatically updates the player's inventory.
  4. Set new Lore.. Apply new ItemMeta to item..
  5. My problem is, I don't want to update the player's inventory. Updating the player's inventory cancels the drawing back of the player's bow, so I'm trying to prevent updating the bow's lore from updating the player's inventory.
  6. AFAIK, you can't. Thats the same as that you want to use a red pen but without red..
  7. Thanks. And I don't agree with your analogy. The server contains all the items a player has in their inventory. The player just sees what the server sends it. So I want to see if there's way to modify the lore of an item so the server now has this updated lore, but the player sees the old lore i.e. the server doesn't send an update to the player.

    In your pen analogy, this would be like:
    I have a red pen but something divine makes it blue, but I see it as red still. So really, it's a blue pen (and the divine knows this), but I still see it as red.
  8. Not sure if possible but i think there is a packet that sends a update to the player for the inventory (Not sure which), you could intercept that packet with Protocollib and cancel it and send the update later?
  9. Yeah I thought about that but the update packets don't give any information on:
    - The player
    - The item
    - The item's slot

    It only gives the list of items in the inventory.
  10. Hmmm. Can't you loop through that list and check for your item?
  11. Even if the bow's found, there still needs to be a way to get the player from the packet since I only want to cancel inventory update packet if the player doesn't have an inventory open.