Help with storing a config

Discussion in 'Plugin Development' started by Suprem20, Jul 1, 2011.

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

    Suprem20

    How am I supposed to store and get lists from a config?
    I'm trying to make a default config generator, but I can't get it to do something like this:

    Code:
    Example:
       - Object 1
       - Object 2
       - Object 3
    Also, what is the best way to import a config?

    Thanks.
     
  2. Offline

    DrBowe

    What do you mean by 'import a config'? As in, load and save?
    Either way, I'll post you the way I set up configs (using the built-in bukkit YAML config):
    Code:java
    1.  
    2. protected static List<String> RESTRICTED_COMMANDS;
    3.  

    (added at the start of my main class)

    And for having it be created in the config (and load a default value if its empty):
    Code:java
    1.  
    2. public void loadConfig(){
    3. Configuration config = getConfiguration();
    4. config.load();
    5. //sets the earlier variable to whatever is in the config
    6. RESTRICTED_COMMANDS = config.getStringList("CommandRestriction.Restricted-Commands", null);
    7. //This will check to see if the list is null (AKA, its the person's first time running it)
    8. //If it is null, it will load in a default value, so that the list actually appears in the config
    9. if(RESTRICTED_COMMANDS.size() == 0){
    10. RESTRICTED_COMMANDS.add("command1");
    11. config.setProperty("CommandRestriction.Restricted-Commands", RESTRICTED_COMMANDS);
    12. }
    13. config.save();
    14. }
    15.  
    

    Then just place the loadConfig() method in the onEnable()
    Bukkit will take care of the rest
    Hope this helped
     
  3. Offline

    Suprem20

    Ya I meant load and save. I'll try what you posted.
    Thx for the help.
     
Thread Status:
Not open for further replies.

Share This Page