[LIB] IO-Toolkit - easy saving/loading API

Discussion in 'Resources' started by Kierrow, Jan 4, 2012.

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

    Kierrow

    IO-Toolkit
    version 1

    Because I have seen a lot of people ask about proper saving and loading of files,
    and I personally did not want to handle all the exceptions it brings with it every time I'd have to use it, I have created IO-Toolkit.

    IO-Toolkit provides an easy saving/loading API for Bukkit Plugins.
    In Bukkit's very own Plugin Tutorial, there is a section about how to do this yourself,
    for proper understanding of the subject, you should read that first.

    -> BukkitDev: IO-Toolkit
    -> API documentation
    -> How to install...


    There are only two classes, the SaveManager and the Save.
    While the Save itself contains the information you want to store (which can basically be anything),
    the SaveManager provides methods to save and load the Saves.
    A Save is built up like a HashMap, with the key being a String, and the value being a class you can
    specify yourself (more on that in a bit).
    This is how you would load a Save containing an Integer as the information:

    Code:
    private Save<Integer> example;
    
    public void onEnable() {
        example = SaveManager.load(this, "example");
    }
    
    public void onDisable() {
        SaveManager.save(example);
    }
    One thing you must keep in mind about the Saves is that they use a generic to define
    what kind of information they actually contain. That generic (Save<GENERIC>) class must implement Serializable, and all it's members (and so on) must as well, for the Save to be savable.
    If you don't keep that in mind, the Java VM will throw exceptions at you!

    To actually store or get integers for that Save, you do the following:

    Code:
    private Save<Integer> example; //We loaded that earlier...
    
    public void addOneToStuff() {
        if (example.contains("test_entry")) {
            int old_value = example.get("test_entry");
            int new_value = old_value + 5;
            example.set("test_entry", new_value);
        } else {
            example.set("test_entry", 0);
        }
    }
    For demonstration purposes, I did not show all methods here.

    But as you can see, this library can be used in several ways, for example to assign Players
    IDs, money, locations, you could set traps, protect area...
    The possibilities are infinite!

    If you did not understand everything or just want to say Hi!, PM me.
     
Thread Status:
Not open for further replies.

Share This Page