Help With Config File

Discussion in 'Plugin Development' started by Jack3885, Jun 13, 2014.

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

    Jack3885

    Hi
    I have got this old plugin off of github and im trying to add a totally new rank system to it
    But i have never made a plugin with a config or had to edit config file loading before so im totally confused
    So my question is does anyone know how this code wants the rank to be put in the config file ?

    Ranks.yml:
    Code:
    debug: false
    ranks: {}

    This is what reads the config file
    Code:java
    1. public class RanksConfig {
    2.  
    3. private final String CONFIG_NAME = "ranks.yml";
    4.  
    5. public boolean DEBUG = false;
    6.  
    7. private LoyaltyPoints plugin;
    8.  
    9. private ArrayList<Rank> playerRanks = new ArrayList<Rank>();
    10. private ArrayList<Rank> staffRanks = new ArrayList<Rank>();
    11. private HashMap<String, Rank> ranksMap = new HashMap<String, Rank>();
    12.  
    13. public RanksConfig(LoyaltyPoints plugin) {
    14. this.plugin = plugin;
    15. }
    16.  
    17. public void reload() {
    18.  
    19. playerRanks.clear();
    20. ranksMap.clear();
    21. loadSettings();
    22. }
    23.  
    24. public void loadSettings(){
    25.  
    26. if (!plugin.getDataFolder().exists()) {
    27. plugin.getDataFolder().mkdirs();
    28. }
    29.  
    30. File f = new File(plugin.getDataFolder(), CONFIG_NAME);
    31. if (!f.exists()) {
    32. try {
    33. f.createNewFile();
    34. } catch (IOException e) {
    35. plugin.getLogger().severe("Unable to create " + CONFIG_NAME + "! No towns or nations were loaded!");
    36. return;
    37. }
    38. }
    39.  
    40. YamlConfiguration conf = new YamlConfiguration();
    41. conf.options().pathSeparator('/');
    42.  
    43. try {
    44. conf.load(f);
    45. } catch (Exception e) {
    46. plugin.getServer().getLogger().severe("==================== " + plugin.getName() + " ====================");
    47. plugin.getServer().getLogger().severe("Unable to load " + CONFIG_NAME);
    48. plugin.getServer().getLogger().severe("Check your config for formatting issues!");
    49. plugin.getServer().getLogger().severe("No config options were loaded!");
    50. plugin.getServer().getLogger().severe("Error: "+e.getMessage());
    51. plugin.getServer().getLogger().severe("====================================================");
    52. return;
    53. }
    54.  
    55. // Check if debug is on
    56. if (!conf.contains("debug"))
    57. conf.set("debug", false);
    58. DEBUG = conf.getBoolean("debug");
    59.  
    60. ConfigurationSection ranksSection = conf.getConfigurationSection("ranks");
    61.  
    62. plugin.debug("ranks:");
    63.  
    64. if (ranksSection == null)
    65. ranksSection = conf.createSection("ranks");
    66.  
    67. for (String rankKey : ranksSection.getKeys(false)) {
    68.  
    69. plugin.debug(" " + rankKey + ":");
    70.  
    71. ConfigurationSection rankSection = ranksSection.getConfigurationSection(rankKey);
    72.  
    73. ChatColor color = ChatColor.WHITE;
    74.  
    75. try {
    76. color = ChatColor.valueOf(rankSection.getString("color"));
    77. } catch (Exception ex) {
    78. plugin.getLogger().warning(rankKey + " has an invalid rank color");
    79. }
    80.  
    81. String fullname = rankSection.getString("fullname", rankKey);
    82. int days = rankSection.getInt("days", 0);
    83. int points = rankSection.getInt("points", 0);
    84.  
    85. boolean staffRank = rankSection.getBoolean("staff-rank", false);
    86. boolean broadcast = rankSection.getBoolean("broadcast", false);
    87.  
    88. Rank newRank = new Rank(rankKey, fullname, color, days, points, staffRank, broadcast);
    89.  
    90. if (staffRank) {
    91. staffRanks.add(newRank);
    92. }else {
    93. playerRanks.add(newRank);
    94. }
    95.  
    96. ranksMap.put(rankKey, newRank);
    97. }
    98.  
    99. try {
    100. conf.save(f);
    101. } catch (IOException e) {
    102. e.printStackTrace();
    103. }
    104. }
    105.  
    106. public Rank getRank(String name) {
    107. return ranksMap.get(name.replace("-D", ""));
    108. }
    109.  
    110. public List<Rank> getPlayerRanks() {
    111. return Collections.unmodifiableList(playerRanks);
    112. }
    113.  
    114. public List<Rank> getStaffRanks() {
    115. return Collections.unmodifiableList(staffRanks);
    116. }
    117. }
    118.  
     
  2. Offline

    jthort

    How this wants the rank to be put in the file? Is "this" the program? I don't really understand your question, it's not very clear.
     
    AoH_Ruthless likes this.
  3. Offline

    Mrawesomecookie

    Jack3885
    You sbould never copy it like that unless you have permission in the license, or from the author. Just telling you.

    http://wiki.bukkit.org/Plugin_Tutorial

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  4. Offline

    Jack3885

    Yes sorry
    I mean how would that code, expect the rank file to be ?

    I havent the owner gave it to me on skype

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

    Jack3885

Thread Status:
Not open for further replies.

Share This Page