Config problems- deleting values

Discussion in 'Plugin Development' started by Adzwoolly, Apr 8, 2013.

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

    Adzwoolly

    I'm making a plugin that uses the config (really?) but, it keeps deleting stuff when I save it.
    The plugin gets rewards from the config and saves player data to the config.
    When it saves it does this to the config:
    Before:
    http://pastie.org/private/7hpax8nkshzlml5pg7f9a
    After:
    http://pastie.org/7374905

    It deletes the values that aren't used and puts ' around the numbers, as well as removing comments.
    I use:
    vv this to save player info (KillCount, KillStreak, DeathCount) vv
    Code:
    .getConfig().set("Players." + e.getEntity().getName() + ".KillStreak", 0);
    vv this to reward the player. If it does = null though it deletes it when I save the file.
    Code:
    if(plugin.getConfig().getInt("Players." + killername + ".KillCount") % 1 == 0){
                if(plugin.getConfig().getString("KillConstant.1") != null){
                        ItemStack item = new ItemStack(Material.getMaterial(plugin.getConfig().getString("KillConstant.1")), 1);
                        killer.getInventory().addItem(item);
                    }
                }
    vv this to save it vv
    Code:
    .saveConfig();
    Can anyone tell me why this is happening and how to fix it please?
     
  2. Offline

    Scizzr

    When you do saveConfig(); it automatically cleans the config up.

    Quoting your numbers : There's not really any way to change that as far as I know. All of the config.yml's I've messed with seem to have the same behavior. I'd just not be so OCD about it and let it do it's thing.

    Wiping your empty values : Same thing here. If you have an empty value, it removes it since it's not needed. Just set a default value (such as the keyword NONE) and use logic to ignore giving an item if it's this value.
     
  3. Offline

    Adzwoolly

    Scizzr Thankyou!
    I wasn't being OCD so much as it was removing important paths. Instead of checking for null, I'll set it to something such as none like you said.
    I'll test it then come back to the thread with the results.
     
  4. Offline

    Scizzr

    Ahh, gotcha. What I meant though was that the numbers being quoted shouldn't matter to the end user as long as it does what it needs to do. :)

    Also I just saw your comment about it removing your comments. Are you using plugin.getConfig().options().header(String value); or setting it manually by editing the file?
     
  5. Offline

    Adzwoolly

    Scizzr
    The comments are in the default config before it's edited.
    The numbers being quoted doesn't make a difference to the function, good.
     
  6. Offline

    Scizzr

    So the way I would go about it is by using that method to set the comments in the plugin itself. ;)
     
  7. Offline

    Adzwoolly

    Scizzr
    I will have the annotations on the bukkitdev page but, what do you mean by
    ?
    Thank you for your help by the way!
     
  8. Offline

    Scizzr

    Right before you save the config, set the header (top comments):
    Code:
    getConfig.options().header("#Configuration for Items4Kills by Adzwoolly!\n\n" +
                               "#Use the link below for item names\n" +
                               "#http://jd.bukkit.org/dev/doxygen/d6/d0e/enumorg_1_1bukkit_1_1Material.html");
    saveConfig();
    
     
  9. Offline

    Adzwoolly

Thread Status:
Not open for further replies.

Share This Page