Get stuff

Discussion in 'Plugin Development' started by DogeDebugger, May 23, 2015.

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

    DogeDebugger

    I'm pretty sure i did this before, but i don't remember how.

    Say i had this in a file
    Code:
    Contents:
      '0':
        ==: org.bukkit.inventory.ItemStack
        type: DIAMOND_SWORD
        meta:
          ==: ItemMeta
          meta-type: UNSPECIFIC
          display-name: 'name '
          enchants:
            FIRE_ASPECT: 2
          repair-cost: 2
      '1':
        ==: org.bukkit.inventory.ItemStack
        type: ANVIL
      '2':
        ==: org.bukkit.inventory.ItemStack
        type: DIAMOND_SWORD
        amount: 3
        meta:
          ==: ItemMeta
          meta-type: UNSPECIFIC
          display-name: 'name '
          lore:
          - "\xa7rhi"
          enchants:
            FIRE_ASPECT: 2
          repair-cost: 2
    As you can infer, those are serialized itemstacks i saved (thanks nverdier lmao)

    So anyway, to get to the point, im trying to load a GUI from those itemstacks. How do i get all the itemstacks in the path "Contents?"

    I tried:
    Code:
    public void openWeaponShop(Player p) throws IOException {
         MenuMaker menu = new MenuMaker(plugin, "Weapon Shop", 5);
         File file = new File(plugin.getDataFolder(), "weaponshop.yml");
         if(!(file.exists()))
           try {
             file.createNewFile();
           } catch (IOException e1) {
             e1.printStackTrace();
           }
         FileConfiguration items = YamlConfiguration.loadConfiguration(file);
         List<ItemStack> contents = ((List<ItemStack>) items.get("Contents"));
         for(ItemStack n: contents) {
           menu.addItem(n);
         }
         menu.showMenu(p);     
       }
     
    
    (I am adding the items to the inventory correctl
     
  2. Offline

    mine-care

    Isn't there a deserialize method provided with the serialise one ?
     
  3. Offline

    DogeDebugger

    not that i know of
     
  4. Offline

    caderape

    @DogeDebugger
    it's the serialize method from bukkit, so yea, there is.
    loops the configuration section 'contents'
    and config.getItemStack(path);
     
  5. Offline

    DogeDebugger

    Code:
    public void openWeaponShop(Player p) throws IOException {
            MenuMaker menu = new MenuMaker(plugin, "Weapon Shop", 5);
            File file = new File(plugin.getDataFolder(), "weaponshop.yml");
            if(!(file.exists()))
                try {
                    file.createNewFile();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            FileConfiguration items = YamlConfiguration.loadConfiguration(file);
            ItemStack itemstack = items.getItemStack("Contents");
            menu.addItem(itemstack);
            menu.showMenu(p);       
        }
       
    
    My GUI comes up blank...
    Code:
    Contents:
      '0':
        ==: org.bukkit.inventory.ItemStack
        type: DIAMOND_SWORD
        amount: 3
        meta:
          ==: ItemMeta
          meta-type: UNSPECIFIC
          display-name: 'name '
          lore:
          - "\xa7rhi"
          enchants:
            FIRE_ASPECT: 2
          repair-cost: 2
      '1':
        ==: org.bukkit.inventory.ItemStack
        type: CAKE
        amount: 64
      '2':
        ==: org.bukkit.inventory.ItemStack
        type: DIAMOND_SWORD
        meta:
          ==: ItemMeta
          meta-type: UNSPECIFIC
          display-name: 'name '
          enchants:
            FIRE_ASPECT: 2
          repair-cost: 2
      '3':
        ==: org.bukkit.inventory.ItemStack
        type: CAKE
        amount: 64
      '4':
        ==: org.bukkit.inventory.ItemStack
        type: CAKE
        amount: 64
      '5':
        ==: org.bukkit.inventory.ItemStack
        type: GOLD_LEGGINGS
      '6':
        ==: org.bukkit.inventory.ItemStack
        type: GOLD_BOOTS
      '7':
        ==: org.bukkit.inventory.ItemStack
        type: GOLD_BOOTS
      '8':
        ==: org.bukkit.inventory.ItemStack
        type: IRON_LEGGINGS
      '27':
        ==: org.bukkit.inventory.ItemStack
        type: CAKE
        amount: 64
      '28':
        ==: org.bukkit.inventory.ItemStack
        type: GOLD_HELMET
      '29':
        ==: org.bukkit.inventory.ItemStack
        type: CAKE
        amount: 32
      '30':
        ==: org.bukkit.inventory.ItemStack
        type: CAKE
      '31':
        ==: org.bukkit.inventory.ItemStack
        type: CAKE
      '32':
        ==: org.bukkit.inventory.ItemStack
        type: CAKE
        amount: 64
      '33':
        ==: org.bukkit.inventory.ItemStack
        type: CAKE
        amount: 61
      '34':
        ==: org.bukkit.inventory.ItemStack
        type: CAKE
        amount: 64
      '35':
        ==: org.bukkit.inventory.ItemStack
        type: CAKE
    
     
  6. Offline

    Zombie_Striker

    @DogeDebugger
    Did you debug? Are there any null tests? Does it retrieve any data from the config?
     
  7. Offline

    caderape

    @DogeDebugger
    ItemStack itemstack = items.getItemStack("Contents");
    what did u expect ? contents dont have itemstack as a value, it's just number.
    i told you to use configuration section
     
  8. Offline

    DogeDebugger

    oh...okay, i'll try
     
  9. Offline

    _Filip

    *sigh* poor guy
    section = getConfigurationSection("contents")
    String slotString : section.getKeys(false)
    itemStack = section.getItemStack(slotString)
     
  10. Offline

    caderape

    @_Filip You forgot the path
    config.getItemStack("contents."+slotString);

    edit; oh nvm, i tot it was the creator of the thread ;)
     
Thread Status:
Not open for further replies.

Share This Page