Edit Config, Save Comments?

Discussion in 'Plugin Development' started by pookeythekid, Mar 15, 2014.

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

    pookeythekid

    Hey guys. I've just made a new plugin that is ESSENTIAL to my server's new Minigames, and it involves world spawns; actually, world spawns is exactly what it is. Anyway... When I edit the config file in-game with a command, it works, but Bukkit's method "saveConfig()" doesn't save config comments. I've also tried using "saveDefaultConfig()" which does save the comments, but saves the default config; the one that's compiled with the plugin's jar file, not the recently edited one. This is where I'm kind of in despair. Granted, I don't really NEED comments, as it's my plugin and I know how it works, but I really, really want to upload this to BukkitDev, to make up for my letdown with my other plugin, SecureLogin.

    If anyone can help with this, please do. I very much hope I can find a solution for this.

    Thanks! :)

    P.S.
    Here's my method that I call when I add to my config via in-game command.
    Code:java
    1. public void setWorldSpawn(String worldName, Player player) {
    2.  
    3. M.getConfig().set("respawnWorlds." + worldName + ".x", player.getLocation().getX());
    4. M.getConfig().set("respawnWorlds." + worldName + ".y", player.getLocation().getY());
    5. M.getConfig().set("respawnWorlds." + worldName + ".z", player.getLocation().getZ());
    6. M.getConfig().set("respawnWorlds." + worldName + ".Pitch", player.getLocation().getPitch());
    7. M.getConfig().set("respawnWorlds." + worldName + ".Yaw", player.getLocation().getYaw());
    8.  
    9. M.saveConfig();
    10.  
    11. player.sendMessage(ChatColor.GREEN + "WorldSpawn Set.");
    12.  
    13. }


    A possible solution to this would be creating new files, but that's part of the Java world that I have zero experience with.

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

    amhokies

    pookeythekid
    Doesn't saving a config with comments already in it keep the comments in?
     
  3. Offline

    pookeythekid

    amhokies Umm yes... That is if you mean using the method "saveDefaultConfig()". But as I mentioned, that's the default config, the one that gets compiled with the plugin's jar file. It never takes effect unless the config file is missing or deleted. Bukkit's method "saveConfig()" does save the config anytime, but removes the comments. These are the only two ways of saving the config that I know of, so you can now see that I'm at a loss.
     
  4. Offline

    Arcoz

    I don't think this is possible (or so I've heard)
    The only work around is using headers
     
  5. Offline

    pookeythekid

    Arcoz Then you wouldn't happen to know about file creation, would you?
     
  6. Offline

    Arcoz

    Try watching Appljuze's video about config files.
     
  7. Offline

    xXSniperzzXx_SD

    pookeythekid as far as I know there is no bukkit api for it other then saveDefaultConfig but what I do is just put all the info in the headers, you could also find other plugins that have comments in the config then see if they have their source public
     
  8. Offline

    AoH_Ruthless

  9. Offline

    xXSniperzzXx_SD

    pookeythekid Another way you can do it, is see if the file exists, if it doesn't saveDefaultConfig() otherwise do nothing. The downfall here is if someone removes something from the config, or you add something in a later version it won't add it.
     
  10. Offline

    pookeythekid

    Wait a second. I'll be adding to my config via in-game command, and both saveDefaultConfig and doing nothing don't save the data into the config.

    AoH_Ruthless Thank you very much for the link. Not to be lazy, but it's nice when someone finds exactly what I want for me. :p I was going to learn file creation this week, as another solution. Then I could put instructions into the config (or another file, since I'd know file creation by then), and the config wouldn't have in-game-command-changing settings.

    Arcoz ... I didn't know Bukkit had a method so simple for multiple config generation... Thanks! He also explains really well so far, and I'm only a few minutes into the video at this point.

    Arcoz What is this dark magic?!??! IT'S SO DANG SIMPLE!!! It's unreal! Yet it's real... I can't thank you enough for this video. : DDDD

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page