Bukkit Custom Config Generation

Discussion in 'Plugin Development' started by goldencreeper, Sep 7, 2012.

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


    Hey minecrafters, i am creating a plugin for my server(May be released to the public later on) and im having a hard time trying to generate a custom config file. Yes i have looked at http://wiki.bukkit.org/Introduction_to_the_New_Configuration but that didnt help much so i tried doing it a different way. My plugin's src code is here: https://github.com/danmw3/ServerPlugin
    when it tries to create the config file it usually gives me a null pointer exception.
    If you need any other details just tell me and ill try to provide them.
    Minecraft Version: 1.3.1
    Bukkit Version: 1.3.1 R2.0
    Java Version: 7
    OS: Windows 7 64 bit
    IDE: Eclipse

  2. Offline


    File conf;
    FileConfiguration config;
    public void onEnable() {
    if (conf == null) {
    conf = new File(getDataFolder(), "die.yml");
    config = YamlConfiguration.loadConfiguration(conf);
    log.info("[Plugin] Enabled!");
    public void saveConf() {
    if (conf == null || config == null) {
    try {
    } catch (IOException e) {
    log.severe("[Plugin] Unable to Save Config.");
    Try this o.o
  3. Offline


    that works or u could try this

    1. public void createconfig1() {
    2. // Creates config.yml
    3. File configfile = new File(getDataFolder() + File.separator + "config.yml");
    4. // If config.yml doesnt exit
    5. if (!configfile.exists()) {
    6. // Tells console its creating a config.yml
    7. this.getConfig().addDefault("this.is.aa.string",
    8. "yo i am aaa string");
    9. this.getConfig().options().copyDefaults(true);
    10. this.saveDefaultConfig();
    11. }
    12. }

    all u need to do now is to put createconfig() into your onEnable()
  4. Offline


    Thx for the fast reply and yes that did work but i want to create a class file that holds the config creation code so if i need to create more configs i wont have to re-type that code for every config. I have tried to create a class called ConfigManager and then created a method with the config creation code and copied over the saveConf method. Then in the main class i put public ConfigManager cm; then in the onEnable method i put cm.createConf(); then i also put cm.saveConf(); but that didnt work. Any idea?
  5. Offline


    make a new class called what ever you want heres a example
  6. Offline


    then what would i put in the onEnable method to create the config?
  7. Offline


    exact same thing you would do with normal voids
  8. Offline


    could u put up an example of the main plugin class that contains the code that goes in the onEnable method to generate the config? srry im kind of a noob when it comes to custom config generation lol
  9. Offline


    How would I get the config outside of that void/class?
  10. Offline

    Sagacious_Zed Bukkit Docs

    That approach more than necessary, and will only change the file named config.yml
Thread Status:
Not open for further replies.

Share This Page