Connect to public partsltd_dev database for use of mod by other people.
This commit is contained in:
34
build.gradle
34
build.gradle
@@ -4,17 +4,10 @@ buildscript {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+'
|
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.74'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
plugins {
|
|
||||||
id 'eclipse'
|
|
||||||
id 'maven-publish'
|
|
||||||
id 'net.minecraftforge.gradle'
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
apply plugin: 'net.minecraftforge.gradle'
|
apply plugin: 'net.minecraftforge.gradle'
|
||||||
apply plugin: 'eclipse'
|
apply plugin: 'eclipse'
|
||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
@@ -51,19 +44,21 @@ minecraft {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
repositories {
|
||||||
/* Project */
|
mavenCentral()
|
||||||
minecraft 'net.minecraftforge:forge:1.18.2-40.1.0'
|
maven {
|
||||||
implementation 'mysql:mysql-connector-java:8.0.27'
|
name = 'Forge'
|
||||||
|
url = 'https://maven.minecraftforge.net/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Tests */
|
dependencies {
|
||||||
// Unit
|
minecraft 'net.minecraftforge:forge:1.18.2-40.2.4'
|
||||||
|
implementation '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'
|
||||||
testImplementation 'org.mockito:mockito-junit-jupiter:4.3.1'
|
testImplementation 'org.mockito:mockito-junit-jupiter:4.3.1'
|
||||||
// Integration
|
|
||||||
// testImplementation 'net.minecraftforge:forge:1.18.2-40.1.0:test'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
@@ -74,7 +69,7 @@ jar {
|
|||||||
"Specification-Version": "1",
|
"Specification-Version": "1",
|
||||||
"Implementation-Title": project.name,
|
"Implementation-Title": project.name,
|
||||||
"Implementation-Version": project.jar.archiveVersion,
|
"Implementation-Version": project.jar.archiveVersion,
|
||||||
"Implementation-Vendor" :"examplemodsareus",
|
"Implementation-Vendor": "examplemodsareus",
|
||||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
@@ -82,7 +77,4 @@ jar {
|
|||||||
|
|
||||||
test {
|
test {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
testLogging {
|
}
|
||||||
events "passed", "skipped", "failed"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +1,87 @@
|
|||||||
package minecraft_mod_player_statistics.src.main.java;
|
package minecraft_mod_player_statistics.src.main.java;
|
||||||
|
|
||||||
import minecraft_mod_player_statistics.src.main.java.PlayerStatisticsMod;
|
import minecraft_mod_player_statistics.src.main.java.PlayerStatisticsMod;
|
||||||
|
// import minecraft_mod_player_statistics.src.main.java.ConfigManager;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.UUID;
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
public class DatabaseManager {
|
public class DatabaseManager {
|
||||||
|
// protected final Properties config;
|
||||||
|
/* Local connection
|
||||||
private static final String DB_URL = "jdbc:mysql://localhost:3306/partsltd_dev";
|
private static final String DB_URL = "jdbc:mysql://localhost:3306/partsltd_dev";
|
||||||
private static final String DB_USER = "root";
|
private static final String DB_USERNAME = "root";
|
||||||
private static final String DB_PASS = System.getenv("DB_PASSWORD"); // "password";
|
private static final String DB_PASSWORD = System.getenv("DB_PASSWORD"); // "password";
|
||||||
private static final Logger LOGGER = Logger.getLogger(DatabaseManager.class.getName());
|
*/
|
||||||
|
/* Public connection */
|
||||||
|
protected static final String DB_URL = "jdbc:mysql://185.221.63.17/partsltd_dev";
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void loadConfig() {
|
||||||
|
File configFile = new File("config/playerstats/database.properties");
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
configFile.getParentFile().mkdirs();
|
||||||
|
createDefaultConfig(configFile);
|
||||||
|
LOGGER.warning("Please configure database settings in config/playerstats/database.properties");
|
||||||
|
}
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(configFile)) {
|
||||||
|
config.load(fis);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.severe("Failed to load database config: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createDefaultConfig(File configFile) {
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(configFile)) {
|
||||||
|
Properties defaultProps = new Properties();
|
||||||
|
defaultProps.setProperty("db.url", "jdbc:mysql://localhost:3306/partsltd_dev");
|
||||||
|
defaultProps.setProperty("db.user", "change_me");
|
||||||
|
defaultProps.setProperty("db.password", "change_me");
|
||||||
|
defaultProps.store(fos, "PlayerStats Database Configuration");
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.severe("Failed to create default config: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Connection getConnection() throws SQLException {
|
public Connection getConnection() throws SQLException {
|
||||||
return DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
|
return DriverManager.getConnection(
|
||||||
|
config.getProperty("db.url"),
|
||||||
|
config.getProperty("db.user"),
|
||||||
|
config.getProperty("db.password")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public Connection getConnection() throws SQLException {
|
||||||
|
return DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recordStat(UUID playerUUID, String statType, int value, String itemId) {
|
public void recordStat(UUID playerUUID, String statType, int value, String itemId) {
|
||||||
try (Connection conn = getConnection();
|
try (Connection conn = getConnection();
|
||||||
PreparedStatement stmt = conn.prepareStatement(
|
PreparedStatement stmt = conn.prepareStatement(
|
||||||
"INSERT INTO player_stats (player_uuid, stat_type, stat_value, item_id, timestamp) VALUES (?, ?, ?, ?, ?)")) {
|
"INSERT INTO MCMPS_player_statistic (player_uuid, stat_type, stat_value, item_id, timestamp) VALUES (?, ?, ?, ?, ?)")) {
|
||||||
|
|
||||||
stmt.setString(1, playerUUID.toString());
|
stmt.setString(1, playerUUID.toString());
|
||||||
stmt.setString(2, statType);
|
stmt.setString(2, statType);
|
||||||
@@ -42,7 +97,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 player_locations (player_uuid, x, y, z, dimension, timestamp) VALUES (?, ?, ?, ?, ?, ?)")) {
|
"INSERT INTO MCMPS_player_locations (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());
|
||||||
@@ -60,7 +115,7 @@ public class DatabaseManager {
|
|||||||
try (Connection conn = getConnection()) {
|
try (Connection conn = getConnection()) {
|
||||||
// Create tables
|
// Create tables
|
||||||
conn.createStatement().execute("""
|
conn.createStatement().execute("""
|
||||||
CREATE TABLE IF NOT EXISTS player_stats (
|
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),
|
||||||
@@ -73,7 +128,7 @@ public class DatabaseManager {
|
|||||||
""");
|
""");
|
||||||
|
|
||||||
conn.createStatement().execute("""
|
conn.createStatement().execute("""
|
||||||
CREATE TABLE IF NOT EXISTS player_locations (
|
CREATE TABLE IF NOT EXISTS MCMPS_player_locations (
|
||||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
player_uuid VARCHAR(36),
|
player_uuid VARCHAR(36),
|
||||||
x DOUBLE,
|
x DOUBLE,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import java.sql.SQLException;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Mod("playerstats")
|
@Mod(value = "playerstats")
|
||||||
public class PlayerStatisticsMod {
|
public class PlayerStatisticsMod {
|
||||||
private final DatabaseManager dbManager;
|
private final DatabaseManager dbManager;
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
modLoader="javafml"
|
modLoader="javafml"
|
||||||
loaderVersion="[47,)"
|
loaderVersion="[40,)"
|
||||||
license="MIT"
|
license="MIT"
|
||||||
|
|
||||||
[[mods]]
|
[[mods]]
|
||||||
modId="playerstatistics"
|
modId="playerstats"
|
||||||
version="1.0.0"
|
version="1.0.0"
|
||||||
displayName="Player Statistics Mod"
|
displayName="Player Statistics"
|
||||||
description='''
|
description="Tracks player statistics and stores them in a database."
|
||||||
A mod that tracks and displays player statistics.
|
|
||||||
'''
|
|
||||||
|
|
||||||
[[dependencies.playerstatistics]]
|
[[dependencies.playerstats]]
|
||||||
modId="forge"
|
modId="forge"
|
||||||
mandatory=true
|
mandatory=true
|
||||||
versionRange="[47,)"
|
versionRange="[40,)"
|
||||||
ordering="NONE"
|
ordering="NONE"
|
||||||
side="BOTH"
|
side="BOTH"
|
||||||
|
|
||||||
[[dependencies.playerstatistics]]
|
[[dependencies.playerstats]]
|
||||||
modId="minecraft"
|
modId="minecraft"
|
||||||
mandatory=true
|
mandatory=true
|
||||||
versionRange="[1.20.1]"
|
versionRange="[1.18.2]"
|
||||||
ordering="NONE"
|
ordering="NONE"
|
||||||
side="BOTH"
|
side="BOTH"
|
||||||
6
src/main/resources/pack.mcmeta
Normal file
6
src/main/resources/pack.mcmeta
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"pack": {
|
||||||
|
"description": "Player Statistics Mod resources",
|
||||||
|
"pack_format": 8
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
CREATE SCHEMA IF NOT EXISTS partsltd_dev;
|
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;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS MCMPS_player_stats (
|
CREATE TABLE IF NOT EXISTS MCMPS_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),
|
||||||
@@ -11,7 +14,7 @@ CREATE TABLE IF NOT EXISTS MCMPS_player_stats (
|
|||||||
INDEX idx_stat_type (stat_type)
|
INDEX idx_stat_type (stat_type)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS MCMPS_player_locations (
|
CREATE TABLE IF NOT EXISTS MCMPS_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,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package minecraft_mod_player_statistics.src.test.java;
|
package minecraft_mod_player_statistics.src.test.java;
|
||||||
|
|
||||||
import minecraft_mod_player_statistics.src.main.java.DatabaseManager;
|
import minecraft_mod_player_statistics.src.test.java.TestDatabaseManager;
|
||||||
|
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -10,7 +11,7 @@ import java.sql.SQLException;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DatabaseManagerIntegrationTest {
|
public class DatabaseManagerIntegrationTest {
|
||||||
private static DatabaseManager dbManager;
|
private static TestDatabaseManager dbManager;
|
||||||
private static final UUID TEST_PLAYER_UUID = UUID.randomUUID();
|
private static final UUID TEST_PLAYER_UUID = UUID.randomUUID();
|
||||||
private static final String TEST_STAT_TYPE = "integration_test_stat";
|
private static final String TEST_STAT_TYPE = "integration_test_stat";
|
||||||
private static final String TEST_BLOCK_ID = "minecraft:test_block";
|
private static final String TEST_BLOCK_ID = "minecraft:test_block";
|
||||||
@@ -18,7 +19,7 @@ public class DatabaseManagerIntegrationTest {
|
|||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void setUp() {
|
static void setUp() {
|
||||||
dbManager = new DatabaseManager();
|
dbManager = new TestDatabaseManager();
|
||||||
// Initialize database schema
|
// Initialize database schema
|
||||||
dbManager.initializeDatabase();
|
dbManager.initializeDatabase();
|
||||||
}
|
}
|
||||||
@@ -28,7 +29,7 @@ public class DatabaseManagerIntegrationTest {
|
|||||||
// Clean up any test data before each test
|
// Clean up any test data before each test
|
||||||
try (Connection conn = dbManager.getConnection();
|
try (Connection conn = dbManager.getConnection();
|
||||||
PreparedStatement stmt = conn.prepareStatement(
|
PreparedStatement stmt = conn.prepareStatement(
|
||||||
"DELETE FROM player_stats WHERE stat_type = ?")) {
|
"DELETE FROM MCMPS_player_statistic WHERE stat_type = ?")) {
|
||||||
stmt.setString(1, TEST_STAT_TYPE);
|
stmt.setString(1, TEST_STAT_TYPE);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
}
|
}
|
||||||
@@ -50,7 +51,7 @@ public class DatabaseManagerIntegrationTest {
|
|||||||
// Verify the recorded data
|
// Verify the recorded data
|
||||||
try (Connection conn = dbManager.getConnection();
|
try (Connection conn = dbManager.getConnection();
|
||||||
PreparedStatement stmt = conn.prepareStatement(
|
PreparedStatement stmt = conn.prepareStatement(
|
||||||
"SELECT * FROM player_stats WHERE player_uuid = ? AND stat_type = ?")) {
|
"SELECT * FROM MCMPS_player_statistic WHERE player_uuid = ? AND stat_type = ?")) {
|
||||||
|
|
||||||
stmt.setString(1, TEST_PLAYER_UUID.toString());
|
stmt.setString(1, TEST_PLAYER_UUID.toString());
|
||||||
stmt.setString(2, TEST_STAT_TYPE);
|
stmt.setString(2, TEST_STAT_TYPE);
|
||||||
@@ -73,7 +74,7 @@ public class DatabaseManagerIntegrationTest {
|
|||||||
// Clean up test data after each test
|
// Clean up test data after each test
|
||||||
try (Connection conn = dbManager.getConnection();
|
try (Connection conn = dbManager.getConnection();
|
||||||
PreparedStatement stmt = conn.prepareStatement(
|
PreparedStatement stmt = conn.prepareStatement(
|
||||||
"DELETE FROM player_stats WHERE stat_type = ?")) {
|
"DELETE FROM MCMPS_player_statistic WHERE stat_type = ?")) {
|
||||||
stmt.setString(1, TEST_STAT_TYPE);
|
stmt.setString(1, TEST_STAT_TYPE);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
}
|
}
|
||||||
@@ -84,7 +85,7 @@ public class DatabaseManagerIntegrationTest {
|
|||||||
// Perform any final cleanup if needed
|
// Perform any final cleanup if needed
|
||||||
try (Connection conn = dbManager.getConnection();
|
try (Connection conn = dbManager.getConnection();
|
||||||
PreparedStatement stmt = conn.prepareStatement(
|
PreparedStatement stmt = conn.prepareStatement(
|
||||||
"DELETE FROM player_stats WHERE stat_type = ?")) {
|
"DELETE FROM MCMPS_player_statistic WHERE stat_type = ?")) {
|
||||||
stmt.setString(1, TEST_STAT_TYPE);
|
stmt.setString(1, TEST_STAT_TYPE);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class DatabaseManagerTest {
|
|||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
verify(connection).prepareStatement(
|
verify(connection).prepareStatement(
|
||||||
"INSERT INTO player_stats (player_uuid, stat_type, stat_value, item_id, timestamp) VALUES (?, ?, ?, ?, ?)"
|
"INSERT INTO MCMPS_player_statistic (player_uuid, stat_type, stat_value, item_id, timestamp) VALUES (?, ?, ?, ?, ?)"
|
||||||
);
|
);
|
||||||
|
|
||||||
verify(preparedStatement).setString(1, TEST_UUID.toString());
|
verify(preparedStatement).setString(1, TEST_UUID.toString());
|
||||||
|
|||||||
24
src/test/java/TestDatabaseManager.java
Normal file
24
src/test/java/TestDatabaseManager.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
package minecraft_mod_player_statistics.src.test.java;
|
||||||
|
|
||||||
|
import minecraft_mod_player_statistics.src.main.java.DatabaseManager;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
// import com.h2.jdbcx.JdbcDataSource;
|
||||||
|
|
||||||
|
public class TestDatabaseManager extends DatabaseManager {
|
||||||
|
/*
|
||||||
|
private static final String TEST_DB_USER = "root";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Connection getConnection() throws SQLException {
|
||||||
|
return DriverManager.getConnection(
|
||||||
|
config.getProperty("db.url"),
|
||||||
|
TEST_DB_USER,
|
||||||
|
System.getenv("DB_PASSWORD")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user