Help getting the first string in a configuration section

Discussion in 'Plugin Development' started by OneBillionAndOne, Jul 30, 2014.

Thread Status:
Not open for further replies.
  1. So I have this capture the flag plugin, and im storing the location data in the config file. Problem is that there will be multiple arenas under the section "arenas" and I need to be able to get only one arenas name, to use at the start. So here is a sample config:
    Code:
    max_points: 3
    arenas:
      test:
        mains:
          x: 117
          y: 67
          z: -202
          w: world
        blues:
          x: 119
          y: 66
          z: -197
          w: world
        reds:
          x: 115
          y: 66
          z: -192
          w: world
        redfs:
          x: 114
          y: 66
          z: -188
          w: world
        bluefs:
          x: 111
          y: 66
          z: -191
          w: world
    
    And I need to use the getConfig method to get a arena name either randomly or just get the first one. And i dont know how to do this/am very confused about it.
    I feel like it should be a simple thing, but ive looked on google a few times and have not found anything similar to what I need. So if someone could help me that would be great! Thanks,
    ~Fire
     
  2. Offline

    mythbusterma

    OneBillionAndOne

    Use ConfigurationSection#getKeys(false) to get a list of all the keys in a particular section.
     
  3. mythbusterma I know how to get the keys, but i need just one key. Gotten either randomly or whatever. I dont know how to get one key that i dont know the name of.
     
  4. Offline

    mythbusterma

    OneBillionAndOne

    If you only want one, read the first item of the list that method returns.
     
  5. Offline

    Flamedek

    mythbusterma To get one just do .iterator().next() on the set.
    (Because a set is not always in a particular order it might be random, but could also not be. )
    To realy get a random one use Collections.shuffle(set), and then get one.
     
  6. Offline

    mythbusterma

    Flamedek

    Or, don't waste resources creating an iterator and just use List#get(0)

    See @Falmedek 's post
     
  7. Offline

    Flamedek

    mythbusterma It returns a Set though, not a List so you cant use .get(0)
    ....
    Edit: sorry I tahged you before btw, ment to tahg the OP
     
    mythbusterma likes this.
  8. Offline

    mythbusterma

    Right, my mistake.
     
  9. Okay so i wasent just creating it wrong. Alright, ill just use Flamedek way. Use a little extra resources but all well.
     
Thread Status:
Not open for further replies.

Share This Page