ModsJava
CRUDStorage
Java mod listed for Minecraft 1.7–1.14. Downloads from the MC Java Mods app on Android.
⬇ Download on Spigot
CRUD Storage
You could opt for a SQL database, and YAML files for data, but it can be difficult to design and to build SQL queries, modularize it and make it independant.
This library is designed to be a common proxy to all possibles storage methods of your plugin's data. It offers also a basic implementation in MySQL. You can use it without using any SQL language, regardless the creation of the database itself (that is in most cases not made by the authors of the plugins).
After that, you can modularize it and change conveniently your method of storage without touching your core plugin code.
You could also use it to manage your settings conveniently., but it's primary designed for mass data.
Quick walkthrough:
You must first choose one method of storage. The only avalaible storage builtin method is MySQL. It store data by a ORM api (object-relational mapping). Each field of the class represent one column in the database, and each instance of your class will represent one line in the database. You will need a model-Class made of basic data types.
It's easy-to-use, you need only, at least, 2 classes and even if there a little bit of code, it's mainly boilerplate and search-and-replace classes.
You will need at least
- an "ID" field for this storage method (as known as primary key or pk in database words) that will be unique.
- an empty constructor
- an "ID" constructor
1) Create a plain Model Class:
Spoiler: Java
public class PlayerData { // Example data
private int id ; // Needed +
private int level ; // Example
public PlayerData ( ) { } // Needed
public PlayerData ( int id ) { this. id = id ; } // Needed
public int getLevel ( ) { return level ; }
public void setLevel ( int level ) { this. level = level ; }
public int getId ( ) { return id ; }
public void setId ( int id ) { this. id = id ; }
}
Code (Java):
public class PlayerData { // Example data
private int id ; // Needed +
private int level ; // Example
public PlayerData ( ) { } // Needed
public PlayerData ( int id ) { this. id = id ; } // Needed
public int getLevel ( ) { return level ; }
public void setLevel ( int level ) { this. level = level ; }
public int getId ( ) { return id ; }
public void setId ( int id ) { this. id = id ; }
}
2) Inherit BeanCRUDful<PlayerData> and override these methods as this:
Spoiler: Java
import net.rafoudiablol.api.crud.sql.BeanCRUDful ;
import org.mentabean.BeanConfig ;
import org.mentabean.DBTypes ;
import java.util.List ;
public class SampleCRUDful extends BeanCRUDful <PlayerData > {
@Override
protected PlayerData createInstance ( int id ) {
return new PlayerData (id ) ;
}
@Override
protected void loadConfig (List <BeanConfig > configs ) {
BeanConfig config = new BeanConfig (PlayerData. class, table ) ;
config. pk ( "id", DBTypes. AUTOINCREMENT ) ;
config. field ( "level", DBTypes. INTEGER ) ;
configs. add (config ) ;
}
}
Code (Java):
import net.rafoudiablol.api.crud.sql.BeanCRUDful ;
import org.mentabean.BeanConfig ;
import org.mentabean.DBTypes ;
import java.util.List ;
public class SampleCRUDful extends BeanCRUDful <PlayerData > {
@Override
protected PlayerData createInstance ( int id ) {
return new PlayerData (id ) ;
}
@Override
protected void loadConfig (List <BeanConfig > configs ) {
BeanConfig config = new BeanConfig (PlayerData. class, table ) ;
config. pk ( "id", DBTypes. AUTOINCREMENT ) ;
config. field ( "level", DBTypes. INTEGER ) ;
configs. add (config ) ;
}
}
You will call the methods pk() to select primary key name and field() to add a field inside your database. Important: To each field, the must be the appropriate getters and setters inside your class ! According to java convention, get/set prefix and first letter as uppercase in cameCase. It allow advanced modification because the changes are not directly injected into the fields but made by function calls.
table is the name of the table where the data is stored inside the database. If you only must store a Datatype, the field table contains then name passed by the method open().
The createInstance() method should be always the same (in exception of the return type).
3) Geta connection instance. You will need an URL, and maybe a login and a password, and then instanciate your class, and next open a connection.
Code (Java):
SampleCRUDful storage
=
new SampleCRUDful
(
)
;
You can use it and automatically create the table if it not already exists.
Spoiler: Java
It doesn't seems like, but these statements manipulates and affects the database through the easy API.
Code (Java):
SampleCRUDful storage
=
new SampleCRUDful
(
)
;
storage. open ( DriverManager. getConnection (url, login, password ), "mytablename" ) ;
storage. createTables ( ) ;
PlayerData data = storage. create ( ) ; // INSERT inside the database
data. setLevel ( 3 ) ;
storage. update (data ) ; // UPDATE inside the database
storage. delete (data. getId ( ) ) ; // DELETE from the database
// Search all players that have level 3
// You can define a method inside your Storage Class
List <PlayerData > players = storage. search ( "level", 3 ) ;
// Other example: Search a players from UUID...
storage. open ( DriverManager. getConnection (url, login, password ), "mytablename" ) ;
storage. createTables ( ) ;
PlayerData data = storage. create ( ) ; // INSERT inside the database
data. setLevel ( 3 ) ;
storage. update (data ) ; // UPDATE inside the database
storage. delete (data. getId ( ) ) ; // DELETE from the database
// Search all players that have level 3
// You can define a method inside your Storage Class
List <PlayerData > players = storage. search ( "level", 3 ) ;
// Other example: Search a players from UUID...
How to implement a new Storage Method:
Inherit from CRUDful<>. You may inherit with a specific type, for a specific need. You can also inherit with genericity and provide an interface for write/read or use Reflection to get dynamially the fields, but it's maybe not the best choice. It is basically very abstract.
Spoiler: Java
The Common Proxy Interface is made only by this CRUD iterface. It's the core of the library.
Code (Text):
package net.rafoudiablol.api.crud;
public interface CRUDful<T> {
T create();
T read(int id);
void update(T object);
void delete(int id);
String VERSION = "1.1";
}
public interface CRUDful<T> {
T create();
T read(int id);
void update(T object);
void delete(int id);
String VERSION = "1.1";
}
If the data is designed to be sorted (to be said a ranking system or a queue), you can inherit instead from SortedCRUDful<> that offer plus 2 methods: position(int id) to read the position of an object and read(int min, int max) to read all data from position min (included) to position max (excluded).
Feature:
This library provide also an implementation for MySQL database.
For more information and documentation, visit https://github.com/saoj/mentabean
Compatibility with Spigot version:
This library has no dependencies to Spigot, it can works on normal Java application. It means that this library can work with (under reserve of Java and libs compatibility) any version of your server, and does not need to be updated when a new version of Spigot is released.
Dependencies:(included)
mentabean, Simple ORM and Query Builder (slightly modified version)
https://github.com/saoj/mentabean
Quick facts
- Edition: Minecraft Java
- File type: .jar
- Minecraft versions listed: 1.7, 1.8, 1.9
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.
CRUDStorage is a free Minecraft Java mod. Compatible with Minecraft 1.7, 1.8, 1.9, 1.10 and newer. Downloaded 140 times (via Spigot). Download it and open it directly in the game.