ModsJava
MySQL Manager
Minecraft Java mod. Downloads from the MC Java Mods app on Android.
⬇ Download on SpigotWell essentially I didn't want to keep having to implement MySQL within each of my plugins, so with the help of a guide by insou I made this plugin which uses data connection pools to make a very nice MySQL environment. Honestly do lazy to explain all the features so I will post an example for now.
Server Owners:
If you are coming here from my other plugins, just drag and drop this plugin into your plugins folder and enable MySQL (fill out info) in the plugin you came from!
Developers:
Essentially most of it should be self explanatory. All you have to do is extend the MySQLUtil class and fill out the constructor. As of version 1.0 it will outprint every query you make to the database, but once it updates it will no longer do that.
I haven't actually tested the code below, but the gist of what it does is here below. It should work and if you have any questions feel free to post.
You need to register the MySQL information via the method method.
Code (Text):
public void initMySQL(){
String hostname, port, database, username, password;
hostname = getConfig().getString("MySQL.Hostname");
port = getConfig().getString("MySQL.Port");
database = getConfig().getString("MySQL.Database");
username = getConfig().getString("MySQL.Username");
password = getConfig().getString("MySQL.Password");
MySQLManager.i.updateConnectionInfo(hostname,port,database,username,password); //Updates the connection information and reloads the connections
testRepo= new TestMySQL(); //Means MySQL is enabled and we can go through with it
}
String hostname, port, database, username, password;
hostname = getConfig().getString("MySQL.Hostname");
port = getConfig().getString("MySQL.Port");
database = getConfig().getString("MySQL.Database");
username = getConfig().getString("MySQL.Username");
password = getConfig().getString("MySQL.Password");
MySQLManager.i.updateConnectionInfo(hostname,port,database,username,password); //Updates the connection information and reloads the connections
testRepo= new TestMySQL(); //Means MySQL is enabled and we can go through with it
}
Code (Text):
import us.siglerdev.sigler.MySQLUtil;
import java.sql.Connection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
public class TestMySQL extends MySQLUtil {
public TestMySQL(){
tableName = "db_test"; //The database 's table name
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
map.put("player_uuid", "varchar(40),"); //Create a column that is called player_uuid with varchar type
map.put("elo", "INT"); //Create a column that is called ELO with INT type
makeTable(map); //This will try and create the table if it does NOT exist.
}
public void setPlayerElo(UUID id, int value){
runStatement("INSERT INTO " + tableName + " (player_uuid,elo) VALUES (?,?) ON DUPLICATE KEY UPDATE elo = ?", id.toString(),value,value);
}
public void removePlayerElo(UUID id){
runStatement("DELETE FROM " + tableName + " WHERE `player_uuid` = ?", id.toString());
}
public int getElo(UUID id){
List<Object> vals = queryDatabase("SELECT `elo` FROM " + tableName + " WHERE `player_uuid` = ?", id.toString());
if (vals != null){ //It returns null if nothing was found
return (int) vals.get(0);
}else
return 0; //The player doesn't have an ELO value.
}
public Connection getConnection(){
return getOriginalConnection();
}
}
import java.sql.Connection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
public class TestMySQL extends MySQLUtil {
public TestMySQL(){
tableName = "db_test"; //The database 's table name
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
map.put("player_uuid", "varchar(40),"); //Create a column that is called player_uuid with varchar type
map.put("elo", "INT"); //Create a column that is called ELO with INT type
makeTable(map); //This will try and create the table if it does NOT exist.
}
public void setPlayerElo(UUID id, int value){
runStatement("INSERT INTO " + tableName + " (player_uuid,elo) VALUES (?,?) ON DUPLICATE KEY UPDATE elo = ?", id.toString(),value,value);
}
public void removePlayerElo(UUID id){
runStatement("DELETE FROM " + tableName + " WHERE `player_uuid` = ?", id.toString());
}
public int getElo(UUID id){
List<Object> vals = queryDatabase("SELECT `elo` FROM " + tableName + " WHERE `player_uuid` = ?", id.toString());
if (vals != null){ //It returns null if nothing was found
return (int) vals.get(0);
}else
return 0; //The player doesn't have an ELO value.
}
public Connection getConnection(){
return getOriginalConnection();
}
}
Quick facts
- Edition: Minecraft Java
- File type: .jar
- 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.
MySQL Manager is a free Minecraft Java mod. Downloaded 513 times (via Spigot). Download it and open it directly in the game.