Get all ints in a section of config

Discussion in 'Plugin Development' started by LordVakar, Jun 13, 2014.

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

    LordVakar

    Pretend I have config with ints under a section.
    So like:



    Code:
                Section:
                    1:
                        derp: lol
                    2:
                        meh:lel

    How would I get the whole section and all the ints under it
     
  2. Offline

    drtshock

    Ok I'm pretending, now what?
     
    xTigerRebornx likes this.
  3. Offline

    LordVakar

    drtshock
    xP
    I sound confusing in my post don't I
    Maybe I should convert from ints to strings
    With strings, you can use getConfigurationSection and getKeys for what I'm trying to accomplish
     
  4. Offline

    JBoss925

    It's very easy. You're storing the ints as strings under the section so do something like...
    Code:java
    1. HashMap<Integer, String> intresult = new HashMap<Integer, String>();
    2.  
    3. for(int i = 1; i<100; i++){
    4. String s = getConfig().getString("Section.".concat(i.toString()));
    5. if(s == null){
    6. break;
    7. }
    8. intresult.put(i, s);
    9. }


    This loops through ints and then concats them with the section name to get the directory or section name specification to the individual ints. Then it returns a string or whatever other datatype you want to change it to from the int and adds the int as a key and the string or datatype you want it to return as the value in a hash map.
     
  5. Offline

    drtshock

    JBoss925 and Garris0n like this.
  6. Offline

    JBoss925

    Ahhh I see, you loop through the keys. Let's say theoretically though, there was something similar to a config but did not contain a getKeys method. How would one go about cycling through all the ints? I assume my check to see if s is null won't return true and break the loop?
     
  7. Offline

    LordVakar

    JBoss925
    I'm not sure but I think I found a solution to what I was trying to do, I just haven't tested it
    for(int keys : fc.getIntegerList("section.")) {
    }
     
  8. Offline

    JBoss925

    It's not an integer list cuz it's not a list. It's a bunch of section names.
     
Thread Status:
Not open for further replies.

Share This Page