From 434061e82bda331005a72177fcb52650af950d81 Mon Sep 17 00:00:00 2001 From: teddy Date: Thu, 5 Dec 2024 12:35:59 +0000 Subject: [PATCH] 1. Fix: Change database schema and table names. \n 2. Remove sync_instance_with_server.bat from this project to server project so users do not need access to this project. --- README.md | 8 ++++++-- build.gradle | 19 ++++++++++++++++++- src/main/java/DatabaseManager.java | 22 +++++++++++++++------- src/main/sql/100_tbls.sql | 15 +++++++++------ 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 7689d03..9ff93ee 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ # Build from windows command line: ## 1. cd /path/to/project -## 2. gradlew.bat build -## 3. find .jar file in build/libs \ No newline at end of file +## 2. gradlew.bat clean build +## 3. find .jar file in build/libs + +# Sync minecraft instance with server: +## 1. paste minecraft_mod_player_statistics/src/main/batch/sync_instance_with_server.bat in your instance's minecraft directory +## 2. double click to run sync_instance_with_server.bat from your instance's minecraft directory \ No newline at end of file diff --git a/build.gradle b/build.gradle index 28a838d..6510705 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,12 @@ archivesBaseName = 'playerstats' java.toolchain.languageVersion = JavaLanguageVersion.of(17) +// Create a configuration for including dependencies in the JAR +configurations { + shade + implementation.extendsFrom shade +} + minecraft { mappings channel: 'official', version: '1.18.2' runs { @@ -54,7 +60,10 @@ repositories { dependencies { minecraft 'net.minecraftforge:forge:1.18.2-40.2.4' - implementation 'mysql:mysql-connector-java:8.0.27' + + // Add MySQL connector to the shade configuration + shade 'mysql:mysql-connector-java:8.0.27' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2' testImplementation 'org.mockito:mockito-core:4.3.1' @@ -73,6 +82,14 @@ jar { "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } + + // Include shaded dependencies + from { + configurations.shade.collect { it.isDirectory() ? it : zipTree(it) } + } + + // Exclude META-INF from dependencies + exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA' } test { diff --git a/src/main/java/DatabaseManager.java b/src/main/java/DatabaseManager.java index 67623de..da95071 100644 --- a/src/main/java/DatabaseManager.java +++ b/src/main/java/DatabaseManager.java @@ -28,17 +28,23 @@ public class DatabaseManager { private static final String DB_PASSWORD = System.getenv("DB_PASSWORD"); // "password"; */ /* Public connection */ - protected static final String DB_URL = "jdbc:mysql://185.221.63.17/partsltd_dev"; + protected static final String DB_URL = "jdbc:mysql://185.221.63.17/partsltd_minecraft"; protected static final String DB_USERNAME = "partsltd_minecraft_mod"; protected static final String DB_PASSWORD = "nipples_are_always_erect"; protected static final Logger LOGGER = Logger.getLogger(DatabaseManager.class.getName()); - /* - public DatabaseManager() { - config = new Properties(); - loadConfig(); + static { + try { + // Explicitly load the MySQL driver + Class.forName("com.mysql.cj.jdbc.Driver"); + LOGGER.info("MySQL JDBC Driver registered successfully"); + } catch (ClassNotFoundException e) { + LOGGER.severe("Failed to load MySQL JDBC driver: " + e.getMessage()); + throw new RuntimeException("Failed to load MySQL JDBC driver", e); + } } + /* protected void loadConfig() { File configFile = new File("config/playerstats/database.properties"); if (!configFile.exists()) { @@ -97,7 +103,7 @@ public class DatabaseManager { public void recordLocation(Player player) { try (Connection conn = getConnection(); PreparedStatement stmt = conn.prepareStatement( - "INSERT INTO MCMPS_player_locations (player_uuid, x, y, z, dimension, timestamp) VALUES (?, ?, ?, ?, ?, ?)")) { + "INSERT INTO MCMPS_player_location (player_uuid, x, y, z, dimension, timestamp) VALUES (?, ?, ?, ?, ?, ?)")) { stmt.setString(1, player.getUUID().toString()); stmt.setDouble(2, player.getX()); @@ -113,6 +119,7 @@ public class DatabaseManager { public void initializeDatabase() { try (Connection conn = getConnection()) { + /* // Create tables conn.createStatement().execute(""" CREATE TABLE IF NOT EXISTS MCMPS_player_statistic ( @@ -128,7 +135,7 @@ public class DatabaseManager { """); conn.createStatement().execute(""" - CREATE TABLE IF NOT EXISTS MCMPS_player_locations ( + CREATE TABLE IF NOT EXISTS MCMPS_player_location ( id BIGINT AUTO_INCREMENT PRIMARY KEY, player_uuid VARCHAR(36), x DOUBLE, @@ -139,6 +146,7 @@ public class DatabaseManager { INDEX idx_player_uuid (player_uuid) ) """); + */ LOGGER.log(Level.INFO, "Database initialised"); } catch (SQLException e) { LOGGER.log(Level.INFO, "Database initialisation error"); diff --git a/src/main/sql/100_tbls.sql b/src/main/sql/100_tbls.sql index 53b4383..60f3566 100644 --- a/src/main/sql/100_tbls.sql +++ b/src/main/sql/100_tbls.sql @@ -1,9 +1,12 @@ -DROP TABLE IF EXISTS partsltd_dev.MCMPS_player_stats; -DROP TABLE IF EXISTS partsltd_dev.MCMPS_MCMPS_player_statistic; -DROP TABLE IF EXISTS partsltd_dev.MCMPS_MCMPS_player_locations; -DROP TABLE IF EXISTS partsltd_dev.MCMPS_MCMPS_player_location; +USE partsltd_minecraft; -CREATE TABLE IF NOT EXISTS MCMPS_MCMPS_player_statistic ( +DROP TABLE IF EXISTS partsltd_dev.MCMPS_player_stats; +DROP TABLE IF EXISTS partsltd_dev.MCMPS_player_statistic; +DROP TABLE IF EXISTS partsltd_dev.MCMPS_player_statistics; +DROP TABLE IF EXISTS partsltd_dev.MCMPS_player_locations; +DROP TABLE IF EXISTS partsltd_dev.MCMPS_player_location; + +CREATE TABLE IF NOT EXISTS MCMPS_player_statistic ( id BIGINT AUTO_INCREMENT PRIMARY KEY, player_uuid VARCHAR(36), stat_type VARCHAR(50), @@ -14,7 +17,7 @@ CREATE TABLE IF NOT EXISTS MCMPS_MCMPS_player_statistic ( INDEX idx_stat_type (stat_type) ); -CREATE TABLE IF NOT EXISTS MCMPS_MCMPS_player_location ( +CREATE TABLE IF NOT EXISTS MCMPS_player_location ( id BIGINT AUTO_INCREMENT PRIMARY KEY, player_uuid VARCHAR(36), x DOUBLE,