I don't understand yml

Discussion in 'Plugin Development' started by bubblegumsoldier, Jun 19, 2012.

Thread Status:
Not open for further replies.
  1. Hi,
    Sorry, maybe the question is silly... But I still haven't found any tutorial for yaml/yml configuration that worked in my scripts.
    So please.... Is there a maybe easy function like

    String Name = config.get("name", "plugins/Config/config.yml");

    ? Please I don't get it
     
  2. Config config = getConfig();
    String Name = config.get("name");
     
  3. Offline

    jamiemac262

    i am sort of in the same boat except i cant seem to create custom YAML files :( and i havent tried to make a config.yml

    i'm also noticing the severe lack of helpful help.. mabey it's just me but 2 lines of code is not a solution..... where do those lines go? does my class need to extend something for them to work etc....
     
  4. jamiemac262
    1. You would get more help if you search: <Edit by Moderator: Redacted bit url>
    2. we never talked about custom YAML files, but:
    File f = new File("path/to/your/file.ext");
    YamlConfiguration conf = new YamlConfiguration();
    conf.load(f);
    String name = conf.get("name");
    3. these lines go to where ever you want them to be.
     
    Last edited by a moderator: Feb 19, 2017
  5. [quote uid=92350 name="V10lator" post=1172686]jamiemac262
    1. You would get more help if you search: <Edit by Moderator: Redacted bit url>
    2. we never talked about custom YAML files, but:
    File f = new File("path/to/your/file.ext");
    YamlConfiguration conf = new YamlConfiguration();
    conf.load(f);
    String name = conf.get("name");
    3. these lines go to where ever you want them to be.[/quote]
    is there a way to save a new variable in there like
    conf.new("adress", "Somewhere");

    Code:
    File f = new File("plugins/nick/config.yml");
        YamlConfiguration conf = new YamlConfiguration();
        public void OnEnable(){
            System.out.println("nickname Plugin is enabled");
            try {
                conf.load(f);
            } catch (FileNotFoundException e) {
           
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvalidConfigurationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
           
            String name = (String) conf.get("name");
            System.out.println(name);
        }
    It gives me a bunch of errors...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 19, 2017
  6. Offline

    Luloak2

    Use the old version of bukkit configs, it is working...

    PHP:
    public void onEnable()
        {   
            
    config getConfig();
     
    //now only examples how to read/write
    boolean your_bolean this.getConfig().getBoolean("your_bolean_in_config_file"true);
    //the last "true" is only if he does not find the variable in your file
     
    boolean create_default_Config_File this.getConfig().getBoolean("Create_default_ConfigFile"true);
    //this "true" is very important, because at first time the plugin runs, there is no config file, so create it ;)
     
    if (create_default_Config_File == true)       
        {               
           
    this.getConfig().set("Create_default_ConfigFile"false);                   
           
    //and save the config.yml
           
    saveConfig();
        }
     
    }
     
  7. Luloak2 This is the new verison, not the old one. The old one was getConfiguration() and was removed from bukkit some time ago. Also Why do you save the reply of getConfig() into config, but then you call getConfig() again everytime instead of using config.
    Sure. Did you click on the first link my lmgtfy link suggested to you? It's all explained there, but here again:
    conf.set("adress", "Something"); // set address to Something
    The good thing is that a custom configuration works almost the same way the default one does. The only real diference is that you save the default one with saveConfig(); and load it with getConfig(); while you use
    YamlConfiguration config = new YamlConfiguratio();
    config.load(file);
    to load a custom config and
    config.save(file);
    to save it. But that's all explained at the link, too.
    Copy&pasted your code example into eclipse: 0 errors.
     
Thread Status:
Not open for further replies.

Share This Page