diff --git a/README.md b/README.md index 536cdcd..53eebc1 100644 --- a/README.md +++ b/README.md @@ -429,14 +429,11 @@ following to your `build.gradle.kts` ```kts repositories { - maven { - url = uri("https://jitpack.io") - } + maven("https://maven.supersanta.me/snapshots") } dependencies { - // For the most recent version, use the latest commit hash - modImplementation("com.github.senseiwells:ServerReplay:da3b0e55ce") + modImplementation("me.senseiwells:server-replay:1.1.2+1.21.1") } ``` diff --git a/build.gradle.kts b/build.gradle.kts index e81eaab..f967f77 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,12 +1,13 @@ -import org.apache.commons.io.output.ByteArrayOutputStream -import java.nio.charset.Charset - plugins { - kotlin("jvm") - kotlin("plugin.serialization") version "2.0.0" - id("me.modmuss50.mod-publish-plugin") version "0.4.5" - id("com.github.johnrengelman.shadow") version "8.1.1" - id("fabric-loom") + val jvmVersion = libs.versions.fabric.kotlin.get() + .split("+kotlin.")[1] + .split("+")[0] + + kotlin("jvm").version(jvmVersion) + alias(libs.plugins.kotlin.serialization) + alias(libs.plugins.fabric.loom) + alias(libs.plugins.mod.publish) + alias(libs.plugins.shadow) `maven-publish` java } @@ -24,58 +25,35 @@ repositories { mavenCentral() } -val modVersion: String by project -val mcVersion: String by project -val parchmentVersion: String by project -val loaderVersion: String by project -val fabricVersion: String by project -val fabricKotlinVersion: String by project - -val carpetVersion: String by project -val voicechatVersion: String by project -val voicechatApiVersion: String by project -val vmpVersion: String by project -val permissionsVersion: String by project -val syncmaticaVersion: String by project - -val releaseVersion = "${modVersion}+mc${mcVersion}" + +val modVersion = "1.1.2" +val releaseVersion = "${modVersion}+mc${libs.versions.minecraft.get()}" +val mavenVersion = "${modVersion}+${libs.versions.minecraft.get()}" version = releaseVersion group = "me.senseiwells" dependencies { - minecraft("com.mojang:minecraft:${mcVersion}") + minecraft(libs.minecraft) @Suppress("UnstableApiUsage") mappings(loom.layered { officialMojangMappings() - parchment("org.parchmentmc.data:parchment-${parchmentVersion}@zip") + parchment("org.parchmentmc.data:parchment-${libs.versions.parchment.get()}@zip") }) - modImplementation("net.fabricmc:fabric-loader:${loaderVersion}") - modImplementation("net.fabricmc:fabric-language-kotlin:${fabricKotlinVersion}") - modImplementation("net.fabricmc.fabric-api:fabric-api:${fabricVersion}") - - modImplementation("com.github.gnembon:fabric-carpet:${carpetVersion}") - modCompileOnly("maven.modrinth:simple-voice-chat:fabric-${voicechatVersion}") - implementation("de.maxhenkel.voicechat:voicechat-api:${voicechatApiVersion}") - - modCompileOnly("maven.modrinth:vmp-fabric:${vmpVersion}") - modCompileOnly("com.github.sakura-ryoko:syncmatica:${syncmaticaVersion}") - - // I've had some issues with ReplayStudio and slf4j (in dev env) - // Simplest workaround that I've found is just to unzip the - // jar and yeet the org.slf4j packages then rezip the jar. - shade(modImplementation("com.github.ReplayMod:ReplayStudio:1e96fda605") { - exclude(group = "org.slf4j") - exclude(group = "it.unimi.dsi") - exclude(group = "org.apache.commons") - exclude(group = "commons-cli") - exclude(group = "com.google.guava", module = "guava-jdk5") - exclude(group = "com.google.guava", module = "guava") - exclude(group = "com.google.code.gson", module = "gson") - }) - include(modImplementation("me.lucko:fabric-permissions-api:${permissionsVersion}") { - exclude("net.fabricmc.fabric-api") - }) + modImplementation(libs.fabric.loader) + modImplementation(libs.fabric.api) + modImplementation(libs.fabric.kotlin) + + modCompileOnly(libs.carpet) + modCompileOnly(libs.vmp) + modCompileOnly(libs.syncmatica) + modCompileOnly(libs.voicechat) + implementation(libs.voicechat.api) + + shade(modImplementation(libs.replay.studio.get())!!) + includeModImplementation(libs.permissions) { + exclude(libs.fabric.api.get().group) + } } loom { @@ -83,7 +61,7 @@ loom { runs { getByName("server") { - runDir = "run/$mcVersion" + runDir = "run/${libs.versions.minecraft.get()}" } getByName("client") { @@ -92,11 +70,11 @@ loom { } } -tasks { - register("relocateResources") { - - } +java { + withSourcesJar() +} +tasks { processResources { inputs.property("version", modVersion) filesMatching("fabric.mod.json") { @@ -138,13 +116,13 @@ tasks { type = STABLE modLoaders.add("fabric") - displayName = "ServerReplay $modVersion for $mcVersion" + displayName = "ServerReplay $modVersion for ${libs.versions.minecraft.get()}" version = releaseVersion modrinth { accessToken = providers.environmentVariable("MODRINTH_API_KEY") projectId = "qCvSZ8ra" - minecraftVersions.add(mcVersion) + minecraftVersions.add(libs.versions.minecraft) requires { id = "P7dR8mSH" @@ -158,21 +136,10 @@ tasks { } } - publishing { - publications { - create("mavenJava") { - groupId = "com.github.senseiwells" - artifactId = "ServerReplay" - version = getGitHash() - from(project.components.getByName("java")) - } - } - } - register("updateReadme") { val readmes = listOf("./README.md") - val regex = Regex("""com.github.Senseiwells:ServerReplay:[a-z0-9]+""") - val replacement = "com.github.Senseiwells:ServerReplay:${getGitHash()}" + val regex = Regex("""me\.senseiwells:server-replay:[\d\.\-a-zA-Z+]+""") + val replacement = "me.senseiwells:server-replay:${mavenVersion}" for (path in readmes) { val readme = file(path) readme.writeText(readme.readText().replace(regex, replacement)) @@ -180,17 +147,41 @@ tasks { println("Successfully updated all READMEs") } -} -java { - withSourcesJar() + named("publish").configure { + finalizedBy("updateReadme") + } } -fun getGitHash(): String { - val out = ByteArrayOutputStream() - exec { - commandLine("git", "rev-parse", "--short=10", "HEAD") - standardOutput = out +publishing { + publications { + create("ServerReplay") { + groupId = "me.senseiwells" + artifactId = "server-replay" + version = mavenVersion + from(components["java"]) + } } - return out.toString(Charset.defaultCharset()).trim() + + repositories { + val mavenUrl = System.getenv("MAVEN_URL") + if (mavenUrl != null) { + maven { + url = uri(mavenUrl) + val mavenUsername = System.getenv("MAVEN_USERNAME") + val mavenPassword = System.getenv("MAVEN_PASSWORD") + if (mavenUsername != null && mavenPassword != null) { + credentials { + username = mavenUsername + password = mavenPassword + } + } + } + } + } +} + +private fun DependencyHandler.includeModImplementation(provider: Provider<*>, action: Action) { + this.include(provider, action) + this.modImplementation(provider, action) } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 7cc8a53..571f118 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,21 +2,4 @@ systemProp.org.gradle.internal.http.connectionTimeout=180000 systemProp.org.gradle.internal.http.socketTimeout=180000 kotlin.code.style=official - -loomVersion=1.7-SNAPSHOT - -mcVersion=1.21 -parchmentVersion=1.20.6:2024.06.16 -loaderVersion=0.15.11 -fabricKotlinVersion=1.11.0+kotlin.2.0.0 -permissionsVersion=0.3.1 -fabricVersion=0.100.1+1.21 -carpetVersion=1.4.147 -voicechatVersion=1.21.1-2.5.20 -voicechatApiVersion=2.5.0 -vmpVersion=0.2.0+beta.7.162+1.21 -syncmaticaVersion=1.21-sakura.6 - -modVersion=1.1.2 - org.gradle.jvmargs=-Xmx4000m \ No newline at end of file diff --git a/libs.versions.toml b/libs.versions.toml new file mode 100644 index 0000000..5b9963d --- /dev/null +++ b/libs.versions.toml @@ -0,0 +1,36 @@ +[versions] +fabric-loom = "1.7-SNAPSHOT" +mod-publish = "0.7.0" +kotlin-serialization = "1.9.21" +shadow = "8.1.1" +minecraft = "1.21.1" +fabric-loader = "0.16.5" +parchment = "1.21:2024.07.28" +fabric-api = "0.103.0+1.21.1" +fabric-kotlin = "1.11.0+kotlin.2.0.0" +permissions = "0.3.1" +carpet = "1.4.147" +voicechat = "fabric-1.21.1-2.5.20" +voicechat-api = "2.5.0" +vmp = "0.2.0+beta.7.162+1.21" +syncmatica = "1.21-sakura.6" +replay-studio = "1e96fda605" + +[libraries] +minecraft = { module = "com.mojang:minecraft" , version.ref = "minecraft" } +fabric-loader = { module = "net.fabricmc:fabric-loader" , version.ref = "fabric-loader" } +fabric-api = { module = "net.fabricmc.fabric-api:fabric-api" , version.ref = "fabric-api" } +fabric-kotlin = { module = "net.fabricmc:fabric-language-kotlin" , version.ref = "fabric-kotlin" } +permissions = { module = "me.lucko:fabric-permissions-api" , version.ref = "permissions" } +carpet = { module = "com.github.gnembon:fabric-carpet" , version.ref = "carpet" } +voicechat = { module = "maven.modrinth:simple-voice-chat" , version.ref = "voicechat" } +voicechat-api = { module = "de.maxhenkel.voicechat:voicechat-api" , version.ref = "voicechat-api" } +vmp = { module = "maven.modrinth:vmp-fabric" , version.ref = "vmp" } +syncmatica = { module = "com.github.sakura-ryoko:syncmatica" , version.ref = "syncmatica" } +replay-studio = { module = "com.github.ReplayMod:ReplayStudio" , version.ref = "replay-studio" } + +[plugins] +fabric-loom = { id = "fabric-loom", version.ref = "fabric-loom" } +kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin-serialization" } +mod-publish = { id = "me.modmuss50.mod-publish-plugin", version.ref = "mod-publish" } +shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 1192dff..87cc13c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,13 @@ rootProject.name = "ServerReplay" + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("libs.versions.toml")) + } + } +} + pluginManagement { repositories { maven("https://maven.fabricmc.net/") { @@ -7,14 +16,4 @@ pluginManagement { mavenCentral() gradlePluginPortal() } - - val loomVersion: String by settings - val fabricKotlinVersion: String by settings - plugins { - id("fabric-loom") version loomVersion - id("org.jetbrains.kotlin.jvm") version - fabricKotlinVersion - .split("+kotlin.")[1] // Grabs the sentence after `+kotlin.` - .split("+")[0] // Ensures sentences like `+build.1` are ignored - } } \ No newline at end of file diff --git a/src/main/kotlin/me/senseiwells/replay/recorder/ReplayRecorder.kt b/src/main/kotlin/me/senseiwells/replay/recorder/ReplayRecorder.kt index bf2817c..8fbdb75 100644 --- a/src/main/kotlin/me/senseiwells/replay/recorder/ReplayRecorder.kt +++ b/src/main/kotlin/me/senseiwells/replay/recorder/ReplayRecorder.kt @@ -84,7 +84,7 @@ import net.minecraft.network.protocol.Packet as MinecraftPacket */ abstract class ReplayRecorder( val server: MinecraftServer, - public val profile: GameProfile, + val profile: GameProfile, private val recordings: Path ) { private val packets by lazy { Object2ObjectOpenHashMap() }