Inventory set/get Contents not working correctly.

Discussion in 'Spigot Plugin Development' started by Folf, Apr 30, 2017.

  1. I'm trying to make a kinda kit system for my plugin, and I'm saving the kits into the config using getContents, no errors in the console are printed, but the kits are returning items with no quantity, making them have that red 0.

    upload_2017-4-30_12-34-17.png

    The error seems to only happen sometimes, but i'm not being able to find whats causing it.

    Code (YAML):

    '7'
    :
      name
    : test
      contents
    :
      - ==
    : org.bukkit.inventory.ItemStack
        type
    : DIAMOND_SWORD
        damage
    : 16
        meta
    :
          ==
    : ItemMeta
          meta-type
    : UNSPECIFIC
          enchants
    :
            THORNS
    : 3
          repair-cost
    : 1
      - ==
    : org.bukkit.inventory.ItemStack
        type
    : DIAMOND_LEGGINGS
        meta
    :
          ==
    : ItemMeta
          meta-type
    : UNSPECIFIC
          enchants
    :
            THORNS
    : 3
          repair-cost
    : 1
      - ==
    : org.bukkit.inventory.ItemStack
        type
    : BOW
        meta
    :
          ==
    : ItemMeta
          meta-type
    : UNSPECIFIC
          enchants
    :
            PROTECTION_FALL
    : 4
          repair-cost
    : 1
      - ==
    : org.bukkit.inventory.ItemStack
        type
    : MUTTON
      - ==
    : org.bukkit.inventory.ItemStack
        type
    : PORK
      - ==
    : org.bukkit.inventory.ItemStack
        type
    : ARROW
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null

     

    Code (YAML):

    '5'
    :
      name
    : CUZISSE
      contents
    :
      - ==
    : org.bukkit.inventory.ItemStack
        type
    : DIAMOND_SWORD
        damage
    : 16
        amount
    : 0
        meta
    :
          ==
    : ItemMeta
          meta-type
    : UNSPECIFIC
          enchants
    :
            THORNS
    : 3
          repair-cost
    : 1
      - ==
    : org.bukkit.inventory.ItemStack
        type
    : DIAMOND_LEGGINGS
        amount
    : 0
        meta
    :
          ==
    : ItemMeta
          meta-type
    : UNSPECIFIC
          enchants
    :
            THORNS
    : 3
          repair-cost
    : 1
      - ==
    : org.bukkit.inventory.ItemStack
        type
    : BOW
        amount
    : 0
        meta
    :
          ==
    : ItemMeta
          meta-type
    : UNSPECIFIC
          enchants
    :
            PROTECTION_FALL
    : 4
          repair-cost
    : 1
      - ==
    : org.bukkit.inventory.ItemStack
        type
    : MUTTON
        amount
    : 0
      - ==
    : org.bukkit.inventory.ItemStack
        type
    : PORK
        amount
    : 0
      - null
      - ==
    : org.bukkit.inventory.ItemStack
        type
    : ARROW
        amount
    : 0
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
     

    Code I use to save the kits:
    Code (Java):

    kitsfile.set(id + ".contents", p.getInventory().getContents());
     
    Code I use to load the kits:
    Code (Java):

    p.getInventory().setContents( (ItemStack[]) file.get(i + ".contents"));
     
     
  2. I don;t know much, but meta-type: UNSPECIFIC Might be a hint.
     
  3. sothatsit

    Patron

    So, don't save the kits with items of amount 0.
     
  4. But the kits don't have amout of 0, I had an inventory with armor sword etc., save it, cleared the inventory and then got the kit, and It returned like the image.
     
  5. sothatsit

    Patron

    Ah I see. You could set the amounts of the items when you load them but otherwise I don't know what the nature of this glitch is.
     
  6. Its weird, I tried creating two kits using the same items, one of them glitched, other one didn't
     
  7. sothatsit

    Patron

    Strange. Was it a one time thing or is it continuing to happen?
     
  8. Its continuing to happen.
     
  9. sothatsit

    Patron

    Alright. For a bandaid solution I would set the amounts of the items as you load them to 1 if they are 0. Otherwise, at this point I don't know why this glitch is happening and how to fix it.
     
    #9 sothatsit, Apr 30, 2017
    Last edited: Apr 30, 2017
  10. I will try it