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:
@@ -1,4 +1,8 @@
|
|||||||
# Build from windows command line:
|
# Build from windows command line:
|
||||||
## 1. cd /path/to/project
|
## 1. cd /path/to/project
|
||||||
## 2. gradlew.bat build
|
## 2. gradlew.bat clean build
|
||||||
## 3. find .jar file in build/libs
|
## 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
|
||||||
19
build.gradle
19
build.gradle
@@ -18,6 +18,12 @@ archivesBaseName = 'playerstats'
|
|||||||
|
|
||||||
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
||||||
|
|
||||||
|
// Create a configuration for including dependencies in the JAR
|
||||||
|
configurations {
|
||||||
|
shade
|
||||||
|
implementation.extendsFrom shade
|
||||||
|
}
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
mappings channel: 'official', version: '1.18.2'
|
mappings channel: 'official', version: '1.18.2'
|
||||||
runs {
|
runs {
|
||||||
@@ -54,7 +60,10 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
minecraft 'net.minecraftforge:forge:1.18.2-40.2.4'
|
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-api:5.8.2'
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
||||||
testImplementation 'org.mockito:mockito-core:4.3.1'
|
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")
|
"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 {
|
test {
|
||||||
|
|||||||
@@ -28,17 +28,23 @@ public class DatabaseManager {
|
|||||||
private static final String DB_PASSWORD = System.getenv("DB_PASSWORD"); // "password";
|
private static final String DB_PASSWORD = System.getenv("DB_PASSWORD"); // "password";
|
||||||
*/
|
*/
|
||||||
/* Public connection */
|
/* 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_USERNAME = "partsltd_minecraft_mod";
|
||||||
protected static final String DB_PASSWORD = "nipples_are_always_erect";
|
protected static final String DB_PASSWORD = "nipples_are_always_erect";
|
||||||
protected static final Logger LOGGER = Logger.getLogger(DatabaseManager.class.getName());
|
protected static final Logger LOGGER = Logger.getLogger(DatabaseManager.class.getName());
|
||||||
|
|
||||||
/*
|
static {
|
||||||
public DatabaseManager() {
|
try {
|
||||||
config = new Properties();
|
// Explicitly load the MySQL driver
|
||||||
loadConfig();
|
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() {
|
protected void loadConfig() {
|
||||||
File configFile = new File("config/playerstats/database.properties");
|
File configFile = new File("config/playerstats/database.properties");
|
||||||
if (!configFile.exists()) {
|
if (!configFile.exists()) {
|
||||||
@@ -97,7 +103,7 @@ public class DatabaseManager {
|
|||||||
public void recordLocation(Player player) {
|
public void recordLocation(Player player) {
|
||||||
try (Connection conn = getConnection();
|
try (Connection conn = getConnection();
|
||||||
PreparedStatement stmt = conn.prepareStatement(
|
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.setString(1, player.getUUID().toString());
|
||||||
stmt.setDouble(2, player.getX());
|
stmt.setDouble(2, player.getX());
|
||||||
@@ -113,6 +119,7 @@ public class DatabaseManager {
|
|||||||
|
|
||||||
public void initializeDatabase() {
|
public void initializeDatabase() {
|
||||||
try (Connection conn = getConnection()) {
|
try (Connection conn = getConnection()) {
|
||||||
|
/*
|
||||||
// Create tables
|
// Create tables
|
||||||
conn.createStatement().execute("""
|
conn.createStatement().execute("""
|
||||||
CREATE TABLE IF NOT EXISTS MCMPS_player_statistic (
|
CREATE TABLE IF NOT EXISTS MCMPS_player_statistic (
|
||||||
@@ -128,7 +135,7 @@ public class DatabaseManager {
|
|||||||
""");
|
""");
|
||||||
|
|
||||||
conn.createStatement().execute("""
|
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,
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
player_uuid VARCHAR(36),
|
player_uuid VARCHAR(36),
|
||||||
x DOUBLE,
|
x DOUBLE,
|
||||||
@@ -139,6 +146,7 @@ public class DatabaseManager {
|
|||||||
INDEX idx_player_uuid (player_uuid)
|
INDEX idx_player_uuid (player_uuid)
|
||||||
)
|
)
|
||||||
""");
|
""");
|
||||||
|
*/
|
||||||
LOGGER.log(Level.INFO, "Database initialised");
|
LOGGER.log(Level.INFO, "Database initialised");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.INFO, "Database initialisation error");
|
LOGGER.log(Level.INFO, "Database initialisation error");
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
DROP TABLE IF EXISTS partsltd_dev.MCMPS_player_stats;
|
USE partsltd_minecraft;
|
||||||
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;
|
|
||||||
|
|
||||||
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,
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
player_uuid VARCHAR(36),
|
player_uuid VARCHAR(36),
|
||||||
stat_type VARCHAR(50),
|
stat_type VARCHAR(50),
|
||||||
@@ -14,7 +17,7 @@ CREATE TABLE IF NOT EXISTS MCMPS_MCMPS_player_statistic (
|
|||||||
INDEX idx_stat_type (stat_type)
|
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,
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
player_uuid VARCHAR(36),
|
player_uuid VARCHAR(36),
|
||||||
x DOUBLE,
|
x DOUBLE,
|
||||||
|
|||||||
Reference in New Issue
Block a user