[Lib] PropertiesLibrary - Explanation (How to use it)

Discussion in 'Resources' started by GameplayJDK, Mar 20, 2014.

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

    GameplayJDK

    In the past I used the yml config, which comes with bukkit, but I wanted a similar way to store my config and my plugins data, which is a bit easier and which can store huge amounts of data easily and fast.​
    So I decided to create my own class for this. Now, that I published the library on bukkit dev, I want to provide a resource on how to use the functions of the library.​

    The Projects git repository can be found here.​

    First I'll list all methods of the PluginProperties class and explain their functionality:


    • Constructors:
    • PluginProperties(Plugin plugin) *
    "plugin" is your plugin that is instantiating the class (in most cases it'll be "this")​
    Note: If you decide to use this constructor you necessarily have to configure the name and if it's shared or not later.
    • PluginProperties(Plugin plugin, String name, boolean shared) *
    "plugin" is your plugin that is instantiating the class (in most cases it'll be "this")​
    "name" is the name of the properties' file (in most cases it'll be your plugins name or at least it'll contain it)​
    "shared" defines if the properties you're creating are created inside the "Global"- or inside the "Internal"-Folder (in this version this variable doesn't matter, but later it'll define if other plugins can access your properties)​
    • Methods:
    • PluginProperties setup() *
    This method returns the class itself, so you can call it while creating a new instance and it sets up a few private variables​
    • PluginProperties name(String name) *
    "name" is the name of the properties' file (in most cases it'll be your plugins name or at least it'll contain it)​
    This method returns the class itself, so you can call it while creating a new instance and it sets up a few private variables​
    • String name() *
    This method returns the raw file name (NOT the relative path!)​
    • PluginProperties shared(boolean shared) *
    "shared" defines if the properties you're creating are created inside the "Global"- or inside the "Internal"-Folder (in this version this variable doesn't matter, but later it'll define if other plugins can access your properties)​
    This method returns the class itself, so you can call it while creating a new instance and it sets up a few private variables​
    • boolean shared() *
    This method returns true if the properties are shared and false if not (in this version this variable doesn't matter, but later it'll define if other plugins can access your properties)​
    • void load() *
    This method loads the config (if it's existing)​
    • void add(String key, String value) *
    "key" is the identifying key of the kv-pair​
    "value" is the value of the key in the kv-pair​
    This method adds a kv-pair with the "value" associated to the "key"​
    • void remove(Object key) *
    "key" is the identifying key of the kv-pair​
    This method removes a kv-pair if its "key" matchs​
    • void clear() *
    This method removes all kv-pairs from the properties (it clears the properties)​
    • boolean containsKey(Object key) *
    "key" is the identifying key of the kv-pair​
    This method returns true if a kv-pairs key matchs the "key"​
    • boolean containsValue(Object value) *
    "value" is the value of the key in the kv-pair​
    This method returns true if a kv-pairs value matchs the "value"​
    • void save(String comment) *
    "comment" is a comment that will be save to the config as comment​
    This method saves the properties to the associated file, but it doesn't close the streams​
    You are able to call this method whenever you want to save the properties.​
    • void unload() *
    This method unloads the properties (they are not writable anymore. It does NOT save the properties before unloading!)​
    • PluginProperties useOwn(String propertiesFolder, String globalPropertiesFolder, String internalPropertiesFolder) *
    "propertiesFolder" is the relative path to the properties' parent folder​
    "globalPropertiesFolder" is the relative path to the properties' "Global"-Folder​
    "internalPropertiesFolder" is the relative path to the properties' "Internal"-Folder​
    This method changes the default path to the parent, global and internal folder of the properties (only this one)​
    This enables per-plugin usage​
    • Properties raw() *
    This method returns the raw java.util.Properties which are used by this class​
    It allows you to call more methods​
    • Plugin accessOwner() *
    This method return the plugin object which owns these properties​


    If you have any suggestion or found bugs, feel free to post them or contact me. :)
     
Thread Status:
Not open for further replies.

Share This Page