Can i search for a particular value through bukkit standard configuration?

Discussion in 'Plugin Development' started by sddddgjd, Aug 22, 2011.

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

    sddddgjd

    I have a configuration that goes like this:
    Player
    Section1:
    Stuff2: <string>
    Stuff3: <string>
    Section2:
    Stuff5: <string>
    etc.

    Is the any way i can just search for "Stuff5" and get the value Stuff5 has?

    LE: From inside a plugin...-.-
     
  2. Offline

    oz_revulsion

    <Ctrl>+<F>?
     
  3. Offline

    sddddgjd

    I want the plugin to search it...
     
  4. Offline

    Darkman2412

    Loop through all lines and if a line starts with Stuff5, split that line and pick the value?

    Oh, and why don't you just use built-in configuration?

    @oz_revulsion LoL
     
  5. Offline

    sddddgjd

    I am using the standard configuration...from the tutorial on the bukkit forums!
    It's a YAML file,but the bukkit forums seem to remove all formatting! :(
     
  6. Offline

    oz_revulsion

    Which YAML library are you using? I use snake YAML and to find it there it is a matter of loading in the config file into Maps and then iterating through them to find Stuff5. Cheers Oz
     
  7. Offline

    Hacksore

    -snip-
    seriously wtf xenforo
     
  8. Offline

    Lolmewn

    Wow the posts get so messed up now.
     
  9. Offline

    sddddgjd

    I'm not sure...the default one? (lol)
    I create the file using this:
    Code:
    File f = new File(Core.dataFolder, "players/" + p.getName() + ".yml");
    		try {
    			f.createNewFile();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    return new Configuration(f);
    
    And then i change it using:

    cfg.setProperty("Section1.stuff1",34);

    How can i put this in a map?

    @Hacksore
    @Lolmewn
    ?????
     
  10. Offline

    Lolmewn

    How do you mean, the content of the file?
     
  11. Offline

    iffa

    config.getProperty("Section1.stuff5", "some string hiar"); ?
     
  12. Offline

    sddddgjd

    The problem is,i have lots of sections!
    There are like 20 sections...and if i put an if() to check every single "stuff" possible,the code will be huge? Isn't there any search function for yml files?
     
  13. Offline

    ChrizC

    Yeah, config.getString("nameOfStuff", "whatToDefaultToIfStuffIsntFound");
     
  14. Offline

    sddddgjd

    Don't i need to write the entire path in nameOfStuff? like "Category1.Stuff1"? I think i do...
    anyway,solved,with an awesome piece of code that looks like this:
    Code:
    for (String SubCat : cfg.getKeys("Category1")) {
    			for (String base : cfg.getKeys("Category1." + SuBCat)) {
                     //Do all my stuff
    }
    
     
Thread Status:
Not open for further replies.

Share This Page