Config keeps resetting?

Discussion in 'Plugin Development' started by silentsam5, Feb 20, 2014.

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

    silentsam5

    This is my code:

    Code:java
    1. package me.silentsam5.Recorder;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12. import org.bukkit.scheduler.BukkitScheduler;
    13.  
    14. public class Recorder
    15. extends JavaPlugin
    16. {
    17. public final Logger logger = Logger.getLogger("Minecraft");
    18. public static Recorder plugin;
    19.  
    20. public void onDisable()
    21. {
    22. PluginDescriptionFile pdfFile = getDescription();
    23. this.logger.info("[" + pdfFile.getName() + "]" + " Has Been Disabled.");
    24. }
    25.  
    26. public void onEnable()
    27. {
    28. PluginDescriptionFile pdfFile = getDescription();
    29. this.logger.info("[" + pdfFile.getName() + "]" + " Version " + pdfFile.getVersion() + " Has Been Enabled.");
    30. getConfig().options().copyDefaults(true);
    31. saveConfig();
    32. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    33. scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
    34. @Override
    35. public void run() {
    36. for(Player player : Bukkit.getOnlinePlayers()) {
    37. int current = getConfig().getInt(player.getName() + ".time");
    38. int newCurrent = current + 1;
    39. getConfig().set(player.getName() + ".time", newCurrent);
    40. }
    41. }
    42. }, 1200L, 1200);
    43. }
    44.  
    45. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    46. {
    47. Player player = (Player)sender;
    48. if (commandLabel.equalsIgnoreCase("recorder")) {
    49. if (args.length == 0)
    50. {
    51. player.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.GOLD + sender.getName() + ChatColor.DARK_RED + "]");
    52. player.sendMessage(ChatColor.RED + "Pay Group: " + ChatColor.GREEN + getConfig().getString(sender.getName() + ".pay"));
    53. player.sendMessage(ChatColor.RED + "Time: " + ChatColor.GREEN + getConfig().getString(sender.getName() + ".time"));
    54. int pay = getConfig().getInt(sender.getName() + ".time");
    55. int check = getConfig().getInt(sender.getName() + ".paycheck");
    56. int paycheck = pay*check;
    57. player.sendMessage(ChatColor.RED + "Total: " + ChatColor.GREEN + paycheck + " Cents");
    58. }
    59. if (args.length == 1)
    60. {
    61. String target = args[0];
    62. if (getConfig().contains(target))
    63. {
    64. player.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.GOLD + target + ChatColor.DARK_RED + "]");
    65. player.sendMessage(ChatColor.RED + "Pay Group: " + ChatColor.GREEN + getConfig().getString(target + ".pay"));
    66. player.sendMessage(ChatColor.RED + "Time: " + ChatColor.GREEN + getConfig().getString(target + ".time"));
    67. int pay = getConfig().getInt(target + ".time");
    68. int check = getConfig().getInt(target + ".paycheck");
    69. int paycheck = pay*check;
    70. player.sendMessage(ChatColor.RED + "Total: " + ChatColor.GREEN + paycheck + " Cents");
    71. }
    72. else
    73. {
    74. player.sendMessage(args[0] + " is not in the database!");
    75. }
    76. }
    77. if (args.length == 3)
    78. {
    79. String target = args[0];
    80. String string = args[1];
    81. getConfig().set(target + "." + string, args[2]);
    82. }
    83. }
    84. return false;
    85. }
    86. }


    My config is basically:

    silentsam5:
    pay: Owner
    paycheck: 2
    time: 10

    with a couple other names.

    So with my plugin I wanted to have it time how long everyone is on but for some reason every time I /reload, it glitches the plugin out and resets everyone's time completely. How would I have the config COMPLETELY permanent, even after a /reload, or after updating my plugin?

    By permanent I mean so that the values in the config stay the way they are even after a reload or update.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  2. In the onDisable(), add
    Code:
    saveConfig();
    
     
    Suicidesilence_ likes this.
Thread Status:
Not open for further replies.

Share This Page