Persistance,Databases,Flatfile Data storage?

Discussion in 'Plugin Development' started by rob4001, Jul 11, 2011.

Thread Status:
Not open for further replies.
  1. Im wanting to make a plugin that stores data such as player names town names ranks etc

    but i dont know how to store the data

    Persistance looked like the best and easiest choice yet i couldnt get to work (Errors and such)
    i dont know SQL so MySQL and SQLite was out
    and flat files seemed too unstable / easily corrupted

    What should i do

    Code examples much appreciated

    i would want two tables

    one for towns

    Town name, owner name, news etc

    and one for residents

    Player name, town nme, rank etc
  2. Offline


  3. You could use Alta189's SQL library. I'd recommend using SQLite for your purposes. Here are some preprepared statements which will create a table. SQL syntax is fairly straightforward so with a little research you'll be writing your own statements in no time :). Make sure you take a look at his tutorial on how to instantiate the SQL core. For the example I will assume that you have already done that.

    sqlCore core;

    void createTables(){
    String t1 "CREATE TABLE towns( 'id' INTEGER PRIMARY KEY AUTOINCREMENT, 'name' VARCHAR(100), 'owner' VARCHAR(100), 'news' VARCHAR(100));";//You can add more yourself.
    String t2 "CREATE TABLE residents( 'id' INTEGER PRIMARY KEY AUTOINCREMENT, 'player' VARCHAR(100), 'town' VARCHAR(100), 'rank' VARCHAR(100));";
    Looking through the example source provided by Alta189 you'll be able to figure out how to add and retrieve data from those tables. If you have any problems I'll do my best to help you out ;)
  4. Offline


  5. Offline


    I've got a thing for this. It uses SQL Lite and Java's serialization. I use it myself in some yet-as-to-be-released plugins (still not feature complete).

    I don't know how much you might know about serialization in Java but it is rather a bit picky. The trick I used in my plugin to keep things sane is to have a separate "serializable" version of my data for complex objects and resurrect them from that.

    It requires very little configuration (next to none) and very little code (a few lines). Caveat: serialized objects are blobs of binary data. You will need to provide your users administration tools and / or commands. Really, though, you should have those anyway so that in-game admins can do their job.

    I'd be glad to give you a hand if it sounds desirable. Love to see this get used!

    You can see it on my github:

    To prevent another Holy War: YES flat or human readable DB / Config files are a benefit sometimes. YES Yaml has it's place. This is for incredibly fast and simple storage of data that can be interfaced with via the program or command line tools provided by the developer. It keeps disk access in the separate thread to keep the main thread light and fast. It is thread safe and uses a storage format this is battle tested to hell and back.

    It works, it works fast, it works well, and you use it like a Map. Easy =D
  6. Offline


Thread Status:
Not open for further replies.

Share This Page