1.2.0 release
This commit is contained in:
parent
e7836a37a4
commit
76836f680f
|
|
@ -119,17 +119,12 @@ dependencies {
|
|||
minecraft 'net.minecraftforge:forge:1.18.2-40.1.0'
|
||||
|
||||
jarJar("curse.maven:MySQL-561280:3685108") {
|
||||
jarJar.ranged(it, '[1.0,)')
|
||||
}
|
||||
|
||||
jarJar("com.zaxxer:HikariCP:3.4.5") {
|
||||
jarJar.ranged(it, '[3.4.5,)')
|
||||
jarJar.ranged(it, '[3685108,)')
|
||||
}
|
||||
|
||||
runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.18.2-5.0.7.1")
|
||||
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.18.2-5.0.7.1:api")
|
||||
implementation fg.deobf("curse.maven:MySQL-561280:3685108")
|
||||
implementation group: 'com.zaxxer', name: 'HikariCP', version: '3.4.5'
|
||||
}
|
||||
|
||||
// Example for how to get properties into the manifest for reading at runtime.
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class PlayerSync
|
|||
|
||||
@SubscribeEvent
|
||||
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," +
|
||||
"inventory MEDIUMBLOB,armor BLOB,advancements BLOB,enderchest MEDIUMBLOB,effects BLOB," +
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@ public class ChatSync {
|
|||
}
|
||||
|
||||
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();
|
||||
tick = 0;
|
||||
while(resultSet.next()) {
|
||||
|
|
@ -57,5 +58,6 @@ public class ChatSync {
|
|||
playerList.broadcastMessage(textComponents, ChatType.CHAT, UUID.nameUUIDFromBytes(player.getBytes()));
|
||||
}
|
||||
resultSet.close();
|
||||
queryResult.getConnection().close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ public class ModsSupport {
|
|||
Curios Support
|
||||
*/
|
||||
LazyOptional<IItemHandlerModifiable> itemHandler = top.theillusivec4.curios.api.CuriosApi.getCuriosHelper().getEquippedCurios(player);
|
||||
ResultSet resultSet = JDBCsetUp.executeQuery("SELECT curios_item FROM curios WHERE uuid = '"+player.getUUID()+"'");
|
||||
JDBCsetUp.QueryResult queryResult=JDBCsetUp.executeQuery("SELECT curios_item FROM curios WHERE uuid = '"+player.getUUID()+"'");
|
||||
ResultSet resultSet = queryResult.getResultSet();
|
||||
if(resultSet.next()) {
|
||||
String curios_data=resultSet.getString("curios_item");
|
||||
if(curios_data.length()>2) {
|
||||
|
|
@ -41,6 +42,7 @@ public class ModsSupport {
|
|||
});
|
||||
}
|
||||
resultSet.close();
|
||||
queryResult.getConnection().close();
|
||||
}else{
|
||||
StoreCurios(player,true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ public class VanillaSync {
|
|||
|
||||
public static void doPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) throws SQLException, CommandSyntaxException, IOException {
|
||||
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();
|
||||
if(!resultSet.next()){
|
||||
Store(event.getPlayer(),true,Dist.CLIENT.isDedicatedServer());
|
||||
|
|
@ -49,10 +50,12 @@ public class VanillaSync {
|
|||
}
|
||||
boolean online = resultSet.getBoolean("online");
|
||||
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) {
|
||||
|
||||
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()){
|
||||
long last_update = getServerInfo.getLong("last_update");
|
||||
boolean enable = getServerInfo.getBoolean("enable");
|
||||
|
|
@ -67,7 +70,6 @@ public class VanillaSync {
|
|||
getServerInfo.close();
|
||||
|
||||
|
||||
|
||||
}
|
||||
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+"'");
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package vip.fubuki.playersync.util;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import vip.fubuki.playersync.config.JdbcConfig;
|
||||
|
||||
import java.sql.*;
|
||||
|
|
@ -9,40 +7,51 @@ import java.sql.*;
|
|||
|
||||
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 {
|
||||
if (dataSource == null) {
|
||||
initDataSource();
|
||||
}
|
||||
return dataSource.getConnection();
|
||||
String url= "jdbc:mysql://"+JdbcConfig.HOST.get()+":"+JdbcConfig.PORT.get()+"?useUnicode=true&characterEncoding=utf-8&useSSL="+JdbcConfig.USE_SSL.get()+"&serverTimezone=UTC&allowPublicKeyRetrieval=true";
|
||||
return DriverManager.getConnection(url, JdbcConfig.USERNAME.get(), JdbcConfig.PASSWORD.get());
|
||||
}
|
||||
|
||||
public static ResultSet executeQuery(String sql) throws SQLException{
|
||||
try (Connection connection = getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
return preparedStatement.executeQuery();
|
||||
public static QueryResult executeQuery(String sql) throws SQLException{
|
||||
Connection connection = getConnection();
|
||||
|
||||
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{
|
||||
executeUpdate(sql,false);
|
||||
}
|
||||
public static class QueryResult{
|
||||
private final Connection connection;
|
||||
private final ResultSet resultSet;
|
||||
|
||||
public static void executeUpdate(String sql,boolean init) throws SQLException{
|
||||
try (Connection connection = getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
if(!init) preparedStatement.executeUpdate("USE "+JdbcConfig.DATABASE_NAME.get());
|
||||
preparedStatement.executeUpdate();
|
||||
public QueryResult(Connection connection, ResultSet resultSet) {
|
||||
this.connection = connection;
|
||||
this.resultSet = resultSet;
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public ResultSet getResultSet() {
|
||||
return resultSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
|
||||
modLoader="javafml" #mandatory
|
||||
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
|
||||
loaderVersion="[43,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
|
||||
loaderVersion="[40,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
|
||||
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
|
||||
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
|
||||
license="GPL-3.0 license"
|
||||
|
|
@ -51,7 +51,7 @@ make multiserver players' data sync
|
|||
# Does this dependency have to exist - if not, ordering below must be specified
|
||||
mandatory=true #mandatory
|
||||
# The version range of the dependency
|
||||
versionRange="[43,)" #mandatory
|
||||
versionRange="[40,)" #mandatory
|
||||
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
|
||||
ordering="NONE"
|
||||
# Side this dependency is applied on - BOTH, CLIENT or SERVER
|
||||
|
|
@ -61,6 +61,6 @@ make multiserver players' data sync
|
|||
modId="minecraft"
|
||||
mandatory=true
|
||||
# This version range declares a minimum of the current minecraft version up to but not including the next major version
|
||||
versionRange="[1.19.2,1.20)"
|
||||
versionRange="[1.18.2,)"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
Loading…
Reference in New Issue
Block a user