Skip to content

Commit

Permalink
Fabric port
Browse files Browse the repository at this point in the history
#8 from IxPrumxI/fabric
  • Loading branch information
Vankka authored Feb 3, 2025
2 parents 785aafb + 8095977 commit 9f80831
Show file tree
Hide file tree
Showing 42 changed files with 2,290 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ hs_err_pid*
# run-* Gradle tasks
**/loader/run/
**/velocity/run/
**/fabric/run

# Fabric mapping migration
**/fabric/remappedSrc
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
alias(libs.plugins.run.paper) apply false
alias(libs.plugins.run.waterfall) apply false
alias(libs.plugins.run.velocity) apply false
alias(libs.plugins.fabric.loom) apply false
}

version = '3.0.0-SNAPSHOT'
Expand Down
6 changes: 4 additions & 2 deletions buildscript/final.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Buildscript for loaders & standalone platforms

task copyOutput(type: Copy) {
tasks.register('copyOutput', Copy) {
from(this.shadowJar)
into rootProject.file('jars')
}
Expand All @@ -14,5 +14,7 @@ shadowJar {
rename { fileName -> 'LICENSE.txt' }
}

finalizedBy copyOutput
if (it.project.name != "fabric") {
finalizedBy copyOutput
}
}
2 changes: 0 additions & 2 deletions buildscript/relocations.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
'net.kyori.adventure.ansi',
'net.kyori.adventure.examination',
'net.kyori.adventure.option',
'net.kyori.adventure.platform',
'net.kyori.adventure.text.serializer',

