Solved Configs are not being created...

Discussion in 'Plugin Development' started by TheMcScavenger, Oct 13, 2013.

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

    TheMcScavenger

    Hi guys,

    I have worked with configuration files in the past, with no problem. However, for a project I'm working on now, I need to use multiple ones. As I was clueless, I started looking at some tutorials, and tried multiple ways of adding these configs in. To get the basic questions out of the way, no eclipse doesn't throw me any error, nor does the console. The plugin loads, and can be found (green) in the /plugins menu. I have [Vault] as dependency, and have it on my server.

    So, as the title suggests, the config files aren't being created, nor is the folder for the plugin. What did I do wrong, and how do I fix this?

    Main plugin file:
    Code:java
    1. package com.McScavenger.TestPlugin;
    2.  
    3. import java.io.File;
    4. import java.util.logging.Logger;
    5.  
    6. import net.milkbowl.vault.economy.Economy;
    7.  
    8. import org.bukkit.Server;
    9. import org.bukkit.configuration.file.FileConfiguration;
    10. import org.bukkit.configuration.file.YamlConfiguration;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.plugin.PluginDescriptionFile;
    13. import org.bukkit.plugin.RegisteredServiceProvider;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class Main extends JavaPlugin implements Listener{
    17. public static Economy economy = null;
    18. Server server;
    19. public final Logger logger = Logger.getLogger("Minecraft");
    20. public static Main plugin;
    21.  
    22. File configFile = null;
    23. File playersFile = null;
    24. File oneFile = null;
    25. File twoFile = null;
    26. FileConfiguration config = null;
    27. FileConfiguration players = null;
    28. FileConfiguration one = null;
    29. FileConfiguration two = null;
    30.  
    31. private boolean setupEconomy(){
    32. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    33. if (economyProvider != null){
    34. economy = economyProvider.getProvider();
    35. }
    36. return (economy != null);
    37. }
    38.  
    39. public void onDisable(){
    40. PluginDescriptionFile pdfFile = getDescription();
    41. logger.info((new StringBuilder(String.valueOf(pdfFile.getName()))).append(" has been disabled!").toString());
    42. }
    43.  
    44. public void onEnable(){
    45. if(!setupEconomy()){
    46. getServer().getPluginManager().disablePlugin(this);
    47. return;
    48. }
    49.  
    50. getServer().getPluginManager().registerEvents(new MyEventHandler(), this);
    51. PluginDescriptionFile pdfFile = getDescription();
    52. logger.info((new StringBuilder(String.valueOf(pdfFile.getName()))).append(" version ").append(pdfFile.getVersion()).append(" has been enabled!").toString());
    53. getCommand("info").setExecutor(new Cmd_info(this));
    54. getCommand("about").setExecutor(new Cmd_about(this));
    55.  
    56. this.configFile = new File(this.getDataFolder(), "config.yml");
    57. this.config = YamlConfiguration.loadConfiguration(configFile);
    58. this.playersFile = new File(this.getDataFolder(), "players.yml");
    59. this.players = YamlConfiguration.loadConfiguration(playersFile);
    60. this.oneFile = new File(this.getDataFolder(), "one.yml");
    61. this.one = YamlConfiguration.loadConfiguration(oneFile);
    62. this.twoFile = new File(this.getDataFolder(), "two.yml");
    63. this.two = YamlConfiguration.loadConfiguration(twoFile);
    64. }
    65. }
     
  2. Offline

    Jogy34

    The files are actually created when you save them, not when you load them.
     
  3. Offline

    TheMcScavenger

    Well, that would explain. That brings me to a new problem:
    Code:java
    1. config.save(configFile);

    Gives me the error: "Unhandled exception type IOException"
     
  4. Offline

    Jogy34

    Surround it with try/catch blocks. That's just saying that it knows before hand that there is a good chance it might throw an IOException.
     
    tommycake50 likes this.
  5. Offline

    TheMcScavenger

    It worked, thanks!
     
  6. Offline

    MrSparkzz

    TheMcScavenger & Jogy34
    Code:java
    1.  
    2. config.saveDefaults();
    3.  

    is better for when you are creating a config.
     
  7. Offline

    Jogy34

    If you don't have a default config then it's useless and he's also using custom config files so you first have to find the default config yourself before you can save it.
     
  8. Offline

    MrSparkzz

    Jogy34
    I just assumed he had one. Because I didn't see any code going to a method that would add anything to it. But still, if he did, then saveDefaults() would be the way to go! :D
     
  9. Offline

    TheMcScavenger

    Jogy34 MrSparkzz
    To clear up any confusion: At the moment, I'm only using the players file, which I'm adding things to when players join for the first time. Since there shouldn't be anything in the config if the server doesn't have any joins, I don't need a default config. For the config.yml I will however make a default config file, which will (of course) be added using the code you provided ;)

    Hereby, I'd like to thank you both for your help, and change the thread prefix to solved :)
     
Thread Status:
Not open for further replies.

Share This Page