1.2.0 release
This commit is contained in:
parent
5ef817a9b7
commit
45e13f1199
|
|
@ -41,7 +41,7 @@ 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(),true);
|
JDBCsetUp.executeUpdate("CREATE DATABASE IF NOT EXISTS "+JdbcConfig.DATABASE_NAME.get());
|
||||||
|
|
||||||
JDBCsetUp.executeUpdate("CREATE TABLE IF NOT EXISTS player_data (uuid CHAR(36) NOT NULL," +
|
JDBCsetUp.executeUpdate("CREATE TABLE IF NOT EXISTS player_data (uuid CHAR(36) NOT NULL," +
|
||||||
"inventory MEDIUMBLOB,armor BLOB,advancements BLOB,enderchest MEDIUMBLOB,effects BLOB," +
|
"inventory MEDIUMBLOB,armor BLOB,advancements BLOB,enderchest MEDIUMBLOB,effects BLOB," +
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ public class ChatSync {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ReadMessage(PlayerList playerList) throws SQLException {
|
public static void ReadMessage(PlayerList playerList) throws SQLException {
|
||||||
ResultSet resultSet= JDBCsetUp.executeQuery("SELECT * FROM chat WHERE timestamp > " + current);
|
JDBCsetUp.QueryResult queryResult=JDBCsetUp.executeQuery("SELECT * FROM chat WHERE timestamp > " + current);
|
||||||
|
ResultSet resultSet= queryResult.getResultSet();
|
||||||
current = System.currentTimeMillis();
|
current = System.currentTimeMillis();
|
||||||
tick = 0;
|
tick = 0;
|
||||||
while(resultSet.next()) {
|
while(resultSet.next()) {
|
||||||
|
|
@ -40,5 +41,6 @@ public class ChatSync {
|
||||||
playerList.broadcastSystemMessage(textComponents, true);
|
playerList.broadcastSystemMessage(textComponents, true);
|
||||||
}
|
}
|
||||||
resultSet.close();
|
resultSet.close();
|
||||||
|
queryResult.getConnection().close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,15 +15,17 @@ import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@SuppressWarnings({"InstantiationOfUtilityClass", "AccessStaticViaInstance"})
|
|
||||||
public class ModsSupport {
|
public class ModsSupport {
|
||||||
|
|
||||||
public void onPlayerJoin(Player player) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
public void onPlayerJoin(Player player) throws SQLException {
|
||||||
if (ModList.get().isLoaded("curios")) {
|
if (ModList.get().isLoaded("curios")) {
|
||||||
//TODO curios support
|
/*
|
||||||
top.theillusivec4.curios.api.CuriosApi CuriosApi = new top.theillusivec4.curios.api.CuriosApi();
|
Curios Support
|
||||||
LazyOptional<IItemHandlerModifiable> itemHandler = CuriosApi.getCuriosHelper().getEquippedCurios(player);
|
*/
|
||||||
ResultSet resultSet = JDBCsetUp.executeQuery("SELECT curios_item FROM curios WHERE uuid = '"+player.getUUID()+"'");
|
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();
|
||||||
if(resultSet.next()) {
|
if(resultSet.next()) {
|
||||||
String curios_data=resultSet.getString("curios_item");
|
String curios_data=resultSet.getString("curios_item");
|
||||||
if(curios_data.length()>2) {
|
if(curios_data.length()>2) {
|
||||||
|
|
@ -40,21 +42,21 @@ public class ModsSupport {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
resultSet.close();
|
resultSet.close();
|
||||||
|
queryResult.getConnection().close();
|
||||||
}else{
|
}else{
|
||||||
StoreCurios(player,true);
|
StoreCurios(player,true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPlayerLeave(Player player) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
public void onPlayerLeave(Player player) throws SQLException {
|
||||||
if (ModList.get().isLoaded("curios")) {
|
if (ModList.get().isLoaded("curios")) {
|
||||||
StoreCurios(player, false);
|
StoreCurios(player, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StoreCurios(Player player,boolean init) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
public void StoreCurios(Player player,boolean init) throws SQLException {
|
||||||
top.theillusivec4.curios.api.CuriosApi CuriosApi = new top.theillusivec4.curios.api.CuriosApi();
|
LazyOptional<IItemHandlerModifiable> itemHandler = top.theillusivec4.curios.api.CuriosApi.getCuriosHelper().getEquippedCurios(player);
|
||||||
LazyOptional<IItemHandlerModifiable> itemHandler = CuriosApi.getCuriosHelper().getEquippedCurios(player);
|
|
||||||
Map<Integer, String> curios = new HashMap<>();
|
Map<Integer, String> curios = new HashMap<>();
|
||||||
itemHandler.ifPresent(handler -> {
|
itemHandler.ifPresent(handler -> {
|
||||||
for (int i = 0; i < handler.getSlots(); i++) {
|
for (int i = 0; i < handler.getSlots(); i++) {
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,10 @@ public class VanillaSync {
|
||||||
|
|
||||||
static ExecutorService executorService = Executors.newCachedThreadPool(new PSThreadPoolFactory("PlayerSync"));
|
static ExecutorService executorService = Executors.newCachedThreadPool(new PSThreadPoolFactory("PlayerSync"));
|
||||||
|
|
||||||
public static void doPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, CommandSyntaxException, IOException {
|
public static void doPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) throws SQLException, CommandSyntaxException, IOException {
|
||||||
String player_uuid = event.getEntity().getUUID().toString();
|
String player_uuid = event.getEntity().getUUID().toString();
|
||||||
ResultSet resultSet=JDBCsetUp.executeQuery("SELECT online, last_server FROM player_data WHERE uuid='"+player_uuid+"'");
|
JDBCsetUp.QueryResult queryResult=JDBCsetUp.executeQuery("SELECT online, last_server FROM player_data WHERE uuid='"+player_uuid+"'");
|
||||||
|
ResultSet resultSet=queryResult.getResultSet();
|
||||||
ServerPlayer serverPlayer = (ServerPlayer) event.getEntity();
|
ServerPlayer serverPlayer = (ServerPlayer) event.getEntity();
|
||||||
if(!resultSet.next()){
|
if(!resultSet.next()){
|
||||||
Store(event.getEntity(),true,Dist.CLIENT.isDedicatedServer());
|
Store(event.getEntity(),true,Dist.CLIENT.isDedicatedServer());
|
||||||
|
|
@ -49,10 +50,12 @@ public class VanillaSync {
|
||||||
}
|
}
|
||||||
boolean online = resultSet.getBoolean("online");
|
boolean online = resultSet.getBoolean("online");
|
||||||
int lastServer = resultSet.getInt("last_server");
|
int lastServer = resultSet.getInt("last_server");
|
||||||
resultSet=JDBCsetUp.executeQuery("SELECT * FROM player_data WHERE uuid='"+player_uuid+"'");
|
queryResult=JDBCsetUp.executeQuery("SELECT * FROM player_data WHERE uuid='"+player_uuid+"'");
|
||||||
|
resultSet= queryResult.getResultSet();
|
||||||
if(online) {
|
if(online) {
|
||||||
|
|
||||||
ResultSet getServerInfo = JDBCsetUp.executeQuery("SELECT last_update,enable FROM server_info WHERE id='"+lastServer+"'");
|
queryResult=JDBCsetUp.executeQuery("SELECT last_update,enable FROM server_info WHERE id='"+lastServer+"'");
|
||||||
|
ResultSet getServerInfo = queryResult.getResultSet();
|
||||||
if(getServerInfo.next()){
|
if(getServerInfo.next()){
|
||||||
long last_update = getServerInfo.getLong("last_update");
|
long last_update = getServerInfo.getLong("last_update");
|
||||||
boolean enable = getServerInfo.getBoolean("enable");
|
boolean enable = getServerInfo.getBoolean("enable");
|
||||||
|
|
@ -67,7 +70,6 @@ public class VanillaSync {
|
||||||
getServerInfo.close();
|
getServerInfo.close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
JDBCsetUp.executeUpdate("UPDATE server_info SET last_update=" + System.currentTimeMillis() + " WHERE id=" + JdbcConfig.SERVER_ID.get());
|
JDBCsetUp.executeUpdate("UPDATE server_info SET last_update=" + System.currentTimeMillis() + " WHERE id=" + JdbcConfig.SERVER_ID.get());
|
||||||
JDBCsetUp.executeUpdate("UPDATE player_data SET online=true,last_server=" + JdbcConfig.SERVER_ID.get() + " WHERE uuid='"+player_uuid+"'");
|
JDBCsetUp.executeUpdate("UPDATE player_data SET online=true,last_server=" + JdbcConfig.SERVER_ID.get() + " WHERE uuid='"+player_uuid+"'");
|
||||||
|
|
@ -154,7 +156,7 @@ public class VanillaSync {
|
||||||
return ItemStack.of(compoundTag);
|
return ItemStack.of(compoundTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doPlayerSaveToFile(PlayerEvent.SaveToFile event) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
public static void doPlayerSaveToFile(PlayerEvent.SaveToFile event) throws SQLException, IOException {
|
||||||
JDBCsetUp.executeUpdate("UPDATE server_info SET last_update=" + System.currentTimeMillis() + " WHERE id=" + JdbcConfig.SERVER_ID.get());
|
JDBCsetUp.executeUpdate("UPDATE server_info SET last_update=" + System.currentTimeMillis() + " WHERE id=" + JdbcConfig.SERVER_ID.get());
|
||||||
if(!event.getEntity().getTags().contains("player_synced")) return;
|
if(!event.getEntity().getTags().contains("player_synced")) return;
|
||||||
Store(event.getEntity(),false,Dist.CLIENT.isDedicatedServer());
|
Store(event.getEntity(),false,Dist.CLIENT.isDedicatedServer());
|
||||||
|
|
@ -179,7 +181,7 @@ public class VanillaSync {
|
||||||
JDBCsetUp.executeUpdate("UPDATE server_info SET enable=false WHERE id=" + JdbcConfig.SERVER_ID.get());
|
JDBCsetUp.executeUpdate("UPDATE server_info SET enable=false WHERE id=" + JdbcConfig.SERVER_ID.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
|
public static void doPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event) throws SQLException, IOException {
|
||||||
if(!event.getEntity().getTags().contains("player_synced")) return;
|
if(!event.getEntity().getTags().contains("player_synced")) return;
|
||||||
String player_uuid = event.getEntity().getUUID().toString();
|
String player_uuid = event.getEntity().getUUID().toString();
|
||||||
JDBCsetUp.executeUpdate("UPDATE player_data SET online=false WHERE uuid='"+player_uuid+"'");
|
JDBCsetUp.executeUpdate("UPDATE player_data SET online=false WHERE uuid='"+player_uuid+"'");
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package vip.fubuki.playersync.util;
|
package vip.fubuki.playersync.util;
|
||||||
|
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
|
||||||
import vip.fubuki.playersync.config.JdbcConfig;
|
import vip.fubuki.playersync.config.JdbcConfig;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
@ -9,40 +7,51 @@ import java.sql.*;
|
||||||
|
|
||||||
public class JDBCsetUp {
|
public class JDBCsetUp {
|
||||||
|
|
||||||
private static HikariDataSource dataSource;
|
|
||||||
|
|
||||||
public static void initDataSource() {
|
|
||||||
HikariConfig config = new HikariConfig();
|
|
||||||
config.setJdbcUrl("jdbc:mysql://"+JdbcConfig.HOST.get()+":"+JdbcConfig.PORT.get()+"?useUnicode=true&characterEncoding=utf-8&useSSL="+JdbcConfig.USE_SSL.get()+"&serverTimezone=UTC&allowPublicKeyRetrieval=true");
|
|
||||||
config.setUsername(JdbcConfig.USERNAME.get());
|
|
||||||
config.setPassword(JdbcConfig.PASSWORD.get());
|
|
||||||
|
|
||||||
dataSource = new HikariDataSource(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Connection getConnection() throws SQLException {
|
public static Connection getConnection() throws SQLException {
|
||||||
if (dataSource == null) {
|
String url= "jdbc:mysql://"+JdbcConfig.HOST.get()+":"+JdbcConfig.PORT.get()+"?useUnicode=true&characterEncoding=utf-8&useSSL="+JdbcConfig.USE_SSL.get()+"&serverTimezone=UTC&allowPublicKeyRetrieval=true";
|
||||||
initDataSource();
|
return DriverManager.getConnection(url, JdbcConfig.USERNAME.get(), JdbcConfig.PASSWORD.get());
|
||||||
}
|
|
||||||
return dataSource.getConnection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResultSet executeQuery(String sql) throws SQLException{
|
public static QueryResult executeQuery(String sql) throws SQLException{
|
||||||
try (Connection connection = getConnection();
|
Connection connection = getConnection();
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
|
||||||
return preparedStatement.executeQuery();
|
PreparedStatement useStatement = connection.prepareStatement("USE " + JdbcConfig.DATABASE_NAME.get());
|
||||||
|
useStatement.executeUpdate();
|
||||||
|
|
||||||
|
PreparedStatement queryStatement = connection.prepareStatement(sql);
|
||||||
|
ResultSet resultSet =queryStatement.executeQuery();
|
||||||
|
return new QueryResult(connection,resultSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int executeUpdate(String sql) throws SQLException{
|
||||||
|
try (Connection connection = getConnection()) {
|
||||||
|
|
||||||
|
try (PreparedStatement useStatement = connection.prepareStatement("USE " + JdbcConfig.DATABASE_NAME.get())) {
|
||||||
|
useStatement.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try (PreparedStatement updateStatement = connection.prepareStatement(sql)) {
|
||||||
|
return updateStatement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void executeUpdate(String sql) throws SQLException{
|
public static class QueryResult{
|
||||||
executeUpdate(sql,false);
|
private final Connection connection;
|
||||||
}
|
private final ResultSet resultSet;
|
||||||
|
|
||||||
public static void executeUpdate(String sql,boolean init) throws SQLException{
|
public QueryResult(Connection connection, ResultSet resultSet) {
|
||||||
try (Connection connection = getConnection();
|
this.connection = connection;
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
this.resultSet = resultSet;
|
||||||
if(!init) preparedStatement.executeUpdate("USE "+JdbcConfig.DATABASE_NAME.get());
|
}
|
||||||
preparedStatement.executeUpdate();
|
|
||||||
|
public Connection getConnection() {
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultSet getResultSet() {
|
||||||
|
return resultSet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user