Getting config parent

Discussion in 'Spigot Plugin Development' started by MadMaxCookie, May 27, 2016.

  1. Hello so I have this config sample

    Code (Java):
    Config:
     s: true
    String parent = // how to get the String "Config" as s parent ?
     
  2. How are you Accessing s:?
     
  3. well at this config sample the parent config tree of s is the Config

    I wanted to get the parent of s as a string.

    String sample = // must be return to "Config";
     
  4. why not use the method getParent()
     
  5. Code (Java):
    Set<String> s = Config#getConfigurationSection("Config").getKeys(false);
    like this ?
     
  6. What are you trying to do, Are you just trying to get all of the keys of a config? Like, What keys do you want out of this config.
    Code (Text):
    Ob1:
      tag1:
         data: "datatest1"
    Ob2:
      tag2:
        data: "testdata"
     
     
  7. yeah like that :D

    Code (Java):
    Ob1:

      tag1:
         ItemStack: value
      tag2:
          ItemStack: value
    well I'm getting the value of Ob1 config section + ".ItemStack"; // just to check if the result on the crafting event is the itemstack in the config.

    now I'm trying to get the Ob1 (Parent) as a string so I can do permission something like craft.<ParentName>
     
  8. so, you have a list of ob's and you want to run though all of them right?
     
  9. yes in craft event I want to check if the result is equals to

    Code (Java):
    Set<String> set = Config#getConfigurationSection(Ob1).getKeys(false);
    then getting the ItemStack by using

    Code (Java):
    ItemStack stack = set + ".ItemStack";
    then checking if they have permission craft.Ob1;

    this is what I'm trying to do.
     
  10. You can get the file path, so if you have your Configuration Section object still you can use
    Code (Text):
    config.getConfigurationSection("foo.foo2").getCurrentPath();
    and if you need to split out just your ob1 use String#.split('.'); and it converts it to an array.
     
  11. Code (Java):
    config.getConfigurationSection("foo.foo2").getCurrentPath();
    foo.foo2 returns to the path where they are ?

    example
    Code (Java):
    Obj1: // is this where the config section foo.foo2 currentpath?
      foo:
         foo2:
     
  12. You Already have the Ob1 path when you search for the keys, I am still unsure what you are asking, Because .getParent() was not what you where looking for or .getRoot();
     
  13. let me try that
    how about this ?

    Code (Java):
    Set<String> s : Config#getConfigurationSection(" ").getKeys(false);
    ConfigurationSection section = Config#getConfigurationSection(s + ".ItemStack").getParent();
    String parentname section.toString();
    // config.yml

    Code (Java):
    Name:
      ItemStack: value
     
  14. What would you put in the blank.
     
  15. nothing just a blank
    Code (Java):
    Set<String> s : Config#getKeys(false); // recode
     
  16. Config
    Code (Text):
    Items:
      Name1:
         Item:
      Name2:
         Item:
     
    Code (Text):
    Set<String> s = config.getConfigurationSection("Items").getKeys(false);
            for(String key :s){
                if(isItem(s)){
                    System.out.println(key);
                    System.out.println(config.getItemStack("Items."+ key +"Item"));
                }
            }
    Is this what you are asking, :D?
     
  17. well I have this kind of config
    Code (Java):
    MadMax:
      Input:
        ==: org.bukkit.inventory.ItemStack
        type: LOG
        amount: 4
      Product:
        ==: org.bukkit.inventory.ItemStack
        type: STONE
      Enabled: true
      Type: Furnace
    craft:
      Slot4:
        ==: org.bukkit.inventory.ItemStack
        type: CHEST
      Slot5:
        ==: org.bukkit.inventory.ItemStack
        type: CHEST
      Slot6:
        ==: org.bukkit.inventory.ItemStack
        type: CHEST
      Product:
        ==: org.bukkit.inventory.ItemStack
        type: WORKBENCH
        amount: 2
      Enabled: true
      Type: Shaped
    woodpecker:
      Slot2:
        ==: org.bukkit.inventory.ItemStack
        type: WOOD
        damage: 1
      Slot4:
        ==: org.bukkit.inventory.ItemStack
        type: WOOD
        damage: 1
      Slot5:
        ==: org.bukkit.inventory.ItemStack
        type: WOOD
        damage: 1
      Slot6:
        ==: org.bukkit.inventory.ItemStack
        type: WOOD
        damage: 1
      Slot8:
        ==: org.bukkit.inventory.ItemStack
        type: WOOD
        damage: 1
      Product:
        ==: org.bukkit.inventory.ItemStack
        type: WOOD
        damage: 1
        amount: 2
        meta:
          ==: ItemMeta
          meta-type: UNSPECIFIC
          display-name: WoodPecker
      Enabled: true
      Type: Shaped
    redblock:
      Slot4:
        ==: org.bukkit.inventory.ItemStack
        type: REDSTONE_BLOCK
        amount: 2
      Slot5:
        ==: org.bukkit.inventory.ItemStack
        type: REDSTONE_BLOCK
        amount: 2
      Product:
        ==: org.bukkit.inventory.ItemStack
        type: REDSTONE
        amount: 4
      Enabled: true
      Type: Shaped
    Set<String> s = Config#getKeys(false);
    then I'm checking at the craft event if the result is equals to the itemstack s + ".Product"; and has the permission for example

    craft.redblock
     
  18. Yea, I gave you the basic structure to do that.