How to insert a comment from the plugin to file .yml

Discussion in 'Plugin Development' started by przemek3697, Feb 2, 2013.

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

    przemek3697

    Hi I have a problem, I do not know how from plugin create a comment in a file *.yml
    Please help
    Plugin:
    Code:
    // getSerwer() return FileConfiguration
    // this is example
    getSerwer().set("", "# This is a simple comment");
    //I know that the first argument can not be empty
    getSerwer().set("on", 1)
    getSerwer().set("", "# This is a second comment");
    getSerwer().set("pvp", "on");
     
    
    This code is not working
    Example config
    Code:
    # This is a simple comment
    on: 1
    # This is a second comment
    pvp: on
    Bump

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

    Assult

    getSerwer()?, Its getServer()
     
  3. Offline

    przemek3697

     
  4. Offline

    Assult

    Ah, didnt read that.. but

    I dont think you are doing anything, becouse getSerwer() only returns FileConfiguration and you have not Set the directory for the file and all that. (I Could be very wrong, just to let you know...)

    You should read this:

    http://wiki.bukkit.org/Configuration_API_Reference

    Edit: Remove // before getSerwer() return FileConfiguration

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

    przemek3697

    You do not understand me
    Code:java
    1. public FileConfiguration getSerwer(){
    2. return this.serwer;
    3. }
    4. public void serwer(){
    5. this.serwerFile = new File(getDataFolder(), "serwer.yml");
    6. this.serwer = YamlConfiguration.loadConfiguration(this.serwerFile);
    7. }
    8. public void onEnable(){
    9. serwer();
    10. if(!this.serwerFile.exists()){
    11. try {
    12. this.serwerFile.createNewFile();
    13. zapiszSerwer();
    14. getSerwer().set("# Czas w sekundach wyznaczajacy co ile ma byc uruchamiane czyszczenie entities", "");
    15. getSerwer().set("czyszczenieentities", 0);
    16. getSerwer().set("autoryzacjaon", 1);
    17. getSerwer().set("# Powiadomienia wyswietlane gracza", null);
    18. getSerwer().set("lang.cos.elo", "witaj");
    19.  
    20. zapiszSerwer();
    21. } catch (IOException e) {
    22. // TODO Auto-generated catch block
    23. e.printStackTrace();
    24. }
    25. }
    26.  
    27. }

    This code is not working
    I want to to create a file and settings were also writing comments
    I can not explain it well because I do not know English well
     
  6. Offline

    sensus12

    you can just do
    saveDefaultConfig();
    then create config in src folder
    and write your strings
     
  7. Offline

    teunie75

    I use this for my plugin and it works:
    Code:
    File folder = new File(Bukkit.getUpdateFolder() + "/../plugins/<your plugin folder> (where the config.yml is saved)>");
    File file = new File(folder + "/" + "<filename>.yml");
    Then:
    Code:
    if(!file.exists()){
                try {
                    folder.mkdir();
                    file.createNewFile();
                    logger.info("File " + file.getName()+ " created in " + file.getPath());
                }catch (IOException e){
                    logger.severe("Error, could not create " + file.getName());
                }
     
Thread Status:
Not open for further replies.

Share This Page