-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#8 from IxPrumxI/fabric
- Loading branch information
Showing
42 changed files
with
2,290 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
125
fabric/src/main/java/com/discordsrv/fabric/DiscordSRVFabricBootstrap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.