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.

This commit is contained in:
2024-12-05 12:35:59 +00:00
parent ed6ce0fdc3
commit 434061e82b
4 changed files with 48 additions and 16 deletions

View File

@@ -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
## 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

View File

@@ -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 {

View File

@@ -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");

View File

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