Skip to content

Commit

Permalink
add forge support!
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNavaStar committed Jan 22, 2024
1 parent 0ec9c28 commit e22b3a8
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 25 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ group = project.maven_group

repositories {
maven { url "https://api.modrinth.com/maven" }
maven { url "https://maven.minecraftforge.net" }
maven { url "https://repo.papermc.io/repository/maven-public/" }
maven {
name = "sonatype-oss-snapshots1"
Expand All @@ -27,6 +28,9 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Forge
implementation "net.minecraftforge:javafmllanguage:${project.forge_version}"

// Paper
compileOnly "io.papermc.paper:paper-api:${project.paper_version}"
modImplementation "net.kyori:adventure-platform-fabric:${project.adventure_version}"
Expand All @@ -50,6 +54,8 @@ shadowJar {

dependencies {
mergeServiceFiles()
exclude(dependency('org.slf4j:.*:.*'))
exclude(dependency('net.java.dev.jna:.*:.*'))
}
}

Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ yarn_mappings=1.20.4+build.3
loader_version=0.15.6
fabric_version=0.95.0+1.20.4

# Forge Properties
# check this on https://files.minecraftforge.net/net/minecraftforge/forge/
forge_version=1.20.4-49.0.11

# Paper
# check this on https://repo.papermc.io/#browse/browse:maven-public:io%2Fpapermc%2Fpaper%2Fpaper-api
paper_version=1.20.4-R0.1-SNAPSHOT
Expand Down
1 change: 0 additions & 1 deletion src/main/java/me/mrnavastar/sqlib/DataContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.StringNbtReader;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
Expand Down
17 changes: 1 addition & 16 deletions src/main/java/me/mrnavastar/sqlib/Fabric.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
package me.mrnavastar.sqlib;

import me.mrnavastar.sqlib.database.Database;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint;

import java.nio.file.Path;

public class Fabric extends SQLib implements PreLaunchEntrypoint, DedicatedServerModInitializer, ClientModInitializer {
public class Fabric extends SQLib implements PreLaunchEntrypoint {

@Override
public void onPreLaunch() {
init(Path.of(FabricLoader.getInstance().getGameDir() + "/sqlib"), FabricLoader.getInstance().getConfigDir());
}

@Override
public void onInitializeServer() {
ServerLifecycleEvents.SERVER_STOPPING.register(server -> databases.forEach(Database::close));
}

@Override
public void onInitializeClient() {
ClientLifecycleEvents.CLIENT_STOPPING.register(client -> databases.forEach(Database::close));
}
}
13 changes: 13 additions & 0 deletions src/main/java/me/mrnavastar/sqlib/Forge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.mrnavastar.sqlib;

import net.minecraftforge.fml.common.Mod;

import java.nio.file.Path;

@Mod(SQLib.MOD_ID)
public class Forge extends SQLib {

public Forge() {
init(Path.of("./sqlib"), Path.of("./config"));
}
}
6 changes: 0 additions & 6 deletions src/main/java/me/mrnavastar/sqlib/Paper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.mrnavastar.sqlib;

import me.mrnavastar.sqlib.database.Database;
import org.bukkit.plugin.java.JavaPlugin;

public class Paper extends JavaPlugin {
Expand All @@ -9,9 +8,4 @@ public class Paper extends JavaPlugin {
public void onLoad() {
SQLib.init(getDataFolder().toPath(), getDataFolder().toPath());
}

@Override
public void onDisable() {
SQLib.getAllDatabases().forEach(Database::close);
}
}
6 changes: 4 additions & 2 deletions src/main/java/me/mrnavastar/sqlib/SQLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

public class SQLib {

public static final String MOD_ID = "SQLib";
public static final String MOD_ID = "sqlib";
public static final Gson GSON = new Gson();

protected static final ArrayList<Database> databases = new ArrayList<>();
private static final ArrayList<Database> databases = new ArrayList<>();
@Getter
protected static Database database;
protected static SQLibConfig config = new SQLibConfig();
Expand Down Expand Up @@ -72,6 +72,8 @@ else if (config.database.type.equalsIgnoreCase("MYSQL")) {

database = new MySQLDatabase(config.database.name, config.mysql.address, String.valueOf(config.mysql.port), config.mysql.username, config.mysql.password);
}

Runtime.getRuntime().addShutdownHook(new Thread(() -> databases.forEach(Database::close)));
}

public static void registerDatabase(Database database) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
modLoader = "javafml"
loaderVersion = "[36,)"
license = "CC0-1.0"
issueTrackerURL="https://github.com/MrNavaStar/SQLib/issues"

[[mods]]
modId = "sqlib"
version = "0.debug-build"
displayName = "SQLib"
displayURL="https://github.com/MrNavaStar/SQLib"
logoFile="assets/sqlib/icon.png"
authors="MrNavaStar"
description = 'A simple SQL wrapper with a focus on Minecraft use cases'

displayTest="IGNORE_ALL_VERSION"
6 changes: 6 additions & 0 deletions src/main/resources/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"description": "ProtoWeaver",
"pack_format": 8
}
}

0 comments on commit e22b3a8

Please sign in to comment.