From bd15d1f244fe8fe58eb984a6c6277a967c8f08dd Mon Sep 17 00:00:00 2001 From: zontreck Date: Tue, 30 Apr 2024 15:13:01 -0700 Subject: [PATCH] Produce a test build to attempt to fix database not being properly set --- gradle.properties | 2 +- .../config/sections/DatabaseSection.java | 6 +++--- .../libzontreck/memory/world/DatabaseWrapper.java | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 71124e1..1631c86 100644 --- a/gradle.properties +++ b/gradle.properties @@ -53,7 +53,7 @@ mod_name=Zontreck's Library Mod # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GPLv3 # The mod version. See https://semver.org/ -mod_version=1201.13.043024.0404 +mod_version=1201.13.043024.1512 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/dev/zontreck/libzontreck/config/sections/DatabaseSection.java b/src/main/java/dev/zontreck/libzontreck/config/sections/DatabaseSection.java index a89a298..774b5a5 100644 --- a/src/main/java/dev/zontreck/libzontreck/config/sections/DatabaseSection.java +++ b/src/main/java/dev/zontreck/libzontreck/config/sections/DatabaseSection.java @@ -16,13 +16,11 @@ public class DatabaseSection public String user = "root"; public String password = ""; public String host = "localhost:3306"; // IP:port - public String database = "savedBlocks"; + public String database = ""; public int version; public static final int VERSION = 1; - private boolean migrated=false; - public static DatabaseSection deserialize(CompoundTag tag) { DatabaseSection ret = new DatabaseSection(); @@ -42,6 +40,8 @@ public class DatabaseSection ret.database = tag.getString(TAG_DATABASE); } + + ret.version = VERSION; return ret; } diff --git a/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java b/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java index 17fc901..f0c1bc8 100644 --- a/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java +++ b/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java @@ -33,6 +33,9 @@ public class DatabaseWrapper { public static void start() { instance = new DatabaseWrapper(); try { + LibZontreck.LOGGER.info("Connecting to database..."); + LibZontreck.LOGGER.info("jdbc:db ://" + ServerConfig.database.user + "@" + ServerConfig.database.host + "/" + ServerConfig.database.database); + instance.connect(ServerConfig.database.host, ServerConfig.database.user, ServerConfig.database.password, ServerConfig.database.database); } catch (SQLException e) { throw new RuntimeException(e); @@ -40,6 +43,17 @@ public class DatabaseWrapper { } public void connect(String url, String username, String password, String database) throws SQLException { + if(database.isBlank()) + { + ServerConfig.init(); + if(ServerConfig.database.database.isBlank()) + { + throw new SQLException("Failed to connect to database"); + } else { + start(); + return; + } + } try { // Try MariaDB JDBC driver Class.forName("org.mariadb.jdbc.Driver");