Get all children of a node in the config

Discussion in 'Plugin Development' started by AXCoding, Jul 23, 2014.

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

    AXCoding

    Hi, I'm making a plugin in which it needs to be able to get all the children of a node in the config.
    Example:

    Config:
    Code:
    FactionTutorial:
        1:
          text: To join a faction do /f join FactionName
          #Delay in seconds
          delay: 1
        2:
          text: Do /f create to create a faction!
          #Delay in seconds
          delay: 1
    CommandTutorial:
        1:
          text: To join a faction do /f join FactionName
          #Delay in seconds
          delay: 1
        2:
          text: Do /f create to create a faction!
          #Delay in seconds
          delay: 1
    
    What I want:
    If I do
    Code:java
    1. getConfig.getChildrenNode(FactionTutorial){
    2. // Do Stuff Here
    3. }

    It should return 1,2

    I really just need the amount of children nodes.

    Code:
    FactionTutorial:
        randomtext:
          text: To join a faction do /f join FactionName
          #Delay in seconds
          delay: 1
        morerandomtext:
          text: Do /f create to create a faction!
          #Delay in seconds
          delay: 1
    CommandTutorial:
        1:
          text: To join a faction do /f join FactionName
          #Delay in seconds
          delay: 1
        2:
          text: Do /f create to create a faction!
          #Delay in seconds
          delay: 1
    All I need to get out of it is there are 2 child nodes of FactionTutorial.

    Thanks in Advance!:)
     
  2. Offline

    Gater12

  3. Offline

    AXCoding

    Gater12 If you wouldn't mind, I'm kind of a visual learner.. Could you post an example?
    Would it be like
    Code:java
    1. this.getConfig().getConfigurationSection("Main").getKeys(false)

    I don't think thats write because I can't seem to get it to work...
     
  4. Offline

    stormneo7

    Code:
    ConfigurationSection factionSection = getConfig().getConfigurationSection("FactionTutorial");
    for(String s : factionSection.getKeys(false)){
      // Subsections [1, 2]
    }
     
  5. Offline

    Gater12

    AXCoding
    E.g.


    Code:
    section:
      1:
        delay: 50
      2:
        delay: 100
    Code:java
    1. for(String s : getConfig().getConfigurationSection("section").getKeys(false)){
    2. int delay = (getConfig().getInt(s + ".delay"));
    3. /* INSERT LOGIC HERE */
    4. }
     
Thread Status:
Not open for further replies.

Share This Page