Skip to content

Commit

Permalink
clean up functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNavaStar committed Jul 18, 2024
1 parent a354492 commit 303b2da
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/main/java/me/mrnavastar/sqlib/Fabric.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package me.mrnavastar.sqlib;

import me.mrnavastar.sqlib.impl.Config;
import net.fabricmc.loader.api.FabricLoader;

import java.nio.file.Path;

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());
}
}
3 changes: 2 additions & 1 deletion src/main/java/me/mrnavastar/sqlib/Quilt.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package me.mrnavastar.sqlib;

import me.mrnavastar.sqlib.impl.Config;
import org.quiltmc.loader.api.QuiltLoader;

import java.nio.file.Path;

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());
}
}
12 changes: 0 additions & 12 deletions src/main/java/me/mrnavastar/sqlib/SQLib.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -36,15 +32,7 @@ public static Database getDatabase() {
}
}

protected static void init(Path localDir, Path configDir) {
database = Config.load(localDir, configDir);
}

public static List<Database> getDatabases() {
return Database.getDatabases();
}

public static void log(Level level, String message) {
LogManager.getLogger().log(level, "[SQLib] " + message);
}
}
4 changes: 3 additions & 1 deletion src/main/java/me/mrnavastar/sqlib/Velocity.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
7 changes: 6 additions & 1 deletion src/main/java/me/mrnavastar/sqlib/impl/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
}

0 comments on commit 303b2da

Please sign in to comment.