How to get a key from a Config?

Discussion in 'Spigot Plugin Development' started by ShishKaBobz, Apr 22, 2017.

  1. Hello! I would like to know how you can get a config Key? Ive already tried .getKeys() and that is a Boolean value so i cannot use that, I need it to be a string? How can i do this... Thanks in advance!
     
  2. Oh also if you didnt understand, I need to get what the Key equals not what the Keys value is
     
  3. Main#getConfig#getConfigurationSection#getKeys(false or true)

    False means it doesn't do a 'deep' search and only gets the surface

    True means it does a deep search and gets everything in the config.

    If you were to get a config item say
    A: b
    Then you would getKeys(false)
    Whilst looping through it check if 'a' has been reached, if it does get the value 'b'


    Sent from my iPhone using Tapatalk
     
    • Like Like x 1
  4. Sorry Im newer to java / Bukkit api too, How can i get it and use it just to use it something for my Value Such as

    1010bob: FromEarth

    plugin.getConfig().getString("1010bob");
    //Gets FromEarth
    How can i get 1010bob for something such as

    String Location = plugin.getConfig().getString("1010bob");
    String User = plugin.getConfig()blah blah blah;
    Bukkit.broadcastMessage(User + "Is "+ Location);
    //Outputs 1010bob is FromEarth
     
  5. You can do a for loop
    Code (Text):
    Map<String, String> data = Collections.synchorisedMap(new Hashmap<String, String>());

    // Basic 'for' loops
    ConfigurationSection section = getConfig.getSection("section_name");
    for(String key : section.getKeys(false)) {
        //Your code here maybe put it in a hashmap?
        data.put(key, section.getString(key));
    }