Skip to content

Commit

Permalink
remove unused table
Browse files Browse the repository at this point in the history
  • Loading branch information
mlus-asuka committed Aug 4, 2024
1 parent 5666f79 commit b9f4736
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
2 changes: 0 additions & 2 deletions src/main/java/vip/fubuki/playersync/PlayerSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/vip/fubuki/playersync/sync/ModsSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onPlayerJoin(Player player) throws SQLException {
*/
LazyOptional<IItemHandlerModifiable> 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) {
Expand All @@ -42,7 +42,7 @@ public void onPlayerJoin(Player player) throws SQLException {
});
}
resultSet.close();
queryResult.getConnection().close();
queryResult.connection().close();
}else{
StoreCurios(player,true);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/vip/fubuki/playersync/sync/VanillaSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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");
Expand Down
45 changes: 24 additions & 21 deletions src/main/java/vip/fubuki/playersync/util/JDBCsetUp.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -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();
Expand All @@ -23,43 +27,42 @@ 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 ?");
useStatement.setString(1, JdbcConfig.DATABASE_NAME.get());
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) {
}
}

0 comments on commit b9f4736

Please sign in to comment.