config.yml

Discussion in 'Plugin Development' started by MrTheNewGuy, Jul 4, 2012.

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

    MrTheNewGuy

    i am making a plugin where i need an config file like this:
    Code:
    kits:
        kitname:
            armor:
            inventory:
    but i dont know how to do this
    can some one help me pleas?
     
  2. use the config api? search on the bukkit furms how to use it?
     
  3. Offline

    MrTheNewGuy

    thanks
     
  4. Offline

    ZachBora

    You can take a look at how I make this config :

    Code:yml
    1. worlds:
    2. plotworld:
    3. PlotAutoLimit: 100
    4. PathWidth: 7
    5. PlotSize: 32
    6. BottomBlockId: 7
    7. WallBlockId: 44
    8. PlotFloorBlockId: 2
    9. PlotFillingBlockId: 3
    10. RoadHeight: 64
    11. DaysToExpiration: 7
    12. ProtectedBlocks:
    13. - 54
    14. - 61
    15. - 62
    16. - 120
    17. - 94
    18. - 93
    19. - 84
    20. - 25
    21. - 355
    22. - 118
    23. - 117
    24. PreventedItems:
    25. - '351:15'
    26. - '321'
    27. - '259'
    28. - '328'
    29. - '343'
    30. - '342'
    31. - '333'
    32. usemySQL: false
    33. mySQLconn: jdbc:mysql://localhost:3306/minecraft
    34. mySQLuname: root
    35. mySQLpass: password


    Using this code :
    Code:java
    1. File configfile = new File(configpath, "config.yml");
    2. FileConfiguration config = new YamlConfiguration();
    3.  
    4. try {
    5. config.load(configfile);
    6. } catch (FileNotFoundException e) {
    7.  
    8. } catch (IOException e) {
    9. logger.severe(PREFIX + " can't read configuration file");
    10. e.printStackTrace();
    11. } catch (InvalidConfigurationException e) {
    12. logger.severe(PREFIX + " invalid configuration format");
    13. e.printStackTrace();
    14. }
    15.  
    16. usemySQL = config.getBoolean("usemySQL", false);
    17. mySQLconn = config.getString("mySQLconn", "jdbc:mysql://localhost:3306/minecraft");
    18. mySQLuname = config.getString("mySQLuname", "root");
    19. mySQLpass = config.getString("mySQLpass", "password");
    20. AutoPlotLimit = config.getInt("AutoPlotLimit", 100);
    21.  
    22. ConfigurationSection worlds;
    23.  
    24. if(!config.contains("worlds"))
    25. {
    26. worlds = config.createSection("worlds");
    27.  
    28. ConfigurationSection plotworld = worlds.createSection("plotworld");
    29.  
    30. plotworld.set("PlotAutoLimit", 100);
    31. plotworld.set("PathWidth", 7);
    32. plotworld.set("PlotSize", 32);
    33. plotworld.set("BottomBlockId", 7);
    34. plotworld.set("WallBlockId", 44);
    35. plotworld.set("PlotFloorBlockId", 2);
    36. plotworld.set("PlotFillingBlockId", 3);
    37. plotworld.set("RoadHeight", 64);
    38. plotworld.set("DaysToExpiration", 7);
    39. plotworld.set("ProtectedBlocks", getDefaultProtectedBlocks());
    40. plotworld.set("PreventedItems", getDefaultPreventedItems());
    41.  
    42. worlds.set("plotworld", plotworld);
    43. config.set("worlds", worlds);
    44. }
    45. else
    46. {
    47. worlds = config.getConfigurationSection("worlds");
    48. }
    49.  
    50. plotmaps = new HashMap<String, PlotMapInfo>();
    51.  
    52. for(String worldname : worlds.getKeys(false))
    53. {
    54. PlotMapInfo tempPlotInfo = new PlotMapInfo();
    55. ConfigurationSection currworld = worlds.getConfigurationSection(worldname);
    56.  
    57. tempPlotInfo.PlotAutoLimit = currworld.getInt("PlotAutoLimit", 100);
    58. tempPlotInfo.PathWidth = currworld.getInt("PathWidth", 7);
    59. tempPlotInfo.PlotSize = currworld.getInt("PlotSize", 32);
    60. tempPlotInfo.BottomBlockId = (byte) currworld.getInt("BottomBlockId", 7);
    61. tempPlotInfo.WallBlockId = (byte) currworld.getInt("WallBlockId", 44);
    62. tempPlotInfo.PlotFloorBlockId = (byte) currworld.getInt("PlotFloorBlockId", 2);
    63. tempPlotInfo.PlotFillingBlockId = (byte) currworld.getInt("PlotFillingBlockId", 3);
    64. tempPlotInfo.RoadHeight = currworld.getInt("RoadHeight", currworld.getInt("WorldHeight", 64));
    65. tempPlotInfo.DaysToExpiration = currworld.getInt("DaysToExpiration", 7);
    66.  
    67. if(currworld.contains("ProtectedBlocks"))
    68. {
    69. tempPlotInfo.protectedblocks = currworld.getLongList("ProtectedBlocks");
    70. }else{
    71. tempPlotInfo.protectedblocks = getDefaultProtectedBlocks();
    72. }
    73.  
    74. if(currworld.contains("PreventedItems"))
    75. {
    76. tempPlotInfo.preventeditems = currworld.getStringList("PreventedItems");
    77. }else{
    78. tempPlotInfo.preventeditems = getDefaultPreventedItems();
    79. }
    80.  
    81. if(tempPlotInfo.RoadHeight > 250)
    82. {
    83. logger.severe(PREFIX + " RoadHeight above 250 is unsafe. This is the height at which your road is located. Setting it to 64.");
    84. tempPlotInfo.RoadHeight = 64;
    85. }
    86.  
    87. currworld.set("PlotAutoLimit", tempPlotInfo.PlotAutoLimit);
    88. currworld.set("PathWidth", tempPlotInfo.PathWidth);
    89. currworld.set("PlotSize", tempPlotInfo.PlotSize);
    90. currworld.set("BottomBlockId", tempPlotInfo.BottomBlockId);
    91. currworld.set("WallBlockId", tempPlotInfo.WallBlockId);
    92. currworld.set("PlotFloorBlockId", tempPlotInfo.PlotFloorBlockId);
    93. currworld.set("PlotFillingBlockId", tempPlotInfo.PlotFillingBlockId);
    94. currworld.set("RoadHeight", tempPlotInfo.RoadHeight);
    95. currworld.set("WorldHeight", null);
    96. currworld.set("DaysToExpiration", tempPlotInfo.DaysToExpiration);
    97. currworld.set("ProtectedBlocks", tempPlotInfo.protectedblocks);
    98. currworld.set("PreventedItems", tempPlotInfo.preventeditems);
    99.  
    100. tempPlotInfo.plots = SqlManager.getPlots(worldname.toLowerCase());
    101.  
    102. plotmaps.put(worldname.toLowerCase(), tempPlotInfo);
    103. }
    104.  
    105. config.set("usemySQL", usemySQL);
    106. config.set("mySQLconn", mySQLconn);
    107. config.set("mySQLuname", mySQLuname);
    108. config.set("mySQLpass", mySQLpass);
    109.  
    110. try {
    111. config.save(configfile);
    112. } catch (IOException e) {
    113. logger.severe(PREFIX + " error writting configurations");
    114. e.printStackTrace();
    115. }


    Adding a new post because if I edit the previous one it'll break the config file indentation.
    P.S. "configpath" is :
    configpath = getDataFolder().getAbsolutePath();

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  5. Offline

    MrTheNewGuy

    thanks
    btw i like your plotme plugin i had a server whit it
     
Thread Status:
Not open for further replies.

Share This Page