for cat server
This commit is contained in:
parent
2e3694d7cb
commit
079ccb4c09
|
|
@ -12,6 +12,7 @@ import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import vip.fubuki.playersync.util.JDBCsetUp;
|
import vip.fubuki.playersync.util.JDBCsetUp;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
|
@ -24,7 +25,11 @@ public abstract class MixinPlayerProgress {
|
||||||
tag.putBoolean("PlayerSync",false);
|
tag.putBoolean("PlayerSync",false);
|
||||||
String nbt = tag.toString().replace(",","|").replace("\"","^").replace("{","<").replace("}",">").replace("'","~");
|
String nbt = tag.toString().replace(",","|").replace("\"","^").replace("{","<").replace("}",">").replace("'","~");
|
||||||
try {
|
try {
|
||||||
JDBCsetUp.executeUpdate("INSERT INTO AstralSorcery(player,tag) VALUES('" + tag.getString("UUID") + "','" + nbt + "') ON DUPLICATE KEY UPDATE tag='" + tag + "';");
|
PreparedStatement preparedStatement= JDBCsetUp.getConnection().prepareStatement("INSERT INTO AstralSorcery(player,tag) VALUES(?,?) ON DUPLICATE KEY UPDATE player=?");
|
||||||
|
preparedStatement.setString(1,tag.getString("UUID"));
|
||||||
|
preparedStatement.setString(2,nbt);
|
||||||
|
preparedStatement.setString(3,tag.getString("UUID"));
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
} catch (SQLException throwable) {
|
} catch (SQLException throwable) {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -34,12 +39,13 @@ public abstract class MixinPlayerProgress {
|
||||||
@Inject(method = "load",at=@At(value="HEAD"), cancellable = true)
|
@Inject(method = "load",at=@At(value="HEAD"), cancellable = true)
|
||||||
private void load(CompoundNBT compound, CallbackInfo ci){
|
private void load(CompoundNBT compound, CallbackInfo ci){
|
||||||
if(compound.get("PlayerSync")==null || !compound.getBoolean("PlayerSync")){
|
if(compound.get("PlayerSync")==null || !compound.getBoolean("PlayerSync")){
|
||||||
compound.putBoolean("PlayerSync",true);
|
|
||||||
try {
|
try {
|
||||||
ResultSet result= JDBCsetUp.executeQuery("SELECT * FROM AstralSorcery WHERE player='" + compound.getString("UUID") + "';").getResultSet();
|
ResultSet result= JDBCsetUp.executeQuery("SELECT * FROM AstralSorcery WHERE player='" + compound.getString("UUID") + "';").getResultSet();
|
||||||
if(result.next()){
|
if(result.next()){
|
||||||
String nbt = result.getString("tag").replace("|",",").replace("^","\"").replace("<","{").replace(">","}").replace("~", "'");
|
String nbt = result.getString("tag").replace("|",",").replace("^","\"").replace("<","{").replace(">","}").replace("~", "'");
|
||||||
load(JsonToNBT.parseTag(nbt));
|
compound=JsonToNBT.parseTag(nbt);
|
||||||
|
compound.putBoolean("PlayerSync",true);
|
||||||
|
load(compound);
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch (SQLException e){
|
}catch (SQLException e){
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,27 @@
|
||||||
package vip.fubuki.playersync.util;
|
package vip.fubuki.playersync.util;
|
||||||
|
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
||||||
import vip.fubuki.playersync.config.JdbcConfig;
|
import vip.fubuki.playersync.config.JdbcConfig;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
public class JDBCsetUp {
|
public class JDBCsetUp {
|
||||||
|
|
||||||
public static Connection getConnection() throws SQLException {
|
public static Connection getConnection() throws SQLException {
|
||||||
String url= "jdbc:mysql://"+JdbcConfig.HOST.get()+":"+JdbcConfig.PORT.get()+"?useUnicode=true&characterEncoding=utf-8&useSSL="+JdbcConfig.USE_SSL.get()+"&serverTimezone=UTC&allowPublicKeyRetrieval=true";
|
String url= "jdbc:mysql://"+JdbcConfig.HOST.get()+":"+JdbcConfig.PORT.get()+"/playersync?useUnicode=true&characterEncoding=utf-8&useSSL="+JdbcConfig.USE_SSL.get()+"&serverTimezone=UTC&allowPublicKeyRetrieval=true";
|
||||||
return DriverManager.getConnection(url, JdbcConfig.USERNAME.get(), JdbcConfig.PASSWORD.get());
|
return DriverManager.getConnection(url, JdbcConfig.USERNAME.get(), JdbcConfig.PASSWORD.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
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 queryStatement = connection.prepareStatement(sql);
|
PreparedStatement queryStatement = connection.prepareStatement(sql);
|
||||||
ResultSet resultSet =queryStatement.executeQuery();
|
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){
|
|
||||||
sql="USE playersync;" + sql;
|
|
||||||
}
|
|
||||||
|
|
||||||
try (PreparedStatement updateStatement = connection.prepareStatement(sql)) {
|
try (PreparedStatement updateStatement = connection.prepareStatement(sql)) {
|
||||||
return updateStatement.executeUpdate();
|
return updateStatement.executeUpdate();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user