HomeJavaMods[1.8-1.14] CoreData - A lightweight, centralized data solution for your plugins!
[1.8-1.14] CoreData - A lightweight, centralized data solution for your plugins!
ModsJava

[1.8-1.14] CoreData - A lightweight, centralized data solution for your plugins!

⬇ Download on Spigot
[​IMG]
What is CoreData?

The majority of plugins in the Spigot resources section involve some level of data storage regarding the users who use the plugin. I often find myself creating new methods in each of my projects for storing data in regards to users. This plugin is designed to make the storage of data in regards to players fast and lightweight so your plugins do not take up precious storage space.

How is CoreData better than my current data solution?
CoreData's purpose is to save storage space by centralizing the location of all plugin data. Instead of each plugin creating their own files to store user data, our API creates a file for each user and allows your plugin to store data under a label in that user's file. This allows your plugins to not have to worry about file management or data storage.

Along with centralized data, our data solution is faster than traditional flat file data storage. Before, you would save all data in a file and traverse it to find the user's data. CoreData will find the user's file and directly access their data. This is very important as plugins that store data for thousands of users will see increases in the time it takes to find a user's data under traditional flat file methods while CoreData sees no change at all.

How do I use CoreData?
The first step is ensuring your plugin depends on CoreData.
Code (YAML):
depend : [ CoreData ]
The next step is creating a reference to our user handler.
Code (Java):

if ( ! this . getServer ( ) . getPluginManager ( ) . isPluginEnabled ( "CoreData" ) ) {
    this . getLogger ( ) . severe ( "[Hook] CoreData not found. Disabling plugin..." ) ;
    return ;
}
UserHandler userHandler = ( ( com. ethanpritchard . data . Main ) this . getServer ( ) . getPluginManager ( ) . getPlugin ( "CoreData" ) ) . getUserHandler ( ) ;
 
Once you have hooked into our plugin and gathered the user handler instance, you have access to a few functions.
Code (Java):
userHandler. createUserFile ( uuid ) ; // Returns void

userHandler. setUserData ( uuid, label, data ) ; // Returns void
userHandler. getUserData ( uuid, label ) ; // Returns object
userHandler. getAllUsersData ( label ) ; // Returns Map<UUID, Object>
Data is stored in a user's file under a label. A label is a String that acts as an identifier to later find that piece of data. Good labels will be more complex strings that further describe the data being stored. Bad labels will be generic words or phrases that other plugins may also attempt to store data under. Here is an example of labels:

Code (Text):
balance = BAD
myPluginName.balance = GOOD
Please note that you should only use periods to separate your strings. The data is stored using Spigot's YamlConfiguration.

How do I transfer existing data to CoreData?
To transfer data to CoreData, you must have a method to get all of your users and their data as well as an iterator to navigate this data. Here is an example piece of code:

Code (Java):
private UserHandler coreDataUserHandler ;

@Override
public void onEnable ( ) {
        if ( ! this . getServer ( ) . getPluginManager ( ) . isPluginEnabled ( "CoreData" ) ) {
            this . getLogger ( ) . severe ( "[Hook] CoreData not found. Disabling plugin..." ) ;
            return ;
        }
        this . coreDataUserHandler = ( ( com. ethanpritchard . data . Main ) this . getServer ( ) . getPluginManager ( ) . getPlugin ( "CoreData" ) ) . getUserHandler ( ) ;
}

public void transferToCoreData ( ) {
    // Establish a data label
    String label = "myPlugin.tokenbalance" ;
 
    // Get the user data
    Map < UUID, Double > balances = this . getUserBalance ( ) ;
 
    // Iterate over the user data
    for ( UUID uuid : balances. keySet ( ) ) {
        // Get the user's data
        double data = balances. get ( uuid ) ;
 
        // Call the CoreData method
        this . coreDataUserHandler . set ( uuid, label, data ) ;
    }
}
Plugins that use CoreData
CorePoints - A simple alternative currency plugin
CorePlaytime - The best plugin for rewarding players for playing!
Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

[1.8-1.14] CoreData - A lightweight, centralized data solution for your plugins! is a free Minecraft Java mod. Compatible with Minecraft 1.7, 1.8, 1.9, 1.10 and newer. Downloaded 775 times (via Spigot). Download it and open it directly in the game.

Explore more