Get a deep copy of an inventory

Discussion in 'Spigot Plugin Development' started by SIndybad, Jun 18, 2015.

  1. How can you get a deep copy of an inventory?
  2. Can you tell me what deep is? Sorry in advance if it is something that should be known, but tbh I currently have no clue what you mean by deep copy
  3. Say variable B is a deep copy of A, when you change A it will not change B and vice versa
    Whereas, if you have a shallow copy, modifying B will modify A
  4. Why would you need this? I'm sure there's an easier way, otherwise you'd have to manually get the contents and clone the ItemStacks.
  5. I'm converting Inventory to String, but every time I convert, I add the armor to the inventory(which is the player's inventory). However, if I created a fake inventory, I could just add the armor to that
  6. There's no way around what @Coder already mentioned: You either have to clone all ItemStacks yourself or you build in some special case handling for the armor you wish to add in your converter.
  7. Never mind, fixed it with this:
    Code (Text):

    for(ItemStack i : player.getInventory().getArmorContents()){
    if(i != null){