Infinite Strings in Config

Discussion in 'Plugin Development' started by Fell, Dec 22, 2011.

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

    Fell

    Hi, I'm working on a Chat-Bot and I was hoping players would be able to define prompts and responses infinity in the config... is this possible?

    It would need to be like this...
    Prompt1 : "Hi chatbot I love you"
    Response1 : "I love you too"

    or even...

    "Hi chatbot I love you" = "I love you too"

    But I don't want these to be in the config already, I want users to define as many as possible
    Thanks :)

    Also: How do you turn ColorCodes into &-codes??
     
  2. Offline

    skore87

    I'm still new how the config works, but if I understand it correctly, you could set a path to this and get a listing of all the child nodes. Like the path = "CleverBot.Phrases" and each node is the phrase prompt and the child String[] are potential responses.
    I would be impressed if you were to make something like the actual cleverbot and decipher key words and meanings. But that's likely out of the scope of your project.

    I've been learning a little about the depreciated Configuration, and it makes this very easy. It's replacement is YamlConfiguration, and it's a bit different though.
     
  3. Offline

    Chiller

    How do you set things in the config?!
     
  4. Offline

    skore87

    I don't know the getConfig() very well, but with Configuration you can do something like this:
    Code:
            Configuration c = new Configuration(new File("plugins/YourPlugin/somefile.yml"));
            c.setProperty("This is the full path within the file", "This is your data to place");
            c.save();
    But there are other ways to do this. I just find this simple for me and will have to learn the other methods soon.
    Here are two tutorials that I find helpful. The FileConfiguration API and the newer YamlConfiguration.
     
  5. Offline

    halley

    Don't try to write to the config-- write to a separate file or database. The other file might be YAML, or it might be a plain text file, but server admins would probably prefer the data be separate from the basic working settings you keep in the config.yml file.
     
  6. Offline

    skore87

    even with the getConfig(), you can actually save and load from a separate file other than your default config.yml
    Code:
            getConfig().save(filepath);
            getConfig().load(filepath);
    Not that I'm an advocate for it, just happened to explore it a tad bit recently.
     
  7. Offline

    Sagacious_Zed Bukkit Docs

    @skore87
    getConfig() and getConfig().options().configuration() gives you back the same object
     
  8. Offline

    skore87

    ehh sue me =P
     
Thread Status:
Not open for further replies.

Share This Page