1.15.2 Need help combining player's inventory with an ItemStack[]

Discussion in 'Spigot Plugin Development' started by DapperNurd, Jan 30, 2020.

  1. I currently have a death book type system where when you die, it removes your inventory and drops the book. When you pickup the book and open it, you can click a line of text in the book and it will restore your inventory. Currently, I'm just doing inventory.setContents(); That works well, and it even keeps the last location the items were in when they died, however it clears the inventory before adding the items.
    I want to know if there is a way I can essentially compare the player's current inventory to the ItemStack[] I'm storing the old contents in. If there is nothing in the current player's inventory but there is something in the ItemStack in that specific spot, add it to the player's inventory. If there are something in both in the same index, put the item from the item stack in the next available slot in the player's inventory. If there are no available slots, drop the item in the world. Would this be possible?
  2. You could try looping through the old inventory ItemStack[]. Check if the player's getInventory#firstEmpty() is -1, and if so you can do getWorld()#dropItem() to drop the item. Else, simply do getInventory()#addItem().
  3. Inventory#addItem(ItemStack...) adds the items in the array until the inventory is full and returns a Hash-Map with what it couldnā€˜t store