Solved Reading an ItemStack[] from config.

Discussion in 'Plugin Development' started by Link_Awesomesause, May 3, 2016.

Thread Status:
Not open for further replies.
  1. Just like the title, how do we read an ItemStack[] from config?
    the code up till now:
    Code:
    ItemStack is = new ItemStack(Material.BONE);
    ItemStack isis = new ItemStack(Material.DIRT);
    ItemStack[] ais = {is, isis};
    
    getConfig().set("data", ais);
    And the problem is reading the data to get an ItemStack[] again.
     
  2. Offline

    WolfMage1

    Save the names of the Material's to the config, loop through the list, and create a new ItemStack and use Material.getMaterial(String) to get the value of it.
     
  3. That would work, but I even need to get ItemMeta.
     
  4. Offline

    WolfMage1

    (If you want to get the meta of the item)
    ItemMeta meta=stack.getItemMeta();
    stack.setItemMeta(meta);

    or if it's a skull

    SkullMeta meta=(SkullMeta) skull.getItemMeta();
    skull.setItemMeta(meta);

    if you want to save the meta then just get it and put the value into your config

    getConfig().set("my.path.to.itemstack.name", stack.getItemMeta().getDisplayName());
     
  5. That would work but will mess up for an ItemStack[], because every Item in the array will have different lore and names..
     
  6. Offline

    I Al Istannen

    @Link_Awesomesause
    You can save a List (e.g. An arraylist) in the config and retrieve it with config.get(String). You need to cast it back to a List<ItemStack> and they should all be correct and with ItemMeta. Works for me, should do that for you too.
    To convert an array to a List, you can use Arrays.asList(array). To convert it back there is a method List#toArray() (Stackoverflow).
     
Thread Status:
Not open for further replies.

Share This Page