My config.yml is empty

Discussion in 'Plugin Development' started by josh12341, Nov 2, 2013.

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

    josh12341

    I figured out with configs and it's working just one big problem...
    The config file is empty when it generates, here is my Main java:
    Code:java
    1. package me.joshepic_1234.Test;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.PluginDescriptionFile;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class Main extends JavaPlugin{
    12. public static Main plugin;
    13. public final Logger logger = Logger.getLogger("Minecraft");
    14.  
    15. @Override
    16. public void onDisable() {
    17. PluginDescriptionFile p = this.getDescription();
    18. this.logger.info(p.getName() + " V" + p.getVersion() + " Has Been Disabled!");
    19. saveConfig();
    20. }
    21.  
    22. @Override
    23. public void onEnable() {
    24. PluginDescriptionFile p = this.getDescription();
    25. this.logger.info(p.getName() + " V" + p.getVersion() + " Has Been Enabled!");
    26. getConfig().options().copyDefaults(true);
    27. saveConfig();
    28. }
    29.  
    30. public boolean onCommand(CommandSender sender, Command cmd, String label, String commandLabel, String[] args){
    31. Player player = (Player) sender;
    32. if(label.equalsIgnoreCase("server")){
    33. if (args[0].equalsIgnoreCase("staff")){
    34. player.sendMessage(getConfig().getString("staff"));
    35. } else if (args[0].equalsIgnoreCase("info")){
    36. player.sendMessage(getConfig().getString("info"));
    37. } else if (args[0].equalsIgnoreCase("rules")){
    38. player.sendMessage(getConfig().getString("rules"));
    39. }
    40.  
    41. }
    42. return false;
    43. }
    44. }

    And my plugin.yml:
    Code:java
    1. name: Test
    2. main: me.joshepic_1234.Test.Main
    3. version: 1.0
    4. description: >
    5. A test!
    6. commands:
    7. server:
    8. description: Main command for SimpleInfo

    And my config.yml:
    Code:java
    1. # Default Configuration file for Test
    2. info: info about the server:
    3. rules: rules of the server:
    4. staff: staff of the server:
     
  2. Offline

    hanahouhanah

    Try:
    saveDefaultConfig()
    This is how I do it:
    Code:java
    1. if(!new File(getDataFolder(), "config.yml").exists()){
    2. saveDefaultConfig();
    3. reloadConfig();
    4. }
     
  3. Offline

    DailyLove

    josh12341 Just change your saveConfig(); line to saveDefaultConfig();

    It will only save the default config if it doesn't exist. There is not need to check if it exists or not hanahouhanah
     
  4. Offline

    hanahouhanah

    DailyLove
    Look at the second line of my post. o_o
    I was simply stating how I implemented this in my code when I make configs, I wasn't stating that's how he should do it.
     
  5. Offline

    DailyLove

    hanahouhanah I know that. I'm stating that you, yourself don't need to check if it exists or not.
     
  6. Offline

    josh12341

    It still doesn't work :(
     
  7. Offline

    AoH_Ruthless

    Code:java
    1. public void onEnable() {
    2. this.saveDefaultConfig(); //this saves the config that you have defined.
    3. }


    Alternatively you could do what others have said and use "saveDefaultConfig()", but I prefer using the first method.
     
Thread Status:
Not open for further replies.

Share This Page