Solved *Sigh* Getting Hashmap from config?

Discussion in 'Plugin Development' started by Larsn, Aug 4, 2015.

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

    Larsn

    I have this config setup:
    Code:
    Main:
      Second:
        Map:
          50: 0.5
    Note, I know that spacing isn't correct. It is in the actual config though!

    I know that I can get the "50" by this:
    Code:
    String thisFifthy = config.getConfigurationSection("Main.Second.Map").getKeys(false).toString();
    But how can I get the 0.5 then?
    I have tried this:
    Code:
    p.sendMessage(Double.toString(config.getDouble("Main.Second.Map." + thisFifthy)));
    But that always returns 0.0
     
  2. Offline

    Tecno_Wizard

    Last edited: Aug 4, 2015
  3. @Larsn
    config.getConfigurationSection("Main.Second.Map").getKeys(false).toString();
    Returns a String representation of a HashSet, which means it will start with a "[" and end with a "]", that's why you can't get the key correctly. Iterate over all results of getKeys and then add it to the path.
     
  4. Offline

    Tecno_Wizard

    That's just the long way of doing values()...
     
  5. @Tecno_Wizard
    Where did your values() even refer to? He never used a Map in his example.
     
  6. Offline

    Tecno_Wizard

    @megamichiel, assumption based on config setup. Disregard my answers.
     
  7. Offline

    Larsn

  8. @Larsn
    Code:
    for(String key : ConfigurationSection#getKeys(false)) {
      double value = ConfigurationSection#getDouble(key);
    }
     
    Larsn likes this.
  9. Offline

    Larsn

    Thanks! It worked :D
     
Thread Status:
Not open for further replies.

Share This Page