1.3.0 update

This commit is contained in:
mlus 2024-02-11 17:29:47 +08:00
parent 3c64bf81fd
commit 7970c87e37
4 changed files with 32 additions and 18 deletions

View File

@ -3,4 +3,4 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
mod_version=1.19.2-1.2.1
mod_version=1.19.2-1.3.0

View File

@ -41,11 +41,24 @@ public class PlayerSync
@SubscribeEvent
public void onServerStarting(ServerStartingEvent event) throws SQLException {
JDBCsetUp.executeUpdate("CREATE DATABASE IF NOT EXISTS "+JdbcConfig.DATABASE_NAME.get(),1);
JDBCsetUp.executeUpdate("CREATE DATABASE IF NOT EXISTS `playersync`",1);
JDBCsetUp.executeUpdate("CREATE TABLE IF NOT EXISTS player_data (uuid CHAR(36) NOT NULL," +
"inventory MEDIUMBLOB,armor BLOB,advancements BLOB,enderchest MEDIUMBLOB,effects BLOB," +
"xp int,food_level int,score int,health int,online boolean, last_server int, PRIMARY KEY (uuid))");
JDBCsetUp.executeUpdate("""
CREATE TABLE IF NOT EXISTS `player_data` (
`uuid` char(36) NOT NULL,
`inventory` mediumblob,
`armor` blob,
`advancements` blob,
`enderchest` mediumblob,
`effects` blob,
`xp` int DEFAULT NULL,
`food_level` int DEFAULT NULL,
`score` int DEFAULT NULL,
`health` int DEFAULT NULL,
`online` tinyint(1) DEFAULT NULL,
`last_server` int DEFAULT NULL,
PRIMARY KEY (`uuid`)
);""");
JDBCsetUp.executeUpdate("CREATE TABLE IF NOT EXISTS chat (player CHAR(36) NOT NULL,message TEXT," +
"timestamp BIGINT)");
JDBCsetUp.executeUpdate("""

View File

@ -11,7 +11,6 @@ import java.util.Random;
public class JdbcConfig {
public static ForgeConfigSpec COMMON_CONFIG;
public static ForgeConfigSpec.ConfigValue<String> HOST;
public static ForgeConfigSpec.ConfigValue<String> DATABASE_NAME;
public static ForgeConfigSpec.IntValue PORT;
public static ForgeConfigSpec.ConfigValue<String> USERNAME;
public static ForgeConfigSpec.ConfigValue<String> PASSWORD;
@ -26,7 +25,6 @@ public class JdbcConfig {
ForgeConfigSpec.Builder COMMON_BUILDER = new ForgeConfigSpec.Builder();
COMMON_BUILDER.comment("General settings").push("general");
HOST=COMMON_BUILDER.comment("The host of the database").define("host", "localhost");
DATABASE_NAME= COMMON_BUILDER.comment("Database name").define("database_name", "playersync");
PORT = COMMON_BUILDER.comment("database port").defineInRange("db_port", 3306, 0, 65535);
USE_SSL = COMMON_BUILDER.comment("whether use SSL").define("use_ssl", false);
USERNAME = COMMON_BUILDER.comment("username").define("user_name", "root");

View File

@ -14,25 +14,28 @@ public class JDBCsetUp {
public static QueryResult executeQuery(String sql) throws SQLException{
Connection connection = getConnection();
PreparedStatement useStatement = connection.prepareStatement("USE `playersync`");
useStatement.executeUpdate();
PreparedStatement useStatement = connection.prepareStatement("USE " + JdbcConfig.DATABASE_NAME.get());
useStatement.executeUpdate();
PreparedStatement queryStatement = connection.prepareStatement(sql);
ResultSet resultSet =queryStatement.executeQuery();
PreparedStatement queryStatement = connection.prepareStatement(sql);
ResultSet resultSet = queryStatement.executeQuery();
return new QueryResult(connection,resultSet);
}
public static int executeUpdate(String sql) throws SQLException{
return executeUpdate(sql,0);
}
public static int executeUpdate(String sql,int init) throws SQLException{
try (Connection connection = getConnection()) {
if(init==0){
sql="USE " + JdbcConfig.DATABASE_NAME.get() +";" + sql;
PreparedStatement useStatement = connection.prepareStatement("USE `playersync`");
useStatement.executeUpdate();
try (PreparedStatement updateStatement = connection.prepareStatement(sql)) {
return updateStatement.executeUpdate();
}
}
}
public static int executeUpdate(String sql,int i) throws SQLException{
try (Connection connection = getConnection()) {
try (PreparedStatement updateStatement = connection.prepareStatement(sql)) {
return updateStatement.executeUpdate();