how to check if parent contains child config

Discussion in 'Spigot Plugin Development' started by kinukin, Jun 4, 2017.

  1. Code (Text):
    Item:
          Test1:
                  Ghost:
                         Thisisanitem:
                                    Material: WOOD_SWORD
                                    Cost: 5
    How can I check if Thisisanitem is inside Test1?

    I'm using a custom config by the way.

    Thank you!!!

    edit: I've tried doing this but it doesn't get the child node

    Code (Text):
    customConfig.get("Item.Test1.Ghost"));
    I want the child node to act as an object

    I want:

    Code (Text):
    Thisisanitem:
                          Material: WOOD_SWORD
                          Cost: 5
    Is it possible to do so?
     
    #1 kinukin, Jun 4, 2017
    Last edited: Jun 4, 2017
  2. Because of the path it's in? Currently they are all parent paths by the looks of it, considering the lack of indentation.
     
  3. Sorry it's been updated!

    How can I check if Thisisanitem is inside Test1?

    edit: I've tried doing this but it doesn't get the child node

    Code (Text):
    customConfig.get("Item.Test1.Ghost"));
    I want the child node to act as an object
     
    #3 kinukin, Jun 4, 2017
    Last edited: Jun 4, 2017
  4. EDIT: in order to get your special config use this code.

    Code (Text):
    public FileConfiguration getSpecialConfig() {
            return this.special;
        }
    Then just use

    Code (Text):
    getSpecialConfig.contains(path);
     
  5. FileConfiguration#getKeys(true)

    Loop through the keys, doing a deep search, and if a key matches the string you're looking for, check the string after it to see if it's an item, and bam.

    Something like this:

    Code (Text):
            Set<String> keys = getConfig().getKeys(true);
            boolean keyCheck = false;
         
            for (String s : keys) {
                if (keyCheck && Material.matchMaterial(s) != null) {
                      //done
                     return;
                }
                if (s.equalsIgnoreCase("Ghost")) {
                     keyCheck = true;
                } else keyCheck = false;
            }
     

  6. IT doesn't seem to be checking if Ghost has Thisisanitem, how can I get it to work?

    Thanks
     
  7. Learn Java. I just spoon fed you the answer.
    Learn to debug yourself. Print out what the strings are displaying, check whether boolean expressions are being evaluated as expected, etc.

    EDIT: I realise that the check Material#matchMaterial will return null in this case, your case, because Thisisanitem is not actually a variable name for an item. I just included that because you will want to make that check. So, either chance Thisisanitem, to something like WOOD, or remove the check.