Config won't save changes outside of in-game edits.

Discussion in 'Plugin Development' started by MCMastery, Apr 24, 2014.

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

    MCMastery

    I have a plugin I am working on, and whenever I edit the config.yml and reload the server, it resets the config file to its state before reloading. This is probably a dumb question, but I am new to bukkit coding :-/ Here is my code:
    Code:java
    1. package com.mcmastery.lotrcraft;
    2.  
    3. import java.util.List;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class Main extends JavaPlugin implements Listener {
    12. @Override
    13. public void onEnable() {
    14. getConfig().options().copyDefaults(true);
    15. saveDefaultConfig();
    16. getServer().getPluginManager().registerEvents(this, this);
    17. getLogger().info("LotRCraft by MCMastery has been enabled.");
    18. }
    19.  
    20. @Override
    21. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    22. if (label.equalsIgnoreCase("lotr") && args.length == 0) {
    23. sender.sendMessage("LotRCraft by MCMastery. Type " + ChatColor.BOLD + "/lotr help "
    24. + ChatColor.RESET + "for plugin help.");
    25. }
    26. else if (label.equalsIgnoreCase("lotr") && args[0].equalsIgnoreCase("help")) {
    27. sender.sendMessage(ChatColor.GREEN + "=====LotRCraft Help=====");
    28. sender.sendMessage(ChatColor.GRAY + "" + ChatColor.BOLD + "/lotr races " + ChatColor.WHITE
    29. + "Lists the current LotRCraft races");
    30. sender.sendMessage(ChatColor.GRAY + "" + ChatColor.BOLD + "/lotr info <Race> " + ChatColor.WHITE
    31. + "Displays the info of race <Race>");
    32. }
    33. else if (label.equalsIgnoreCase("lotr") && args[0].equalsIgnoreCase("races")) {
    34. List<String> rules = this.getConfig().getStringList("races");
    35. sender.sendMessage(ChatColor.GREEN + "=====LotRCraft Races=====");
    36. for (String s : rules) {
    37. s = ChatColor.translateAlternateColorCodes('&', s);
    38. sender.sendMessage(s);
    39. }
    40. }
    41.  
    42. return true;
    43. }
    44.  
    45. public void onDisable() {
    46. saveConfig();
    47. getLogger().info("LotRCraft by MCMastery has been disabled.");
    48. }
    49. }
    50.  


    But, if I make a command that edits the config.yml, and I run that command and reload the server, it will save the edits the command did!
     
  2. Offline

    Garris0n

    Code:
    public void onDisable() {
        saveConfig();
    }
    That saves the config in memory to the file, which overwrites anything in the file that was changed since the plugin used reloadConfig().
     
  3. Offline

    MCMastery

    Garris0n
    So I should remove saveConfig()?
     
  4. Offline

    TnT

    Moved to the correct forum.
     
  5. Offline

    badboysteee98

  6. Offline

    MCMastery

Thread Status:
Not open for further replies.

Share This Page