// EnhancedLegacyText, MCDiscordReserializer
'dev.vankka.enhancedlegacytext',
Expand Down
2 changes: 2 additions & 0 deletions bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ allprojects {

[
'net.kyori',
'net.kyori.adventure.platform',
'net.kyori.adventure.text.serializer',
'me.lucko.commodore'
].each {
tasks.shadowJar.relocate it, 'com.discordsrv.dependencies.' + it
Expand Down
4 changes: 3 additions & 1 deletion bungee/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ shadowJar {

configure {
[
'net.kyori'
'net.kyori',
'net.kyori.adventure.platform',
'net.kyori.adventure.text.serializer'
].each {
relocate it, 'com.discordsrv.dependencies.' + it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ public boolean isAcceptableCommand(DiscordGuildMember member, DiscordUser user,

for (String configCommand : commands) {
if (isCommandMatch(configCommand, command, suggestions, helper) != blacklist) {
return true;
return blacklist;
}
}
return false;
return !blacklist;
}
}
89 changes: 89 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
apply from: rootProject.file('buildscript/standalone.gradle')
apply plugin: 'fabric-loom'

configurations.configureEach {
resolutionStrategy {
force "org.slf4j:slf4j-api:1.7.36" // Introduced by Minecraft itself
}
}

java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

processResources {
filesMatching('**/fabric.mod.json') {
expand 'VERSION': project.version, 'MINECRAFT_VERSION': libs.fabric.minecraft.get().version, 'LOADER_VERSION': libs.fabric.loader.get().version
}
dependsOn generateRuntimeDownloadResourceForRuntimeDownloadOnly
}

shadowJar {
configurations = [project.configurations.shadow]
mergeServiceFiles()
}

tasks.register('copyRemappedJar', Copy) {
from remapJar.archiveFile
into rootProject.file('jars')
}

remapJar {
dependsOn shadowJar
mustRunAfter shadowJar
inputFile = shadowJar.archiveFile
archiveBaseName = 'DiscordSRV-Fabric'
archiveClassifier = jar.archiveClassifier

finalizedBy copyRemappedJar
}

artifacts {
archives remapJar
shadow shadowJar
}

loom {
serverOnlyMinecraftJar()
accessWidenerPath = file('src/main/resources/discordsrv.accesswidener')
}

repositories {
exclusiveContent {
forRepository {
maven { url = 'https://maven.fabricmc.net/' }
}
filter {
includeGroup 'net.fabricmc'
}
}
}

dependencies {
// To change the versions see the settings.gradle file
minecraft(libs.fabric.minecraft)
mappings(variantOf(libs.fabric.yarn) { classifier("v2") })
compileOnly(libs.fabric.loader)

// Fabric API
modImplementation(libs.fabric.api)
modImplementation(libs.fabric.permissions.api)
include(libs.fabric.permissions.api)

// API
annotationProcessor project(':api')
shadow project(':common:common-api')

// Common
shadow project(':common')

// Adventure
modImplementation(libs.adventure.platform.fabric)
include(libs.adventure.platform.fabric)

// DependencyDownload
shadow(libs.mcdependencydownload.fabric) {
exclude module: 'fabric-loader'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* This file is part of DiscordSRV, licensed under the GPLv3 License
* Copyright (c) 2016-2025 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.discordsrv.fabric;

import com.discordsrv.common.abstraction.bootstrap.IBootstrap;
import com.discordsrv.common.abstraction.bootstrap.LifecycleManager;
import com.discordsrv.common.core.logging.Logger;
import com.discordsrv.common.core.logging.backend.impl.Log4JLoggerImpl;
import dev.vankka.dependencydownload.classpath.ClasspathAppender;
import dev.vankka.mcdependencydownload.fabric.classpath.FabricClasspathAppender;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.kyori.adventure.platform.modcommon.MinecraftServerAudiences;
import net.minecraft.GameVersion;
import net.minecraft.MinecraftVersion;
import net.minecraft.server.MinecraftServer;
import org.apache.logging.log4j.LogManager;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;

public class DiscordSRVFabricBootstrap implements DedicatedServerModInitializer, IBootstrap {

private final Logger logger;
private final ClasspathAppender classpathAppender;
private final LifecycleManager lifecycleManager;
private final Path dataDirectory;
private MinecraftServer minecraftServer;
private FabricDiscordSRV discordSRV;
private MinecraftServerAudiences adventure;

public DiscordSRVFabricBootstrap() {
this.logger = new Log4JLoggerImpl(LogManager.getLogger("DiscordSRV"));
this.classpathAppender = new FabricClasspathAppender();
this.dataDirectory = FabricLoader.getInstance().getConfigDir().resolve("DiscordSRV");
try {
this.lifecycleManager = new LifecycleManager(
this.logger,
dataDirectory,
Collections.singletonList("dependencies/runtimeDownload-fabric.txt"),
classpathAppender
);
} catch (IOException e) {
throw new RuntimeException(e);
}
this.minecraftServer = null;
this.adventure = null;
}

@Override
public void onInitializeServer() {
ServerLifecycleEvents.SERVER_STARTING.register(minecraftServer -> {
this.minecraftServer = minecraftServer;
this.adventure = MinecraftServerAudiences.of(minecraftServer);
lifecycleManager.loadAndEnable(() -> this.discordSRV = new FabricDiscordSRV(this));
});

ServerLifecycleEvents.SERVER_STARTED.register(minecraftServer -> this.discordSRV.runServerStarted());

ServerLifecycleEvents.SERVER_STOPPING.register(minecraftServer -> {
if (this.discordSRV != null) this.discordSRV.runDisable();
});
}

@Override
public Logger logger() {
return logger;
}

@Override
public ClasspathAppender classpathAppender() {
return classpathAppender;
}

@Override
public ClassLoader classLoader() {
return getClass().getClassLoader();
}

@Override
public LifecycleManager lifecycleManager() {
return lifecycleManager;
}

@Override
public Path dataDirectory() {
return dataDirectory;
}

@Override
public String platformVersion() {
GameVersion version = MinecraftVersion.CURRENT;
return version.getName() + " (from Fabric)"; //TODO: get current build version for Fabric
}

public MinecraftServer getServer() {
return minecraftServer;
}

public FabricDiscordSRV getDiscordSRV() {
return discordSRV;
}

public MinecraftServerAudiences getAdventure() {
return adventure;
}
}
Loading

0 comments on commit 9f80831

Please sign in to comment.