Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build a Mojang mapped jar in addition to the reobf one, publish both to Modrinth with correct metadata #2981

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/announce-release-on-discord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ jobs:
""
"The download is available at:"
"- Spigot: <https://www.spigotmc.org/resources/13932/>"
"- Modrinth: <https://modrinth.com/plugin/fastasyncworldedit/version/${{ github.event.release.tag_name }}>"
"- Modrinth: <https://modrinth.com/plugin/fastasyncworldedit>"
"- CurseForge: <https://www.curseforge.com/minecraft/bukkit-plugins/fawe>"
2 changes: 1 addition & 1 deletion .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: FastAsyncWorldEdit-SNAPSHOT
path: worldedit-bukkit/build/libs/FastAsyncWorldEdit-Bukkit-*.jar
path: worldedit-bukkit/build/libs/FastAsyncWorldEdit-*.jar
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: FastAsyncWorldEdit-Bukkit-SNAPSHOT
path: worldedit-bukkit/build/libs/FastAsyncWorldEdit-Bukkit-*.jar
path: worldedit-bukkit/build/libs/FastAsyncWorldEdit-*.jar
- name: Publish to Modrinth
if: ${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/main'}}
run: ./gradlew modrinth
run: ./gradlew publishMods
env:
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/upload-release-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ jobs:
- name: Upload Release Assets
uses: AButler/[email protected]
with:
files: 'worldedit-bukkit/build/libs/FastAsyncWorldEdit-Bukkit-*.jar'
files: 'worldedit-bukkit/build/libs/FastAsyncWorldEdit-*.jar'
repo-token: ${{ secrets.GITHUB_TOKEN }}
release-tag: ${{ github.event.release.tag_name }}
4 changes: 4 additions & 0 deletions buildSrc/src/main/kotlin/AdapterConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ fun Project.applyPaperweightAdapterConfiguration() {
tasks.named("assemble") {
dependsOn("reobfJar")
}

tasks.named("javadoc") {
enabled = false
}
}
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/PlatformConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.the
import org.gradle.kotlin.dsl.withType
import org.gradle.plugins.signing.SigningExtension

fun Project.applyPlatformAndCoreConfiguration() {
Expand Down Expand Up @@ -132,7 +133,7 @@ fun Project.applyPlatformAndCoreConfiguration() {
}

fun Project.applyShadowConfiguration() {
tasks.named<ShadowJar>("shadowJar") {
tasks.withType<ShadowJar>().configureEach {
dependencies {
include(project(":worldedit-libs:core"))
include(project(":worldedit-libs:${project.name.replace("worldedit-", "")}"))
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mockito = "5.14.2"

# Gradle plugins
pluginyml = "0.6.0"
minotaur = "2.8.7"
mod-publish-plugin = "0.7.4"

[libraries]
# Minecraft expectations
Expand Down Expand Up @@ -127,4 +127,4 @@ log4jCore = { group = "org.apache.logging.log4j", name = "log4j-core", version.r

[plugins]
pluginyml = { id = "net.minecrell.plugin-yml.bukkit", version.ref = "pluginyml" }
minotaur = { id = "com.modrinth.minotaur", version.ref = "minotaur" }
mod-publish-plugin = { id = "me.modmuss50.mod-publish-plugin", version.ref = "mod-publish-plugin" }
109 changes: 87 additions & 22 deletions worldedit-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import io.papermc.paperweight.userdev.attribute.Obfuscation
import me.modmuss50.mpp.ReleaseType

plugins {
`java-library`
alias(libs.plugins.minotaur)
alias(libs.plugins.mod.publish.plugin)
}

project.description = "Bukkit"
Expand Down Expand Up @@ -47,21 +48,26 @@ val localImplementation = configurations.create("localImplementation") {
}

val adapters = configurations.create("adapters") {
description = "Adapters to include in the JAR"
description = "Adapters to include in the JAR (Mojmap)"
isCanBeConsumed = false
isCanBeResolved = true
shouldResolveConsistentlyWith(configurations["runtimeClasspath"])
attributes {
attribute(Obfuscation.OBFUSCATION_ATTRIBUTE,
if ((project.findProperty("enginehub.obf.none") as String?).toBoolean()) {
objects.named(Obfuscation.NONE)
} else {
objects.named(Obfuscation.OBFUSCATED)
}
)
attribute(Obfuscation.OBFUSCATION_ATTRIBUTE, objects.named(Obfuscation.NONE))
}
}

val adaptersReobf = configurations.create("adaptersReobf") {
description = "Adapters to include in the JAR (Spigot-Mapped)"
isCanBeConsumed = false
isCanBeResolved = true
shouldResolveConsistentlyWith(configurations["runtimeClasspath"])
attributes {
attribute(Obfuscation.OBFUSCATION_ATTRIBUTE, objects.named(Obfuscation.OBFUSCATED))
}
extendsFrom(adapters)
}

dependencies {
// Modules
api(projects.worldeditCore)
Expand Down Expand Up @@ -141,9 +147,37 @@ tasks.named<Jar>("jar") {

addJarManifest(WorldEditKind.Plugin, includeClasspath = true)

tasks.register<ShadowJar>("reobfShadowJar") {
archiveFileName.set("${rootProject.name}-Bukkit-${project.version}.${archiveExtension.getOrElse("jar")}")
configurations = listOf(
project.configurations.runtimeClasspath.get(), // as is done by shadow for the default shadowJar
adaptersReobf
)

// as is done by shadow for the default shadowJar
from(sourceSets.main.map { it.output })
manifest.inheritFrom(tasks.jar.get().manifest)
exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "module-info.class")

manifest {
attributes(
"FAWE-Plugin-Jar-Type" to "spigot"
)
}
}

tasks.named<ShadowJar>("shadowJar") {
archiveFileName.set("${rootProject.name}-Paper-${project.version}.${archiveExtension.getOrElse("jar")}")
configurations.add(adapters)
archiveFileName.set("${rootProject.name}-Bukkit-${project.version}.${archiveExtension.getOrElse("jar")}")
manifest {
attributes(
"paperweight-mappings-namespace" to "mojang",
"FAWE-Plugin-Jar-Type" to "mojang"
)
}
}

tasks.withType<ShadowJar>().configureEach {
dependencies {
// In tandem with not bundling log4j, we shouldn't relocate base package here.
// relocate("org.apache.logging", "com.sk89q.worldedit.log4j")
Expand Down Expand Up @@ -198,20 +232,51 @@ tasks.named<ShadowJar>("shadowJar") {

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

tasks {
modrinth {
token.set(System.getenv("MODRINTH_TOKEN"))
publishMods {
displayName.set("${project.version}")
version.set("${project.version}")
type.set(ReleaseType.STABLE)
changelog.set("The changelog is available on GitHub: https://github.com/IntellectualSites/" +
"FastAsyncWorldEdit/releases/tag/${project.version}")

val common = modrinthOptions {
accessToken.set(System.getenv("MODRINTH_TOKEN"))
projectId.set("fastasyncworldedit")
versionName.set("${project.version}")
versionNumber.set("${project.version}")
versionType.set("release")
uploadFile.set(file("build/libs/${rootProject.name}-Bukkit-${project.version}.jar"))
gameVersions.addAll(listOf("1.20.2", "1.20.4", "1.20.6", "1.21.1", "1.21.3"))
loaders.addAll(listOf("paper", "spigot"))
changelog.set("The changelog is available on GitHub: https://github.com/IntellectualSites/" +
"FastAsyncWorldEdit/releases/tag/${project.version}")
syncBodyFrom.set(rootProject.file("README.md").readText())
projectDescription.set(rootProject.file("README.md").readText())
}

// We publish the reobfJar twice to ensure that the modrinth download menu picks the right jar for the platform regardless
// of minecraft version.

val mojmapPaperVersions = listOf("1.20.6", "1.21.1", "1.21.3")
val spigotMappedPaperVersions = listOf("1.20.2", "1.20.4")

// Mark reobfJar as spigot only for 1.20.5+
modrinth("spigot") {
from(common)
file.set(tasks.named<ShadowJar>("reobfShadowJar").flatMap { it.archiveFile })
minecraftVersions.set(mojmapPaperVersions)
modLoaders.set(listOf("spigot"))
}

// Mark reobfJar as spigot & paper for <1.20.5
modrinth("spigotAndOldPaper") {
from(common)
file.set(tasks.named<ShadowJar>("reobfShadowJar").flatMap { it.archiveFile })
minecraftVersions.set(spigotMappedPaperVersions)
modLoaders.set(listOf("paper", "spigot"))
}

// Mark mojang mapped jar as paper 1.20.5+ only
modrinth {
from(common)
file.set(tasks.named<ShadowJar>("shadowJar").flatMap { it.archiveFile })
minecraftVersions.set(mojmapPaperVersions)
modLoaders.set(listOf("paper"))
}

// dryRun.set(true) // For testing
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditManifest;
import com.sk89q.worldedit.bukkit.adapter.AdapterLoadException;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
Expand Down Expand Up @@ -90,7 +92,9 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.jar.Attributes;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.internal.anvil.ChunkDeleter.DELCHUNKS_FILE_NAME;
Expand Down Expand Up @@ -131,6 +135,50 @@ public void onLoad() {
}
}
//FAWE end
//FAWE start
final Attributes attributes = WorldEditManifest.readAttributes();
Objects.requireNonNull(attributes, "Could not retrieve manifest attributes");
final String type = attributes.getValue("FAWE-Plugin-Jar-Type");
Objects.requireNonNull(type, "Could not determine plugin jar type");
if (PaperLib.isPaper()) {
if (PaperLib.getMinecraftVersion() < 20 || (PaperLib.getMinecraftVersion() == 20 && PaperLib.getMinecraftPatchVersion() < 5)) {
if (type.equals("mojang") && !Refraction.isMojangMapped()) {
throw new IllegalStateException(
"""

**********************************************
** You are using the wrong FAWE jar for your Minecraft version.
** Download the correct FAWE jar from Modrinth: https://modrinth.com/plugin/fastasyncworldedit/
**********************************************"""
);
}
} else if (PaperLib.getMinecraftVersion() > 20 || (PaperLib.getMinecraftVersion() == 20 && PaperLib.getMinecraftPatchVersion() >= 5)) {
if (type.equals("spigot")) {
LOGGER.warn(
"""

**********************************************
** You are using the Spigot-mapped FAWE jar on a modern Paper version.
** This will result in slower first-run times and wasted disk space from plugin remapping.
** Download the Paper FAWE jar from Modrinth to avoid this: https://modrinth.com/plugin/fastasyncworldedit/
**********************************************"""
);
}
}
} else {
if (type.equals("mojang")) {
throw new IllegalStateException(
"""

**********************************************
** You are attempting to run the Paper FAWE jar on a Spigot server.
** Either switch to Paper (https://papermc.io), or download the correct FAWE jar for your platform
** from Modrinth: https://modrinth.com/plugin/fastasyncworldedit/
**********************************************"""
);
}
}
//FAWE end

INSTANCE = this;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public static String pickName(String mojangName, String spigotName) {
return IS_MOJANG_MAPPED ? mojangName : spigotName;
}

public static boolean isMojangMapped() {
return IS_MOJANG_MAPPED;
}

private Refraction() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static WorldEditManifest load() {
}

@Nullable
private static Attributes readAttributes() {
public static Attributes readAttributes() {
Class<WorldEditManifest> clazz = WorldEditManifest.class;
String className = clazz.getSimpleName() + ".class";
String classPath = clazz.getResource(className).toString();
Expand Down
Loading