Skip to content

Commit

Permalink
feat: added fabric support (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
confuser authored Jan 5, 2025
1 parent 2eb8f0b commit 92f0faa
Show file tree
Hide file tree
Showing 53 changed files with 2,453 additions and 152 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ jobs:
matrix:
include:
- storageType: mariadb
java: 8
- storageType: h2
java: 8
- storageType: mariadb
java: 11
- storageType: h2
java: 11
java: 21
# - storageType: h2 # disabled for now due to memory issues
# java: 21

steps:
- uses: actions/checkout@v2
Expand All @@ -38,14 +34,21 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- uses: actions/cache@v4
with:
path: |
.gradle/loom-cache
key: ${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle-${{ matrix.java }}-

- name: Execute Gradle build
env:
STORAGE_TYPE: ${{ matrix.storageType }}
run: ./gradlew build --info

- name: Publish to Maven Central
# only publish once
if: github.ref == 'refs/heads/master' && matrix.java == '8' && matrix.storageType == 'h2'
if: github.ref == 'refs/heads/master' && matrix.java == '21' && matrix.storageType == 'mariadb'
env:
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPEUSERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPEPASSWORD }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</p>
<p align="center">
<a aria-label="Tests status" href="https://github.com/BanManagement/BanManager/actions/workflows/build.yml">
<img alt="" src="https://img.shields.io/github/workflow/status/BanManagement/BanManager/Java%20CI?label=Tests&style=for-the-badge&labelColor=000000">
<img alt="" src="https://img.shields.io/github/actions/workflow/status/BanManagement/BanManager/build.yml?branch=master&label=Tests&style=for-the-badge&labelColor=000000">
</a>
<a aria-label="Join the community on Discord" href="https://discord.gg/59bsgZB">
<img alt="" src="https://img.shields.io/discord/664808009393766401?label=Support&style=for-the-badge&labelColor=000000&color=7289da">
Expand All @@ -38,7 +38,7 @@
To learn more about configuration, usage and features of BanManager, take a look at [the website](https://banmanagement.com/docs/banmanager/configuration) or view [the website demo](https://demo.banmanagement.com).

## Requirements
- Java 8+
- Java 8+ (JDK21+ required to build from source)
- CraftBukkit/Spigot/Paper, BungeeCord or Sponge for Minecraft 1.7.2+
- Optionally [MySQL or MariaDB](https://banmanagement.com/docs/banmanager/install#setup-shared-database-optional)

Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ logger.lifecycle("""
""")

plugins {
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id("io.freefair.aggregate-javadoc") version "6.3.0"
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
id("io.freefair.aggregate-javadoc") version "8.11"
}

nexusPublishing {
Expand Down
13 changes: 9 additions & 4 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ repositories {
name = "sponge"
url = uri("https://repo.spongepowered.org/repository/maven-public/")
}
maven {
name = "Fabric"
url = uri("https://maven.fabricmc.net/")
}
}

dependencies {
implementation(gradleApi())
implementation("com.github.jengelman.gradle.plugins:shadow:6.1.0")
implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.21.0")
implementation("org.spongepowered:spongegradle-plugin-development:2.0.0")
}
implementation("com.gradleup.shadow:com.gradleup.shadow.gradle.plugin:9.0.0-beta4")
implementation("org.jfrog.buildinfo:build-info-extractor-gradle:5.2.5")
implementation("org.spongepowered:spongegradle-plugin-development:2.3.0")
implementation("fabric-loom:fabric-loom.gradle.plugin:1.9-SNAPSHOT")
}
8 changes: 4 additions & 4 deletions buildSrc/src/main/kotlin/CommonConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ fun Project.applyCommonConfiguration() {
}

dependencies {
"compileOnly"("org.projectlombok:lombok:1.18.22")
"annotationProcessor"("org.projectlombok:lombok:1.18.22")
"compileOnly"("org.projectlombok:lombok:1.18.36")
"annotationProcessor"("org.projectlombok:lombok:1.18.36")

"testCompileOnly"("org.projectlombok:lombok:1.18.22")
"testAnnotationProcessor"("org.projectlombok:lombok:1.18.22")
"testCompileOnly"("org.projectlombok:lombok:1.18.36")
"testAnnotationProcessor"("org.projectlombok:lombok:1.18.36")
}

configurations.all {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/LibsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fun Project.applyLibrariesConfiguration() {
apply(plugin = "java-base")
apply(plugin = "maven-publish")
apply(plugin = "signing")
apply(plugin = "com.github.johnrengelman.shadow")
apply(plugin = "com.gradleup.shadow")

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/PlatformConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fun Project.applyPlatformAndCoreConfiguration() {
}

fun Project.applyShadowConfiguration() {
apply(plugin = "com.github.johnrengelman.shadow")
apply(plugin = "com.gradleup.shadow")
tasks.named<ShadowJar>("shadowJar") {
archiveClassifier.set("dist")
dependencies {
Expand Down
18 changes: 11 additions & 7 deletions bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ tasks.named<ShadowJar>("shadowJar") {
dependencies {
include(dependency(":BanManagerCommon"))
include(dependency(":BanManagerLibs"))
relocate("org.bstats", "me.confuser.banmanager.common.bstats") {
include(dependency("org.bstats:"))
}
relocate("org.slf4j", "me.confuser.banmanager.common.slf4j") {
include(dependency("org.slf4j:"))
}

include(dependency("org.bstats:.*:.*"))
include(dependency("org.slf4j:.*:.*"))

relocate("org.bstats", "me.confuser.banmanager.common.bstats")
relocate("org.slf4j", "me.confuser.banmanager.common.slf4j")
}

exclude("GradleStart**")
Expand All @@ -132,8 +132,12 @@ tasks.named<ShadowJar>("shadowJar") {
exclude("org/intellij/**")
exclude("org/jetbrains/**")
exclude("bungeecord.yml")
exclude("velocity.yml")

minimize()
minimize {
exclude(dependency("org.bstats:.*:.*"))
exclude(dependency("org.slf4j:.*:.*"))
}
}

tasks.named("assemble").configure {
Expand Down
11 changes: 7 additions & 4 deletions bungee/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ tasks.named<ShadowJar>("shadowJar") {
dependencies {
include(dependency(":BanManagerCommon"))
include(dependency(":BanManagerLibs"))
relocate("org.bstats", "me.confuser.banmanager.common.bstats") {
include(dependency("org.bstats:"))
}
include(dependency("org.bstats:.*:.*"))

relocate("org.bstats", "me.confuser.banmanager.common.bstats")
}
exclude("GradleStart**")
exclude(".cache");
Expand All @@ -105,8 +105,11 @@ tasks.named<ShadowJar>("shadowJar") {
exclude("META-INF/maven/**")
exclude("org/intellij/**")
exclude("org/jetbrains/**")
exclude("velocity.yml")

minimize()
minimize {
exclude(dependency("org.bstats:.*:.*"))
}
}

tasks.named("assemble").configure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,19 @@ public final void enable() throws Exception {
results2.close();
}

try {
metrics.submitStorageType(config.getLocalDb().getStorageType());
metrics.submitDiscordMode(discordConfig.isHooksEnabled());
metrics.submitGeoMode(geoIpConfig.isEnabled());
metrics.submitGlobalMode(config.getGlobalDb().isEnabled());
metrics.submitOnlineMode(config.isOnlineMode());
if (storageVersion != null) {
metrics.submitStorageVersion(storageVersion);
if (metrics != null) {
try {
metrics.submitStorageType(config.getLocalDb().getStorageType());
metrics.submitDiscordMode(discordConfig.isHooksEnabled());
metrics.submitGeoMode(geoIpConfig.isEnabled());
metrics.submitGlobalMode(config.getGlobalDb().isEnabled());
metrics.submitOnlineMode(config.isOnlineMode());
if (storageVersion != null) {
metrics.submitStorageVersion(storageVersion);
}
} catch (Exception e) {
logger.warning("Failed to submit stats, ignoring");
}
} catch (Exception e) {
logger.warning("Failed to submit stats, ignoring");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ public CommandParser getParser(String[] args) throws NoSuchMethodException, Ille
args, start);
}

public CommandParser getParser(List<String> args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
return getParser(args.toArray(new String[0]));
}

public List<String> handlePlayerNameTabComplete(CommonSender sender, String[] args) {
ArrayList<String> mostLike = new ArrayList<>();
if(args.length == 1) {
Expand Down
141 changes: 141 additions & 0 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.fabricmc.loom.task.RemapJarTask

plugins {
`java-library`
`maven-publish`
`signing`
`fabric-loom`
}

applyPlatformAndCoreConfiguration()
applyShadowConfiguration()

publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])

pom {
name.set("BanManagerFabric")
description.set("BanManager for Fabric")
url.set("https://github.com/BanManagement/BanManager/")
licenses {
license {
name.set("Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales")
url.set("https://github.com/BanManagement/BanManager/blob/master/LICENCE")
}
}
developers {
developer {
id.set("confuser")
name.set("James Mortemore")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:git://github.com/BanManagement/BanManager.git")
developerConnection.set("scm:git:ssh://[email protected]/BanManagement/BanManager.git")
url.set("https://github.com/BanManagement/BanManager/")
}
}
}
}
}

signing {
if (project.findProperty("signingKey")?.toString()?.toBoolean() == true) {
useInMemoryPgpKeys(findProperty("signingKey")?.toString(), findProperty("signingPassword")?.toString())

sign(publishing.publications["mavenJava"])
}
}

repositories {
maven {
name = "Fabric"
url = uri("https://maven.fabricmc.net/")
}
}

configurations {
compileClasspath.get().extendsFrom(create("shadeOnly"))
}

dependencies {
minecraft("com.mojang:minecraft:1.21.4")
mappings("net.fabricmc:yarn:1.21.4+build.1:v2")
modImplementation("net.fabricmc:fabric-loader:0.16.9")

val modules = listOf(
"fabric-api-base",
"fabric-command-api-v2",
"fabric-events-interaction-v0",
"fabric-lifecycle-events-v1",
"fabric-message-api-v1",
"fabric-networking-api-v1",
"fabric-entity-events-v1"
)

modules.forEach {
modImplementation(fabricApi.module(it, "0.111.0+1.21.4"))
}

modImplementation("me.lucko:fabric-permissions-api:0.3.1")

api(project(":BanManagerCommon"))
}

tasks.named<Copy>("processResources") {
val internalVersion = project.ext["internalVersion"]

inputs.property("internalVersion", internalVersion)

filesMatching(listOf("plugin.yml", "fabric.mod.json")) {
expand("internalVersion" to internalVersion, "mainPath" to "me.confuser.banmanager.fabric.BMFabricPlugin")
}
}

tasks.named<Jar>("jar") {
val projectVersion = project.version
inputs.property("projectVersion", projectVersion)
manifest {
attributes("Implementation-Version" to projectVersion)
}
}

tasks.named<ShadowJar>("shadowJar") {
configurations = listOf(project.configurations["shadeOnly"], project.configurations["runtimeClasspath"])

archiveBaseName.set("BanManagerFabric")
archiveClassifier.set("")
archiveVersion.set("")

dependencies {
include(dependency(":BanManagerCommon"))
include(dependency(":BanManagerLibs"))
}
exclude("GradleStart**")
exclude(".cache");
exclude("LICENSE*")
exclude("META-INF/services/**")
exclude("META-INF/maven/**")
exclude("org/intellij/**")
exclude("org/jetbrains/**")
exclude("/mappings/*")

minimize()
}

tasks.named<RemapJarTask>("remapJar") {
dependsOn(tasks.named<ShadowJar>("shadowJar"))

inputFile.set(tasks.named<ShadowJar>("shadowJar").get().archiveFile)
archiveBaseName.set("BanManagerFabric")
archiveClassifier.set("")
archiveVersion.set("")
}

tasks.named("assemble").configure {
dependsOn("shadowJar")
}
Loading

0 comments on commit 92f0faa

Please sign in to comment.