Question about undefined lists - BUKKIT CONFIG

Discussion in 'Plugin Development' started by Tster, Feb 2, 2012.

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

    Tster

    How would I go about creating an undefined (IE not a set amount of items) list. I am used to the old config. Thanks alot

    EG

    Values:
    - 64-64-64
    - 34-34-34
    and so on, without a set amount of objects
     
  2. Offline

    hammale

    Code:java
    1.  
    2. public FileConfiguration config;
    3.  
    4. public void loadConfiguration(){
    5. if(exists() == false){
    6. config = getConfig();
    7. config.options().copyDefaults(false);
    8. String path1 = "DrugIds.353.Effect";
    9. String path2 = "DrugIds.351.Effect";
    10. String path3 = "DrugIds.40.Effect";
    11.  
    12. config.addDefault(path1, 9);
    13. config.addDefault(path2, 9);
    14. config.addDefault(path3, 9);
    15. config.options().copyDefaults(true);
    16. saveConfig();
    17. }
    18. }
    19.  
    20. private boolean exists() {
    21. try{
    22. File file = new File("plugins/DrugMeUp/config.yml");
    23. if (file.exists()) {
    24. return true;
    25. }else{
    26. return false;
    27. }
    28.  
    29. }catch (Exception e){
    30. System.err.println("Error: " + e.getMessage());
    31. return true;
    32. }
    33. }
    34.  

    which generates:
    Code:
    DrugIds:
      '353':
        Effect: 9
      '351':
        Effect: 9
      '40':
        Effect: 9
    
    then to read it:
    Code:java
    1.  
    2. public int getEffect(int id){
    3. config = getConfig();
    4. int amnt = config.getInt("DrugIds." + id + "." + "Effect");
    5. return amnt;
    6. }
    7.  

    thats the current config setup for DrugMeUp, with a bit of modifying it should work for you :D lemme know if u got any questions :p
     
Thread Status:
Not open for further replies.

Share This Page