issue fix backport
This commit is contained in:
parent
d16e42c505
commit
226bc39185
|
|
@ -3,4 +3,4 @@
|
||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
|
||||||
mod_version=1.18.2-1.2.1
|
mod_version=1.18.2-1.3.2
|
||||||
|
|
@ -14,6 +14,7 @@ public class JdbcConfig {
|
||||||
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;
|
||||||
|
public static ForgeConfigSpec.ConfigValue<String> DATABASE_NAME;
|
||||||
public static ForgeConfigSpec.ConfigValue<List<String>> SYNC_WORLD;
|
public static ForgeConfigSpec.ConfigValue<List<String>> SYNC_WORLD;
|
||||||
public static ForgeConfigSpec.BooleanValue USE_SSL;
|
public static ForgeConfigSpec.BooleanValue USE_SSL;
|
||||||
public static ForgeConfigSpec.BooleanValue SYNC_CHAT;
|
public static ForgeConfigSpec.BooleanValue SYNC_CHAT;
|
||||||
|
|
@ -29,6 +30,7 @@ public class JdbcConfig {
|
||||||
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");
|
||||||
PASSWORD = COMMON_BUILDER.comment("password").define("password", "password");
|
PASSWORD = COMMON_BUILDER.comment("password").define("password", "password");
|
||||||
|
DATABASE_NAME = COMMON_BUILDER.comment("database name").define("db_name","playersync");
|
||||||
SERVER_ID = COMMON_BUILDER.comment("the server id should be unique").define("Server_id", new Random().nextInt(1,Integer.MAX_VALUE-1));
|
SERVER_ID = COMMON_BUILDER.comment("the server id should be unique").define("Server_id", new Random().nextInt(1,Integer.MAX_VALUE-1));
|
||||||
SYNC_WORLD = COMMON_BUILDER.comment("The worlds that will be synchronized.If running in server it is supposed to have only one").define("sync_world", new ArrayList<>());
|
SYNC_WORLD = COMMON_BUILDER.comment("The worlds that will be synchronized.If running in server it is supposed to have only one").define("sync_world", new ArrayList<>());
|
||||||
SYNC_CHAT= COMMON_BUILDER.comment("Whether synchronize chat").define("sync_chat", true);
|
SYNC_CHAT= COMMON_BUILDER.comment("Whether synchronize chat").define("sync_chat", true);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import vip.fubuki.playersync.util.JDBCsetUp;
|
import vip.fubuki.playersync.util.JDBCsetUp;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
@ -25,7 +27,14 @@ public class ChatSync {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onPlayerChat(net.minecraftforge.event.ServerChatEvent event) throws SQLException {
|
public static void onPlayerChat(net.minecraftforge.event.ServerChatEvent event) throws SQLException {
|
||||||
JDBCsetUp.executeUpdate("INSERT INTO chat (player, message, timestamp) VALUES ('" + event.getUsername() + "', '" + event.getMessage() + "', '" + current + "')");
|
String sql = "INSERT INTO chat (player, message, timestamp) VALUES (?, ?, ?)";
|
||||||
|
try (Connection connection = JDBCsetUp.getConnection();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||||
|
preparedStatement.setString(1, event.getUsername());
|
||||||
|
preparedStatement.setString(2, event.getMessage());
|
||||||
|
preparedStatement.setLong(3, current);
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ 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`");
|
PreparedStatement useStatement = connection.prepareStatement("USE "+JdbcConfig.DATABASE_NAME.get());
|
||||||
useStatement.executeUpdate();
|
useStatement.executeUpdate();
|
||||||
|
|
||||||
PreparedStatement queryStatement = connection.prepareStatement(sql);
|
PreparedStatement queryStatement = connection.prepareStatement(sql);
|
||||||
|
|
@ -25,7 +25,7 @@ public class JDBCsetUp {
|
||||||
public static int executeUpdate(String sql) throws SQLException{
|
public static int executeUpdate(String sql) throws SQLException{
|
||||||
try (Connection connection = getConnection()) {
|
try (Connection connection = getConnection()) {
|
||||||
|
|
||||||
PreparedStatement useStatement = connection.prepareStatement("USE `playersync`");
|
PreparedStatement useStatement = connection.prepareStatement("USE "+JdbcConfig.DATABASE_NAME.get());
|
||||||
useStatement.executeUpdate();
|
useStatement.executeUpdate();
|
||||||
|
|
||||||
try (PreparedStatement updateStatement = connection.prepareStatement(sql)) {
|
try (PreparedStatement updateStatement = connection.prepareStatement(sql)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user