Saving config when you type /pcb reload?

Discussion in 'Plugin Development' started by PolarCraft, Jan 9, 2014.

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

    PolarCraft

    Okay so when i try to save the config and type /pcb reload it does not save it. All It does is get the default config.

    Code:java
    1. package net.jc.minecraft;
    2.  
    3. import java.util.Random;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public final class PcBroadcast extends JavaPlugin
    11. {
    12. public static boolean enabled = true;
    13.  
    14. public void onEnable() {
    15. getLogger().info("PCB Is Enabled!");
    16. getConfig().options().copyDefaults(true);
    17. saveDefaultConfig();
    18. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    19. public void run() {
    20. if (PcBroadcast.enabled) {
    21. int I = new Random().nextInt(PcBroadcast.this.getConfig().getStringList("Messages").size());
    22. String PCM = ChatColor.translateAlternateColorCodes('&', (String)PcBroadcast.this.getConfig().getStringList("Messages").get(I));
    23. String prefix = ChatColor.translateAlternateColorCodes('&', PcBroadcast.this.getConfig().getString("Prefix"));
    24. Bukkit.broadcastMessage(prefix + PCM);
    25. }
    26. }
    27. }
    28. , 0L, getConfig().getLong("Time") * 20L);
    29. }
    30.  
    31. public void onDisable()
    32. {
    33. getLogger().info("PCB Is Disabled!");
    34. Bukkit.getScheduler().cancelTasks(this);
    35. }
    36.  
    37. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    38. {
    39. if (cmd.getName().equalsIgnoreCase("pcb")) {
    40. if (args.length == 0) {
    41. if (sender.hasPermission("pcb")) {
    42. sender.sendMessage(ChatColor.GOLD + "/pcb toggle - This command will toggle broadcasting messages!");
    43. sender.sendMessage(ChatColor.GOLD + "/pcb reload - This command will reload the configuration of PCM!");
    44. sender.sendMessage(ChatColor.GOLD + "/pcb credits - This will display the people who developed PCM!");
    45. } else {
    46. sender.sendMessage(ChatColor.RED + "NICE TRY!");
    47. }
    48. } else if (args.length == 1)
    49. {
    50. if (args[0].equalsIgnoreCase("toggle")) {
    51. if (sender.hasPermission("pcb.toggle")) {
    52. enabled = !enabled;
    53. sender.sendMessage(ChatColor.GREEN + "PCB BROADCAST IS NOW SET TO" + ChatColor.RED + enabled);
    54. } else {
    55. sender.sendMessage(ChatColor.RED + "NICE TRY!");
    56. }
    57. }
    58. else if (args[0].equalsIgnoreCase("reload")) {
    59. if (sender.hasPermission("pcb.reload")) {
    60. reloadConfig();
    61. sender.sendMessage(ChatColor.AQUA + "PCB" + ChatColor.GREEN + " Has Been Reloaded From Disk Space!");
    62. } else {
    63. sender.sendMessage(ChatColor.RED + "NICE TRY!");
    64. }
    65. }
    66. else if (args[0].equalsIgnoreCase("credits")) {
    67. if (sender.hasPermission("pcb.credits")){
    68. sender.sendMessage(ChatColor.GREEN + "PCB was made by Polarcraft");
    69. sender.sendMessage(ChatColor.AQUA + "Aka tripps41");
    70. }
    71. }
    72. } else if (args.length >= 2) {
    73. sender.sendMessage("TOO MANY ARGUMENTS.");
    74. }
    75. }
    76. return false;
    77. }
    78. }
     
  2. Offline

    felixfritz

    If you add a saveConfig() infront of reloadConfig()?
     
  3. Offline

    PolarCraft

  4. Offline

    hubeb

    PolarCraft try:
    Code:
    this.saveConfig();
    this.reloadConfig();
     
  5. Offline

    PolarCraft

    hubeb Nope still does not work. hmm this is really wierd. Maybe It was the class i deleted but it had nothing to do with the reload or anything really.
    [Edit] Hmm was not the class.
     
  6. Offline

    Stealth2800

    Hm. Try:
    Code:
    //replacing:
    getConfig().options().copyDefaults(true);
     
    //with:
    getConfig().options().copyDefaults(false);
    According to: http://jd.bukkit.org/rb/apidocs/org...nfigurationOptions.html#copyDefaults(boolean), "If this is true, all values in the default Configuration will be directly copied, making it impossible to distinguish between values that were set and values that are provided by default."
    I believe setting it to false will only copy the value if nothing is defined for it in the config.
     
  7. Offline

    jimbo8

    this.getConfig().save();
    Or this.saveConfig ();
     
  8. Offline

    PolarCraft

  9. Offline

    PolarCraft

Thread Status:
Not open for further replies.

Share This Page