Skip to content

Developer PlayerData

ludgart edited this page May 29, 2021 · 11 revisions

Developer PlayerData

The PlayerData is a powerful tool. With the functionality you can very easily read and write player data from the storage.

There are some procedures:

  • Get
  • Set
  • Insert
  • Delete
  • ...

How does it work?

The server owner can configure in the configration file, which storage system he want to use.

Storage options:

  • SQL
  • MySQL

To improve the performance is it possible to setup a internal memory cache system or a external cache system with redis.
Calling, example the .get() method from the PlayerData, it load automatic in background (SQL or MySQL) the requested data. No SQL knowledge required!

The structure:
PlayerData -> DatabaseHelper -> DatabaseInterface

It is always possible to switch between SQL and MySQL.

Synchron and Asynchron

The API work mainly only asynchron. It is not recommended to use it synchron.
Every response from the PlayerData give you the object CompletableFuture back. That mean, you have still the possibility to work synchron.

How I can implement my own data?

Before we can start there is one thing we need to consider.
The API must be able work with single and multplie servers (network).

It is advisable, to implement following into the configartion file:

MY_CONFIG.set("config.global", true, "0.0.1");

Create preferably in your Main class a method like verifyDatabase() to support multiple servers, we need to add following code:

if (MY_CONFIG.getBool("config.global")) {
  MY_DATABASE_TABLE = "player_my_table";
} else {
  MY_DATABASE_TABLE = "player_my_table_" + StorageManager.getServerName();
}

Now we can start with the table and the columns creation.
This part require SQL knowledge, but there a thousand of online tools to create the table query.

Create table

String createTable = "CREATE TABLE IF NOT EXISTS `" + MY_DATABASE_TABLE + "` (`player_uuid` varchar(36) NOT NULL,`my_column` varchar(36) NOT NULL, FOREIGN KEY (player_uuid) REFERENCES player (uuid) ON DELETE CASCADE);";

Now we need to execute the createTable query. Dont forget to implement the method verifyDatabase() on startup!

if (StorageManager.isMySQL()) {
  assert StorageManager.getMySQLDatabase() != null : "Create table failed.";
  StorageManager.getMySQLDatabase().createTable(createTable);
  return;
}

assert StorageManager.getSQLiteDatabase() != null : "Create table failed.";
StorageManager.getSQLiteDatabase().createTable(createTable);

After the successful setup, you can continue with PlayerData Get tutorial.

Information

Server Owner

Developer

Clone this wiki locally