1.3.0 update

This commit is contained in:
mlus 2024-02-11 17:34:19 +08:00
parent da99e59d0a
commit b3352fde51
4 changed files with 32 additions and 18 deletions

View File

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

View File

@ -41,11 +41,24 @@ public class PlayerSync
@SubscribeEvent @SubscribeEvent
public void onServerStarting(ServerStartingEvent event) throws SQLException { 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," + JDBCsetUp.executeUpdate("""
"inventory MEDIUMBLOB,armor BLOB,advancements BLOB,enderchest MEDIUMBLOB,effects BLOB," + CREATE TABLE IF NOT EXISTS `player_data` (
"xp int,food_level int,score int,health int,online boolean, last_server int, PRIMARY KEY (uuid))"); `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," + JDBCsetUp.executeUpdate("CREATE TABLE IF NOT EXISTS chat (player CHAR(36) NOT NULL,message TEXT," +
"timestamp BIGINT)"); "timestamp BIGINT)");
JDBCsetUp.executeUpdate(""" JDBCsetUp.executeUpdate("""

View File

@ -11,7 +11,6 @@ import java.util.Random;
public class JdbcConfig { public class JdbcConfig {
public static ForgeConfigSpec COMMON_CONFIG; public static ForgeConfigSpec COMMON_CONFIG;
public static ForgeConfigSpec.ConfigValue<String> HOST; public static ForgeConfigSpec.ConfigValue<String> HOST;
public static ForgeConfigSpec.ConfigValue<String> DATABASE_NAME;
public static ForgeConfigSpec.IntValue PORT; public static ForgeConfigSpec.IntValue PORT;
public static ForgeConfigSpec.ConfigValue<String> USERNAME; public static ForgeConfigSpec.ConfigValue<String> USERNAME;
public static ForgeConfigSpec.ConfigValue<String> PASSWORD; public static ForgeConfigSpec.ConfigValue<String> PASSWORD;
@ -26,7 +25,6 @@ public class JdbcConfig {
ForgeConfigSpec.Builder COMMON_BUILDER = new ForgeConfigSpec.Builder(); ForgeConfigSpec.Builder COMMON_BUILDER = new ForgeConfigSpec.Builder();
COMMON_BUILDER.comment("General settings").push("general"); COMMON_BUILDER.comment("General settings").push("general");
HOST=COMMON_BUILDER.comment("The host of the database").define("host", "localhost"); 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); PORT = COMMON_BUILDER.comment("database port").defineInRange("db_port", 3306, 0, 65535);
USE_SSL = COMMON_BUILDER.comment("whether use SSL").define("use_ssl", false); USE_SSL = COMMON_BUILDER.comment("whether use SSL").define("use_ssl", false);
USERNAME = COMMON_BUILDER.comment("username").define("user_name", "root"); 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{ public static QueryResult executeQuery(String sql) throws SQLException{
Connection connection = getConnection(); Connection connection = getConnection();
PreparedStatement useStatement = connection.prepareStatement("USE `playersync`");
useStatement.executeUpdate();
PreparedStatement useStatement = connection.prepareStatement("USE " + JdbcConfig.DATABASE_NAME.get()); PreparedStatement queryStatement = connection.prepareStatement(sql);
useStatement.executeUpdate(); ResultSet resultSet = queryStatement.executeQuery();
PreparedStatement queryStatement = connection.prepareStatement(sql);
ResultSet resultSet =queryStatement.executeQuery();
return new QueryResult(connection,resultSet); return new QueryResult(connection,resultSet);
} }
public static int executeUpdate(String sql) throws SQLException{ 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()) { try (Connection connection = getConnection()) {
if(init==0){ PreparedStatement useStatement = connection.prepareStatement("USE `playersync`");
sql="USE " + JdbcConfig.DATABASE_NAME.get() +";" + sql; 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)) { try (PreparedStatement updateStatement = connection.prepareStatement(sql)) {
return updateStatement.executeUpdate(); return updateStatement.executeUpdate();