[LIB] PCD - Parsable Configuration Data - Save data to and from Strings!

Discussion in 'Resources' started by caldabeast, Feb 23, 2013.

?

Does this seem useful to you?

  1. Yes!

    66.7%
  2. Not really.

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

    caldabeast

    I have been working on a rather large project over the past few weeks, and I had recently come to the point where I needed to create the plugin's i/o management, and I realized that I had no good way to go about that. Bukkit's YAML configuration is great, but it doesn't work for what I was doing, so I decided to make...

    PCD - Parsable Configuration Data
    PCD is a library that converts data in an out of Strings for use in anything you could need to user Strings in. It contains a data and module structure similar to that of Minecraft's NBT tag system.

    How does it work?
    PCD uses a variety of objects designed to make the conversion of data simple and easy. The first step you must take is to create a ParsableConfigurationData with the name of the data. You can then add different "DataBits" and "Modules" to it. For a quick look at the ParsableConfigurationData in action, take a look at the syntax block below.
    Code:java
    1. ParsableConfigurationData data = new ParsableConfigurationData("ExamplePCD");
    2.  
    3. //adding data bits of all four DataBit types to the PCD
    4. data.addNewData(new BooleanData("exampleBool", true));
    5. data.addNewData(new IntData("exampleInt", 42));
    6. data.addNewData(new FloatData("exampleFloat", 42.0f));
    7. data.addNewData(new StringData("exampleString", "example"));
    8.  
    9. //creating a new module to add to the ParsableConfigurationData
    10. ParsableModule module = new ParsableModule("ExampleModule");
    11. //you can add data to modules the same way you add it to PCDs
    12. module.addNewDatabit(new BooleanData("moduleBool",false));
    13. module.addNewDatabit(new IntData("moduleInt", 24));
    14. module.addNewDatabit(new FloatData("moduleFloat", 24.0f));
    15. module.addNewDatabit(new StringData("moduleString", "module"));
    16. //adding the module to the PCD
    17. data.addNewData(module);
    Great! Making a ParsableConfigurationData is simple enough, but now you need to do something with it. To convert the data contained inside to a String for use in any way, it is as simple as the following method:
    Code:java
    1. String parsed = data.getParsedString();
    The parsed string of the PCD created above would look like this:
    With that String saved and later accessible, you can reconstruct it into an UnparsedConfigurationData and retrieve the data put into it. How? Simple:
    Code:java
    1. String unparsed = however you retrieve your data;
    2. UnparsedConfigurationData data = new UnparsedConfigurationData(unparsed);
    If unparsing the String from earlier, you would get an UnparsedConfigurationData with the below data. You can see that it keeps the name and the type of the data from the PCD in the UCD.
    You can retrieve the data by name and type using the methods getBoolean(name), getInt(name), getFloat(name), getString(name), and getModule(name). These methods return the corresponding data, read from the String.

    Using this library, you can easily save and retrieve complex data structures without having to parse and unparse your own data each time. (Hopefully) It will make your lives easier so you can stop spending so much time on the saving of data and focus on making your plugins (or anything, for that matter, because PCD has no Bukkit dependencies) as great as they can be!

    Downloads and Source Code
    Download
    Source Code and Documentation (Powered by Doxygen)
    If either of these links go down, inform me and I will reconnect them as quickly as possible.

    License
    PCD isn't licensed in any way.
    Feel free to use it wherever you want, however you want.
    You don't have to credit me, but please at least don't claim it as your own.

    If you have any questions, suggestions, or bugs, feel free to post in this thread or send me a message. I'd love to hear them!

    duuuuurp I meant to post this in Resources. Could somebody move it for me..?

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

    Butkicker12

  3. Offline

    caldabeast

    Thanks!
     
  4. Offline

    evilmidget38

    I apologize if you explained this, but I don't really understand what this offers over bukkit's configuration. Could you elaborate on what it offers that bukkit doesn't?
     
  5. Offline

    caldabeast

    It doesn't necessarily do anything different or better than Bukkit's configuration, but it is intended for when Bukkit's YAMLConfiguration cannot be used.
    I designed it so that I could use it with MySQL and get data in a similar way that I could from a YAMLConfiguration without having t0 create a field for each piece of data and instead having a single 'data' field which I can retrieve in Java. Instead of having to manually parse the String for each different plugin I would need to do this with, I created this to do it for me.
    Not necessarily useful to anyone else, but if it helps at least one person, then it does it's job.
     
  6. Offline

    Comphenix

    You could use YamlConfiguration.loadFromString(data) and saveToString() though.
     
    caldabeast likes this.
  7. Offline

    caldabeast

    Welp. That would have been useful to know.
    Oh well.
     
Thread Status:
Not open for further replies.

Share This Page