1.2.0 release

This commit is contained in:
mlus-Asuka 2023-08-09 16:00:09 +08:00
parent e7836a37a4
commit 76836f680f
7 changed files with 55 additions and 45 deletions

View File

@ -119,17 +119,12 @@ dependencies {
minecraft 'net.minecraftforge:forge:1.18.2-40.1.0' minecraft 'net.minecraftforge:forge:1.18.2-40.1.0'
jarJar("curse.maven:MySQL-561280:3685108") { jarJar("curse.maven:MySQL-561280:3685108") {
jarJar.ranged(it, '[1.0,)') jarJar.ranged(it, '[3685108,)')
}
jarJar("com.zaxxer:HikariCP:3.4.5") {
jarJar.ranged(it, '[3.4.5,)')
} }
runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.18.2-5.0.7.1") 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") 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 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. // Example for how to get properties into the manifest for reading at runtime.

View File

@ -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," +

View File

@ -47,7 +47,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()) {
@ -57,5 +58,6 @@ public class ChatSync {
playerList.broadcastMessage(textComponents, ChatType.CHAT, UUID.nameUUIDFromBytes(player.getBytes())); playerList.broadcastMessage(textComponents, ChatType.CHAT, UUID.nameUUIDFromBytes(player.getBytes()));
} }
resultSet.close(); resultSet.close();
queryResult.getConnection().close();
} }
} }

View File

@ -24,7 +24,8 @@ public class ModsSupport {
Curios Support Curios Support
*/ */
LazyOptional<IItemHandlerModifiable> itemHandler = top.theillusivec4.curios.api.CuriosApi.getCuriosHelper().getEquippedCurios(player); 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()) { 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) {
@ -41,6 +42,7 @@ public class ModsSupport {
}); });
} }
resultSet.close(); resultSet.close();
queryResult.getConnection().close();
}else{ }else{
StoreCurios(player,true); StoreCurios(player,true);
} }

View File

@ -41,7 +41,8 @@ public class VanillaSync {
public static void doPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) throws SQLException, 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.getPlayer(),true,Dist.CLIENT.isDedicatedServer()); Store(event.getPlayer(),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+"'");

View File

@ -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;
} }
} }
} }

View File

@ -6,7 +6,7 @@
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory modLoader="javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version # 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. # 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. # 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" 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 # Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory mandatory=true #mandatory
# The version range of the dependency # 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 # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering="NONE" ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER # Side this dependency is applied on - BOTH, CLIENT or SERVER
@ -61,6 +61,6 @@ make multiserver players' data sync
modId="minecraft" modId="minecraft"
mandatory=true mandatory=true
# This version range declares a minimum of the current minecraft version up to but not including the next major version # 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" ordering="NONE"
side="BOTH" side="BOTH"