Configuration Comments

Discussion in 'Plugin Development' started by shadow5353, Sep 25, 2013.

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

    shadow5353

    Hello bukkit Developers

    I have just 1 quick questions about Configuration Comments i have used getConfig().options().copyDefaults(true); but i cant get any Configuration Comments. please help
     
  2. Offline

    Janmm14

    shadow5353
    If you want to have comments in your first created config.yml, create your default config.yml like you want, and add it like tbe plugin.yml to your project. Then in your on Enable() do:
    saveDefaultConfig();
     
    tommycake50 likes this.
  3. Offline

    shadow5353

    Janmm14 but i am using a settingsmanager to my plugin and in the setup i cant use saveDefaultConfig
     
  4. Offline

    tommycake50

    Then you can't add comments using the default yaml API. It just isn't supported.
     
  5. Offline

    Hoolean

    shadow5353

    A 'settingsmanager'? You'll have to provide a bit more information, as there is no class built in to Bukkit using that name so I assume it is something you wrote yourself. :)
     
    Janmm14 and tommycake50 like this.
  6. Offline

    Alshain01

    The thing about these comments though... if you write to the file after it's creation, they tend to go away, even if you used saveDefaultConfig.
     
  7. Offline

    The_Doctor_123

    I'm having this issue also, how do other plugins pull it off?
     
  8. Offline

    tommycake50

    Easy question.
    DON'T. USE. YAML.
    Seriously YAML absolutely sucks i have dreaded it ever since i started with bukkit, The syntax sucks the parsing time sucks i have no idea why bukkit chose yaml.
    /rant
    I don't know how plugins pull it off, And I don't think they do.
     
  9. Offline

    The_Doctor_123

    tommycake50
    There's nothing wrong with YAML for easy configurations..
     
  10. Offline

    tommycake50

    Yeah for configs which only require a few lines yaml is fine.
    When you start using multiple files or large configs your code looks messy and it would be more efficient just to parse a plaintext document not to mention it takes up more space than it should(A few bytes but its still a bit).
    Although I guess no other configuration syntax is any better come to think of it.
    Maybe we should all just parse our own plaintext documents.
     
  11. Offline

    The_Doctor_123

    tommycake50
    Why would we parse our own? It would take lots more work than Bukkit's YAML since it's already there for us to use! What I'm really wondering here is how Bukkit's YAML configuration inefficient or whatever compared to what other things we could do?
     
  12. Offline

    shadow5353

    tommycake50 Is there nothing else i can do to get comments in the config when i use a settingsmanager
     
  13. Offline

    Janmm14

    if you save the default configs the same way as the plugin.yml, you can do this in your onEnable:
    Untested!
    Code:
    File f = new File(getDataFolder(), "yourconfigfile.yml");
    if(!f.exists()) {
    InputStream in = getClassLoader().getResourceAsStream("/yourconfigfile.yml");
    source = new FileInputStream(in).getChannel();
    destination = new FileOutputStream(f).getChannel();
    destination.transferFrom(source, 0, source.size());
    }
     
  14. Offline

    tommycake50

    Ok so for example yaml stores lists like this.
    Code:
    list:
        - item1
        - item2
        - etc
    
    It would be more efficient like this for example.
    Code:
    list:item1,item2,etc
    
    Plus it uses indentation which doesnt allow tabs eg:
    Code:
    section:
        subsection:
            subsubsection:
                something:something
    
    could be written like this(but with tabs).
    Code:
    section{
        subsection{
            subsubsection{
                something:something
            }
        }
    }
    
    This way you can just .trim and still keep the structure.
    See where im going?
    I could go on if you like?
    Yaml is also missing a lot of good methods it could have implemented a lot better.
    EG: Allowing comment insertion.
    etc.



    You could write to the file yourself with a bufferedwriter/printwriter.
     
Thread Status:
Not open for further replies.

Share This Page