Solved config not creating

Discussion in 'Plugin Development' started by kamakarzy, May 7, 2013.

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

    kamakarzy

    can anyone help my config.yml is not generating on start and its actually not saving i thought everything was fine and i have no idea why its not working i do not have no error code


    class
    Code:java
    1. package com.gmail.nomad856.kamakarzy;
    2.  
    3. import java.util.List;
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.World;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12. import org.bukkit.scheduler.BukkitRunnable;
    13.  
    14. public class Main extends JavaPlugin {
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. public static Main plugin;
    17.  
    18. public void onEnable() {
    19. getLogger().info(
    20. "By nomad856 aka kamakarzy with thanks to bukkit fourms team");
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. this.logger.info(pdfFile.getName() + "Has Been Enabled");
    23. plugin = this;
    24. getConfig().options().copyDefaults(true);
    25. saveConfig();
    26. BukkitRunnable run = new BukkitRunnable() {
    27.  
    28. private int count = 0;
    29.  
    30. @Override
    31. public void run() {
    32. if (count >= 4) {
    33. performSave();
    34. count = 0;
    35. return;
    36. }
    37. count++;
    38.  
    39. }
    40.  
    41. };
    42. run.runTaskTimer(this, 0L, 20L);
    43. return;
    44. }
    45.  
    46. @Override
    47. public void onDisable() {
    48. PluginDescriptionFile pdfFile = this.getDescription();
    49. this.logger.info(pdfFile.getName() + "Has Been Disabled");
    50. saveConfig();
    51. }
    52.  
    53. public boolean onCommand(CommandSender sender, Command cmd, String label,
    54. String[] args) {
    55. if (cmd.getName().equals("save")) {
    56. performSave();
    57.  
    58. }
    59. return true;
    60. }
    61.  
    62. private int saveWorlds() {
    63. int i = 0;
    64. List<World> worlds = this.getServer().getWorlds();
    65. for (World world : worlds) {
    66. Bukkit.broadcastMessage("Saving world: " + world.getName());
    67. world.save();
    68. i++;
    69. }
    70. return i;
    71. }
    72.  
    73. private void savePlayers() {
    74. // Save the players
    75. Bukkit.broadcastMessage("Saving Players...");
    76. this.getServer().savePlayers();
    77. }
    78.  
    79. public void performSave() {
    80. if (getServer().getOnlinePlayers().length == 0) {
    81. Bukkit.broadcastMessage("Skipping save, no players online.");
    82. return;
    83. } else
    84. Bukkit.broadcastMessage("Now Saving...");
    85. savePlayers();
    86. saveWorlds();
    87. Bukkit.broadcastMessage("Saved Players");
    88.  
    89. Bukkit.broadcastMessage(String.format("Saved "
    90. + Bukkit.getWorld(getName()) + "Worlds"));
    91. return;
    92.  
    93. }
    94. }
    95.  
    96.  


    config.yml
    Code:
    # This is the Default config for Easysave
     
    #Time in seconds default is 108000 seconds
    Time: 108000
     
  2. Offline

    Jamie Marks

    remove the @override onEnable? see if that does it. everything else looks sound.
     
  3. Offline

    teunie75

    You can better use saveDefaultConfig() instead of saveConfig() because saveDefaultConfig() will only create a file if it exists.
    You only have to use saveConfig() if you changed something in the config and want to save it to the file.
     
  4. Offline

    kamakarzy

    teunie75 its still not creating it

    Jamie Marks nope

    guys please help i aded a command and nothing is working have i missed something i really thought this should work

    Code:java
    1. package com.gmail.nomad856.kamakarzy;
    2.  
    3. import java.util.List;
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.World;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12. import org.bukkit.scheduler.BukkitRunnable;
    13.  
    14. public class Main extends JavaPlugin {
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. public static Main plugin;
    17.  
    18. public void onEnable() {
    19. getLogger().info(
    20. "By nomad856 aka kamakarzy with thanks to bukkit fourms team");
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. this.logger.info(pdfFile.getName() + "Has Been Enabled");
    23. plugin = this;
    24. getConfig().options().copyDefaults(true);
    25. saveConfig();
    26. BukkitRunnable run = new BukkitRunnable() {
    27.  
    28. private int count = 0;
    29.  
    30. @Override
    31. public void run() {
    32. if (count >= 4) {
    33. performSave();
    34. count = 0;
    35. return;
    36. }
    37. count++;
    38.  
    39. }
    40.  
    41. };
    42. run.runTaskTimer(this, 0L, 20L);
    43. return;
    44. }
    45.  
    46. @Override
    47. public void onDisable() {
    48. PluginDescriptionFile pdfFile = this.getDescription();
    49. this.logger.info(pdfFile.getName() + "Has Been Disabled");
    50. saveConfig();
    51. }
    52.  
    53. public boolean onCommand(CommandSender sender, Command cmd, String label,
    54. String[] args) {
    55. if (cmd.getName().equals("save")) {
    56. performSave();
    57.  
    58. }
    59. return true;
    60. }
    61.  
    62. private int saveWorlds() {
    63. int i = 0;
    64. List<World> worlds = this.getServer().getWorlds();
    65. for (World world : worlds) {
    66. Bukkit.broadcastMessage("Saving world: " + world.getName());
    67. world.save();
    68. i++;
    69. }
    70. return i;
    71. }
    72.  
    73. private void savePlayers() {
    74. // Save the players
    75. Bukkit.broadcastMessage("Saving Players...");
    76. this.getServer().savePlayers();
    77. }
    78.  
    79. public void performSave() {
    80. if (getServer().getOnlinePlayers().length == 0) {
    81. Bukkit.broadcastMessage("Skipping save, no players online.");
    82. return;
    83. } else
    84. Bukkit.broadcastMessage("Now Saving...");
    85. savePlayers();
    86. saveWorlds();
    87. Bukkit.broadcastMessage("Saved Players");
    88.  
    89. Bukkit.broadcastMessage(String.format("Saved "
    90. + Bukkit.getWorld(getName()) + "Worlds"));
    91. return;
    92.  
    93. }
    94. }
    95.  
    96.  


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

    psycowithespn

    Do you have a "config.yml" file in the jar?
     
  6. Offline

    kamakarzy

    psycowithespn yes but its not just not generating the config its like the plugin isnt doing anything
     
  7. Offline

    Jamie Marks

    do you have a config.yml in your plugin? same location as the plugin.yml?

    EDIT ninjad
     
  8. Offline

    kamakarzy

  9. Offline

    Burnett1

    Maybe put some indentation so it is easier to read. CTRL + SHIFT + F

    Never mind i got the file.
     
  10. Offline

    kamakarzy

  11. Offline

    Burnett1

    Purpose of this code?


    Code:
    BukkitRunnable run = new BukkitRunnable() {
     
                private int count = 0;
     
                @Override
                public void run() {
                    if (count >= 4) {
                        performSave();
                        count = 0;
                        return;
                    }
                    count++;
     
                }
     
            };run.runTaskTimer(this, 0L, 20L);
    Edit: If im correct that will save the worlds and players every tick.
     
  12. Offline

    kamakarzy

    @Burnett1 right now it was a test to see if it was working but it wasnt the real value of that is
    Code:
    BukkitRunnable run = new BukkitRunnable() {
     
                private int count = 0;
     
                @Override
                public void run() {
                    if (count >= getConfig().getInt("Time"));
                        performSave();
                        count = 0;
                        return;
                    }
                    count++;
     
                }
     
            };run.runTaskTimer(this, 0L, 20L);
     
  13. Offline

    Burnett1

    Might work test it.

    Code:
    package com.gmail.nomad856.kamakarzy;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin {
     
        public final Logger logger = Bukkit.getLogger();
        public static Main plugin;
     
        @Override
        public void onEnable() {
            getLogger().info("By nomad856 aka kamakarzy with thanks to bukkit forums team.");
         
            PluginDescriptionFile pdfFile = this.getDescription();
         
            this.logger.info(pdfFile.getName() + "Has Been Enabled");
         
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
     
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "Has Been Disabled");
            saveConfig();
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("save")){
                if(args.length == 0){
                    performSave();
                    return true;
                }
                return true;
            }
            return false;
        }
     
        private void saveWorlds() {
            for (World world : Bukkit.getServer().getWorlds()) {
             
                Bukkit.broadcastMessage("Saving world: " + world.getName());
                world.save();
            }
            return;
        }
     
        private void savePlayers() {
         
            Bukkit.broadcastMessage("Saving Players...");
            this.getServer().savePlayers();
        }
     
        public void performSave() {
            if (getServer().getOnlinePlayers().length == 0) {
             
                Bukkit.broadcastMessage("Skipping save, no players online.");
                return;
             
            }else{
                Bukkit.broadcastMessage("Now Saving...");
                savePlayers();
                saveWorlds();
                Bukkit.broadcastMessage("Saved Players.");
     
                Bukkit.broadcastMessage("World's saved.");
                return;
            }
        }
    }
    
     
  14. Offline

    kamakarzy

    Burnett1 nope didnt work but even then you got rid of my timer i need that in the command is only there for testingi want it to be fully automatic with no commands
     
  15. Offline

    Lolmewn

    this.getDataFolder().mkdir(); first perhaps?
     
  16. Offline

    kamakarzy

    Lolmewn thanks but where exactly would i put that
     
  17. Offline

    Lolmewn

    kamakarzy Right before you try creating the file.
     
  18. Offline

    kamakarzy

    Lolmewn no still not creating it and the command is still not working
     
  19. Offline

    Burnett1

    Any errors in the console?
     
  20. Offline

    kamakarzy

    Burnett1 none

    Code:
    2013-05-07 19:03:36 [INFO] [Teleport] Enabling Teleport v1.0
    2013-05-07 19:03:36 [INFO] TeleportVersion1.0Has Been Enabled
    2013-05-07 19:03:36 [INFO] [EasySave] Enabling EasySave v1.0
    2013-05-07 19:03:36 [INFO] EasySaveVersion1.0Has Been Enabled
    2013-05-07 19:03:36 [INFO] [Huggs] Enabling Huggs v1.1
    2013-05-07 19:03:36 [INFO] HuggsVersion1.1Has Been Enabled
    2013-05-07 19:03:36 [INFO] Server permissions file permissions.yml is empty, ignoring it
    2013-05-07 19:03:36 [INFO] Done (2.183s)! For help, type "help" or "?"
    wow this is soo annoying nothing is working its like i have put a blank plugin in

    solved incase anyone wants to know had to recode it but i have another problem now :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page