Get all items in config file

Discussion in 'Plugin Development' started by arinerron, May 6, 2015.

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

    arinerron

    Ok so here is my problem. I want to get all of the String that are beneath Minigame. For example I want the below config file so when I do it it gives me the list {"MG", "MiniG"}. I'm really sorry if this is a confusing question, I don't know how to say it in words. Basically I want to get a list of all the sub-configs beneath Minigame, so in this example it'd return MG and MiniG.
    Code:
    # Data for Minigame plugin is located here.
    Minigame:
      MG:
        title: MG
        minplayers: 3
        maxplayers: 20
        lobby:
          x: 24.471761549705942
          y: 65.0
          z: 214.49650359450865
          world: tester
        spawnstart:
          x: 20.48164620457543
          y: 65.0
          z: 205.93598638629672
          world: tester
        spawnend:
          x: 20.43698998564763
          y: 65.0
          z: 224.15009702960185
          world: tester
     
      MiniG:
        title: MiniG
        minplayers: 3
        maxplayers: 20
        lobby:
          x: 24.471761549705942
          y: 65.0
          z: 214.49650359450865
          world: tester
        spawnstart:
          x: 20.48164620457543
          y: 65.0
          z: 205.93598638629672
          world: tester
        spawnend:
          x: 20.43698998564763
          y: 65.0
          z: 224.15009702960185
          world: tester
    Please, if you understand my question and you know how to express it better than I did, please tell me! :p Thanks alot!
     
  2. Offline

    TheDiamond06

    @arinerron I have had a similar occurrence like this, I think I get what you are saying if I am correct. You want to get all the variables beneath MG and MiniG, if I am correct. Under these variables, you would like to get title: minplayers: etc... To do this you would need to iterate through the first variable (Minigame).
    If you are confused about this iteration, because I was too at first you would do this
    Code:java
    1.  
    2. for(String key : getConfig().getConfigurationSection("Minigame.MG").getKeys(false))
    3.  

    You can do the same thing for MiniG. The String "key" will be everything below MG. example, like the title string, minplayers string, etc... Now if you want to get the values of these strings you would do.
    Code:java
    1.  
    2. int value = getConfig().getInt("Minigame.MG." + key);
    3. // I see that some values are integers, and some are strings, change the int to a string if you need to.
    4.  

    I believe so that was your question to find those values, if not tell me.
     
    Last edited: May 6, 2015
  3. Offline

    caderape

    @arinerron Im not sure to understand coorectly what you watn, but you might create a class for each game and add it in an arraylist
     
  4. Offline

    arinerron

    Ok so what I mean is the program doesn't know the minigame names, so it can't get their loobyx, or anything like that. So I need to get a list of all the Minigames beneath the tag
    Code:
    Minigames:
    So that I get this list (It's an example) {"MG, MiniG"}
     
  5. Offline

    Gater12

    @arinerron
    Loop through ConfigurationSection previously stated, with examples too, by the first response.
     
  6. Offline

    arinerron

    Do you know how I can do that? (Sorry, I'm not an expert in config files) All I need right now is how to get the config file as a String. Thanks! :)
     
  7. Offline

    Gater12

  8. Offline

    arinerron

Thread Status:
Not open for further replies.

Share This Page