From 378f44b76963e3d40874b12898727d3dde8ac298 Mon Sep 17 00:00:00 2001 From: zontreck Date: Tue, 23 Apr 2024 22:02:28 -0700 Subject: [PATCH] Fix a crash --- gradle.properties | 2 +- .../libzontreck/memory/world/DatabaseWrapper.java | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/gradle.properties b/gradle.properties index 23d1db4..771ae1a 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.042324.2051 +mod_version=1201.13.042324.2158 # 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/memory/world/DatabaseWrapper.java b/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java index 8902578..2e870b1 100644 --- a/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java +++ b/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java @@ -10,11 +10,6 @@ public class DatabaseWrapper { private Connection connection; private static DatabaseWrapper instance; - private static boolean hasDatabase = false; - - private static void setHasDatabase(boolean value) { - hasDatabase = value; - } public static DatabaseWrapper get() { if (instance == null) @@ -28,7 +23,7 @@ public class DatabaseWrapper { * @return */ public static boolean databaseIsAvailable() { - return hasDatabase; + return instance.connection!=null; } public DatabaseWrapper() { @@ -39,9 +34,7 @@ public class DatabaseWrapper { instance = new DatabaseWrapper(); try { instance.connect(ServerConfig.database.host, ServerConfig.database.user, ServerConfig.database.password); - setHasDatabase(true); } catch (SQLException e) { - setHasDatabase(false); throw new RuntimeException(e); } } @@ -71,8 +64,7 @@ public class DatabaseWrapper { Class.forName("org.sqlite.JDBC"); connection = DriverManager.getConnection("jdbc:sqlite:" + url); } catch (ClassNotFoundException | SQLException exc) { - LibZontreck.LOGGER.warn("Failed to connect via SQLite: " + e.getMessage() + "; If you require the use of the block queues, please check the above warnings for explanation on cause. It could be that you do not have the relevant JDBC installed in your server mods list."); - throw new SQLException("Failed to connect to database: " + exc.getMessage()); + LibZontreck.LOGGER.error("Failed to connect via SQLite: " + e.getMessage() + "; If you require the use of the block queues, please check the above warnings for explanation on cause. It could be that you do not have the relevant JDBC installed in your server mods list."); } } }