Increment the default in a configuration section?

Discussion in 'Plugin Development' started by ItsComits, Oct 9, 2017.

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

    ItsComits

    Hello, Does anyone have any ideas of how I would make a default for a specific configuration section.
    What would be the most efficient way of doing this?
    Here is an example of what I mean:
    Code:
    Section:
      SOMETHING_1:
        '1':
            // add another section for lets say an object which
           // would be '2:'
      SOMETHING_2:
        '1':
            // add another section for lets say an object which
           // would be '2:'
    Any help is much appreciated. :D
     
  2. It's not entirely clear what you're trying to do, but if you're trying to dynamically make new configuration sections with number ids, I could do something like this

    Code:
    ConfigurationSection newSection = null;
    if(config.getKeys(false).isEmpty){
    newSection = config.createSection("0");
    } else {
    ConfigurationSection lastSec = config.getConfgurationSection(Iterables.getLast(config.getKeys(false));
    Integer num = Integer.parseInt(lastSec.getName);
    newSection = config.createSection(String.valueOf(num+1));
    }
    
    This assumes that the config section names are 0,1,2, etc. If not, just filter out the text part with a regex.

    Sorry for errors, this was typed on mobile :)

    Sent from my SM-G903F using Tapatalk
     
  3. Offline

    MightyOne

    AFAIK you can use Plugin#getConfig()#setDeafault(String key, Anything value) but idk if you even talk about configuration files xD
     
Thread Status:
Not open for further replies.

Share This Page