diff --git a/src/main/java/vip/fubuki/playersync/PlayerSync.java b/src/main/java/vip/fubuki/playersync/PlayerSync.java index 520bf08..daf185a 100644 --- a/src/main/java/vip/fubuki/playersync/PlayerSync.java +++ b/src/main/java/vip/fubuki/playersync/PlayerSync.java @@ -59,8 +59,6 @@ public void onServerStarting(ServerStartingEvent event) throws SQLException { `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(""" CREATE TABLE IF NOT EXISTS server_info ( `id` INT NOT NULL, diff --git a/src/main/java/vip/fubuki/playersync/sync/ModsSupport.java b/src/main/java/vip/fubuki/playersync/sync/ModsSupport.java index 4b0f3ed..8ed4de8 100644 --- a/src/main/java/vip/fubuki/playersync/sync/ModsSupport.java +++ b/src/main/java/vip/fubuki/playersync/sync/ModsSupport.java @@ -25,7 +25,7 @@ public void onPlayerJoin(Player player) throws SQLException { */ LazyOptional itemHandler = top.theillusivec4.curios.api.CuriosApi.getCuriosHelper().getEquippedCurios(player); JDBCsetUp.QueryResult queryResult=JDBCsetUp.executeQuery("SELECT curios_item FROM curios WHERE uuid = '"+player.getUUID()+"'"); - ResultSet resultSet = queryResult.getResultSet(); + ResultSet resultSet = queryResult.resultSet(); if(resultSet.next()) { String curios_data=resultSet.getString("curios_item"); if(curios_data.length()>2) { @@ -42,7 +42,7 @@ public void onPlayerJoin(Player player) throws SQLException { }); } resultSet.close(); - queryResult.getConnection().close(); + queryResult.connection().close(); }else{ StoreCurios(player,true); } diff --git a/src/main/java/vip/fubuki/playersync/sync/VanillaSync.java b/src/main/java/vip/fubuki/playersync/sync/VanillaSync.java index b2aa20f..23686cb 100644 --- a/src/main/java/vip/fubuki/playersync/sync/VanillaSync.java +++ b/src/main/java/vip/fubuki/playersync/sync/VanillaSync.java @@ -42,7 +42,7 @@ public static void register(){} public static void doPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) throws SQLException, CommandSyntaxException, IOException { String player_uuid = event.getEntity().getUUID().toString(); JDBCsetUp.QueryResult queryResult=JDBCsetUp.executeQuery("SELECT online, last_server FROM player_data WHERE uuid='"+player_uuid+"'"); - ResultSet resultSet=queryResult.getResultSet(); + ResultSet resultSet=queryResult.resultSet(); ServerPlayer serverPlayer = (ServerPlayer) event.getEntity(); if(!resultSet.next()){ Store(event.getPlayer(),true,Dist.CLIENT.isDedicatedServer()); @@ -51,11 +51,11 @@ public static void doPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) throws SQ boolean online = resultSet.getBoolean("online"); int lastServer = resultSet.getInt("last_server"); queryResult=JDBCsetUp.executeQuery("SELECT * FROM player_data WHERE uuid='"+player_uuid+"'"); - resultSet= queryResult.getResultSet(); + resultSet= queryResult.resultSet(); if(online) { queryResult=JDBCsetUp.executeQuery("SELECT last_update,enable FROM server_info WHERE id='"+lastServer+"'"); - ResultSet getServerInfo = queryResult.getResultSet(); + ResultSet getServerInfo = queryResult.resultSet(); if(getServerInfo.next()){ long last_update = getServerInfo.getLong("last_update"); boolean enable = getServerInfo.getBoolean("enable"); diff --git a/src/main/java/vip/fubuki/playersync/util/JDBCsetUp.java b/src/main/java/vip/fubuki/playersync/util/JDBCsetUp.java index 14a53c1..d313227 100644 --- a/src/main/java/vip/fubuki/playersync/util/JDBCsetUp.java +++ b/src/main/java/vip/fubuki/playersync/util/JDBCsetUp.java @@ -1,5 +1,9 @@ package vip.fubuki.playersync.util; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.TranslatableComponent; +import org.lwjgl.system.CallbackI; import vip.fubuki.playersync.config.JdbcConfig; import java.sql.*; @@ -13,7 +17,7 @@ public static Connection getConnection() throws SQLException { } public static QueryResult executeQuery(String sql) throws SQLException{ - Connection connection = getConnection(); + Connection connection = getConnection(); PreparedStatement useStatement = connection.prepareStatement("USE ?"); useStatement.setString(1, JdbcConfig.DATABASE_NAME.get()); useStatement.executeUpdate(); @@ -23,7 +27,7 @@ public static QueryResult executeQuery(String sql) throws SQLException{ return new QueryResult(connection,resultSet); } - public static int executeUpdate(String sql) throws SQLException{ + public static void executeUpdate(String sql) throws SQLException{ try (Connection connection = getConnection()) { PreparedStatement useStatement = connection.prepareStatement("USE ?"); @@ -31,35 +35,34 @@ public static int executeUpdate(String sql) throws SQLException{ useStatement.executeUpdate(); try (PreparedStatement updateStatement = connection.prepareStatement(sql)) { - return updateStatement.executeUpdate(); + updateStatement.executeUpdate(); } } } - public static int executeUpdate(String sql,int i) throws SQLException{ + public static void Update(String sql, String... argument) throws SQLException{ + Connection connection = getConnection(); + + PreparedStatement useStatement = connection.prepareStatement("USE ?"); + useStatement.setString(1, JdbcConfig.DATABASE_NAME.get()); + useStatement.executeUpdate(); + + PreparedStatement updateStatement = connection.prepareStatement(sql); + for (int i = 1; i <= argument.length; i++) { + updateStatement.setString(i,argument[i]); + } + updateStatement.executeUpdate(); + } + + public static void executeUpdate(String sql, int i) throws SQLException{ try (Connection connection = getConnection()) { try (PreparedStatement updateStatement = connection.prepareStatement(sql)) { - return updateStatement.executeUpdate(); + updateStatement.executeUpdate(); } } } - public static class QueryResult{ - private final Connection connection; - private final ResultSet resultSet; - - public QueryResult(Connection connection, ResultSet resultSet) { - this.connection = connection; - this.resultSet = resultSet; - } - - public Connection getConnection() { - return connection; - } - - public ResultSet getResultSet() { - return resultSet; - } + public record QueryResult(Connection connection, ResultSet resultSet) { } }