Default config.yml ignored

Discussion in 'Plugin Development' started by zolcos, Oct 29, 2011.

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

    zolcos

    Since the old Bukkit config system was deprecated, I've been following this tutorial to upgrade: http://wiki.bukkit.org/Introduction_to_the_New_Configuration
    All I want to do is put my defaults in the jar's config.yml, be able to load the user's config.yml, and when values are missing from it, assume defaults and write them. That way, when the user starts with no config file, one containing default values will be created for them. In other words, the same thing every other plugin does.

    However, I noticed that when I load my plugin without a config.yml on the server, one is created, but it's blank. I tried checking the values given within the plugin, and it turns out, the defaults really are not there. According to that tutorial, adding a default config.yml to the jar and calling config.options().copyDefaults(true); should be enough to provide all the options with a default value, but I must be missing something.
    Btw, when I edit the blank config.yml that is created, and dump the contents of the jar's config.yml into it, the values are there, so I know the structure is OK.

    Here's my code that gets called in my onEnable. "plugin" is the object of my main class that extends JavaPlugin.
    Code:
            FileConfiguration config = plugin.getConfig();
            config.options().copyDefaults(true);
    
            SHOP_COST =                config.getDouble(    "fees.create");
            MOVE_COST =                config.getDouble(    "fees.move");
            DEFAULT_WIDTH =            config.getInt(        "size.default-width");
            DEFAULT_HEIGHT =        config.getInt(        "size.default-height");
            MAX_WIDTH =                config.getInt(        "size.max-width");
            MAX_HEIGHT =            config.getInt(        "size.max-height");
            MAX_SHOPS_PER_PLAYER =    config.getInt(        "limits.shops-per-player");
            MAX_DAMAGE =             config.getInt(        "limits.item-damage");
            FIND_MAX_DISTANCE =        config.getInt(        "limits.find-distance");
            LOG_ENABLE =            config.getBoolean(    "log.enable");
            NOTIFY_INTERVAL =        config.getInt(        "log.notify-interval");
            LOG_LIMIT =                config.getInt(        "log.limit");
            DEBUG =                    config.getBoolean(    "debug");
            plugin.saveConfig();
    Here's my config.yml that is placed in the jar right next to my plugin.yml:
    Code:
    limits:
        item-damage: 35      #Maximum damage% with which a shop will accept an item. Limit of 35 damage here means require at least 65% durability remaining. Needed because item damage is discarded when adding to stock.
        find-distance: 150   #Block radius to include shops in "find" results.
        shops-per-player: -1 #Maximum number of shops each player can have; Unlimited = -1
    fees:
        create: 100.0        #Cost of creating a shop; 0 = free
        move: 10.0           #Cost of moving a shop; 0 = free
    log:
        enable: true         #Enable transaction logging.
        limit: 100           #Maximum number of transactions saved in log per shop.
        notify-interval: 300 #Number of seconds between transaction notifications; 0 = Disable notifications
    size:
        max-height: 10       #Maximum custom shop height.
        max-width: 30        #Maximum custom shop width (both horizontal dimensions).
        default-height: 3    #Default shop height.
        default-width: 5     #Default shop width (both horizontal dimensions).
    debug: false             #Enable verbose debug output.
    
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    Does this code live inside a different class? It is not immediately clear to me why you have a plugin variable that refers to your main object, if it is in you r main object.
     
  3. Offline

    zolcos

    You got it right. It's a separate class that handles configuration and thus needs the plugin object passed in. This approach worked fine when I was using org.bukkit.util.Configuration
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    You did confirm that it is in the jar? In the event you are using an IDE.

    Version of Bukkit and CraftBukkit you are using?

    And you did not override getConfig in your main correct?
     
  5. Offline

    zolcos

    Yes, I opened the jar with 7zip and it's definitely in there, in the same place as plugin.yml.
    I didn't override getConfig.
    Using CB 1337.
    Compiled against Bukkit from the head branch at commit 78616678ea3600f351299097b07fb37fb5890a73
     
  6. Offline

    Sagacious_Zed Bukkit Docs

    seems like a problem with this bukkit commit, the one i was using before worked....
    and it magically broke with this commit.

    or it could have been craftbukkit, it worked before but not working now.....

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  7. Offline

    zolcos

    Interesting! We may have grounds for a bug report. What commit were you using before when it worked?
     
  8. Offline

    Sagacious_Zed Bukkit Docs

    It was when it first came out.... Whatever that was...

    @zolcos
    Never mind, I found my problem. I can now load the defaults with the prescribed method. Working for the HEAD revision and the latest RB. For the record, i forgot the add my config.yml back after changing stuff.

    back to square one.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  9. Offline

    zolcos

    Ah, no lead then. But thanks
     
Thread Status:
Not open for further replies.

Share This Page