Solved Dynamic Configuration List With Values

Discussion in 'Plugin Development' started by Scizzr, Apr 8, 2013.

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

    Scizzr

    I'm writing a plugin for my server and it has the ability to auto-promote users after a certain amount of time. I'm wanting to make it configurable though so that I don't have to rewrite code if I want to change the times or the groups that we have. The logic is such that they will not be promoted if the next highest group has a time of -1 otherwise they will be promoted if their playtime (seconds) is equal to or greater than the required number.

    Here's the section in the config file pertinent to this:
    Code:
    groups:
    - Guest: 0
    - Player: 14400
    - Trusted: 144000
    - Moderator: -1
    - Admin: -1
    - Owner: -1
    
    All I need is a way to read these entries from the config.yml file. I tried using config.getConfigurationSection() and config.getStringList() and they both come up empty.

    Thanks! :)
     
  2. Offline

    gomeow

    Code:
    groups:
      Guest: 0
      Player: 14400
      Trusted: 144000
      Moderator: -1
      Admin: -1
      Owner: -1
    
    I would do it this way:
    Code:java
    1. HashMap<String, Integer> values = new HashMap<String, Integer>();
    2. for(String key:getConfig().getConfigurationSection("groups").getKeys(false)) {
    3. values.put(key, getConfig().getInt("groups." + key));
    4. }
     
    microgeek likes this.
  3. Offline

    Scizzr

    I tried that before you posted and the getConfigurationSection() call is returning null. Not sure why. :\ I verified that the config file is being loaded properly by using getStringList() with this and it works 100%:
    Code:
    testing:
      - One
      - Two
      - Three
    
    I'm still trying different things with no luck. Anyone?

    Edit: I see the problem I was having. The config file I was trying to use was formatted incorrectly... I was using a hyphen for each member of the key, and it doesn't expect a hyphen. ^_^
     
Thread Status:
Not open for further replies.

Share This Page