From 303b2da871c023cb30eb6f5fac2455e4797656ee Mon Sep 17 00:00:00 2001 From: MrNavaStar Date: Wed, 17 Jul 2024 20:23:23 -0600 Subject: [PATCH] clean up functions --- src/main/java/me/mrnavastar/sqlib/Fabric.java | 3 ++- src/main/java/me/mrnavastar/sqlib/Quilt.java | 3 ++- src/main/java/me/mrnavastar/sqlib/SQLib.java | 12 ------------ src/main/java/me/mrnavastar/sqlib/Velocity.java | 4 +++- src/main/java/me/mrnavastar/sqlib/impl/Config.java | 7 ++++++- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/me/mrnavastar/sqlib/Fabric.java b/src/main/java/me/mrnavastar/sqlib/Fabric.java index dbca63d..f84f02b 100644 --- a/src/main/java/me/mrnavastar/sqlib/Fabric.java +++ b/src/main/java/me/mrnavastar/sqlib/Fabric.java @@ -1,5 +1,6 @@ package me.mrnavastar.sqlib; +import me.mrnavastar.sqlib.impl.Config; import net.fabricmc.loader.api.FabricLoader; import java.nio.file.Path; @@ -7,6 +8,6 @@ public class Fabric extends SQLib { public static void init() { - init(Path.of(FabricLoader.getInstance().getGameDir() + "/sqlib"), FabricLoader.getInstance().getConfigDir()); + database = Config.load(Path.of(FabricLoader.getInstance().getGameDir() + "/sqlib"), FabricLoader.getInstance().getConfigDir()); } } \ No newline at end of file diff --git a/src/main/java/me/mrnavastar/sqlib/Quilt.java b/src/main/java/me/mrnavastar/sqlib/Quilt.java index 2dead1a..0fff294 100644 --- a/src/main/java/me/mrnavastar/sqlib/Quilt.java +++ b/src/main/java/me/mrnavastar/sqlib/Quilt.java @@ -1,5 +1,6 @@ package me.mrnavastar.sqlib; +import me.mrnavastar.sqlib.impl.Config; import org.quiltmc.loader.api.QuiltLoader; import java.nio.file.Path; @@ -7,6 +8,6 @@ public class Quilt extends SQLib { public static void init() { - init(Path.of(QuiltLoader.getGameDir() + "/sqlib"), QuiltLoader.getConfigDir()); + database = Config.load(Path.of(QuiltLoader.getGameDir() + "/sqlib"), QuiltLoader.getConfigDir()); } } diff --git a/src/main/java/me/mrnavastar/sqlib/SQLib.java b/src/main/java/me/mrnavastar/sqlib/SQLib.java index 1b2b971..5668cbf 100644 --- a/src/main/java/me/mrnavastar/sqlib/SQLib.java +++ b/src/main/java/me/mrnavastar/sqlib/SQLib.java @@ -1,11 +1,7 @@ package me.mrnavastar.sqlib; -import me.mrnavastar.sqlib.impl.Config; import me.mrnavastar.sqlib.api.database.Database; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import java.nio.file.Path; import java.util.List; public class SQLib { @@ -36,15 +32,7 @@ public static Database getDatabase() { } } - protected static void init(Path localDir, Path configDir) { - database = Config.load(localDir, configDir); - } - public static List getDatabases() { return Database.getDatabases(); } - - public static void log(Level level, String message) { - LogManager.getLogger().log(level, "[SQLib] " + message); - } } \ No newline at end of file diff --git a/src/main/java/me/mrnavastar/sqlib/Velocity.java b/src/main/java/me/mrnavastar/sqlib/Velocity.java index 246a45d..c476899 100644 --- a/src/main/java/me/mrnavastar/sqlib/Velocity.java +++ b/src/main/java/me/mrnavastar/sqlib/Velocity.java @@ -1,11 +1,13 @@ package me.mrnavastar.sqlib; +import me.mrnavastar.sqlib.impl.Config; + import java.nio.file.Path; public class Velocity extends SQLib { public static void init() { Path dir = Path.of("plugins/sqlib"); - init(dir,dir); + database = Config.load(dir,dir); } } diff --git a/src/main/java/me/mrnavastar/sqlib/impl/Config.java b/src/main/java/me/mrnavastar/sqlib/impl/Config.java index 812b97e..0ef7ff6 100644 --- a/src/main/java/me/mrnavastar/sqlib/impl/Config.java +++ b/src/main/java/me/mrnavastar/sqlib/impl/Config.java @@ -6,6 +6,7 @@ import me.mrnavastar.sqlib.api.database.PostgreSQL; import me.mrnavastar.sqlib.api.database.SQLite; import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; import java.io.File; import java.io.FileWriter; @@ -77,7 +78,7 @@ public static me.mrnavastar.sqlib.api.database.Database load(Path localDir, Path } if (!INSTANCE.validate()) { - SQLib.log(Level.ERROR, "Invalid config - Stopping"); + log(Level.ERROR, "Invalid config - Stopping"); System.exit(1); } @@ -88,4 +89,8 @@ public static me.mrnavastar.sqlib.api.database.Database load(Path localDir, Path default -> null; }; } + + public static void log(Level level, String message) { + LogManager.getLogger().log(level, "[SQLib] " + message); + } } \ No newline at end of file