Solved Getting config values(List<ItemStack>)

Discussion in 'Plugin Development' started by Gorbit99, Nov 29, 2015.

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

    Gorbit99

    I have a config file like this:
    Code:
    Recipes:
      diamond:
        ingredients:
        - ==: org.bukkit.inventory.ItemStack
          type: COAL
        - ==: org.bukkit.inventory.ItemStack
          type: COAL
        - ==: org.bukkit.inventory.ItemStack
          type: COAL
        result:
          ==: org.bukkit.inventory.ItemStack
          type: DIAMOND
      diamond_sword:
        ingredients:
        - ==: org.bukkit.inventory.ItemStack
          type: DIAMOND
        - ==: org.bukkit.inventory.ItemStack
          type: DIAMOND
        - ==: org.bukkit.inventory.ItemStack
          type: STICK
        result:
          ==: org.bukkit.inventory.ItemStack
          type: DIAMOND_SWORD
    
    I want to get the groups under "Recipes" in a list, but everything I tried so far returned nothing. Which one of the getters do I need to use?

    Read if it's not clear for you:
    I want a list, with the groups under "Recipes" in a String format, so I can use them as a path. The problem is, that if I use a getStringList() it won't return anything, and if I cast an undefined list to "List<String>", once again, it won't return anything. How could I do that?

    EDIT: Okay, I found the solution to my first problem, but now I need help in getting the ItemStack lists.

    -Gorbit99
     
    Last edited: Nov 29, 2015
  2. Offline

    DoggyCode™

    Use for loops:
    Code:
    for(String recipes : getConfig().getString("Recipes"){
      getLogger().log(recipes.toString()); //returns all the different recipes (ex: "diamond_sword")
      for(ItemStack ingredients : getConfig().getString(recipes.toString()){
        getLogger().log(ingredients.getType().toString()); //returns the itemstacks
      }
    }
    I'm not very sure if this will work, but worth a shot!
     
  3. Offline

    mcdorli

    Probably won't, Recipes is a configurationsection, he need to do
    Code:
    List<String> recipes = getConfig().getConfigurationSection("Recipes").getKeys(false);
    
     
  4. Offline

    Gorbit99

    Like I said, that problem were solved, the problem now, is that I don't know, how to get a list of ItemStack
     
  5. Offline

    Scimiguy

    You get a list of strings, then make the itemstacks out of those strings
     
  6. Offline

    Gorbit99

    How could I do that? GetStringList doesn't return anything.

    EDIT:
    nevermind, I solved it by storing the three ingredient in different paths
     
Thread Status:
Not open for further replies.

Share This Page