Skip to content

Commit dcd6b93

Browse files
authored
Build a Mojang mapped jar in addition to the reobf one, publish both to Modrinth with correct metadata (#2981)
1 parent e3fc35c commit dcd6b93

File tree

11 files changed

+153
-31
lines changed

11 files changed

+153
-31
lines changed

.github/workflows/announce-release-on-discord.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
""
2525
"The download is available at:"
2626
"- Spigot: <https://www.spigotmc.org/resources/13932/>"
27-
"- Modrinth: <https://modrinth.com/plugin/fastasyncworldedit/version/${{ github.event.release.tag_name }}>"
27+
"- Modrinth: <https://modrinth.com/plugin/fastasyncworldedit>"
2828
"- CurseForge: <https://www.curseforge.com/minecraft/bukkit-plugins/fawe>"

.github/workflows/build-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
uses: actions/upload-artifact@v3
2525
with:
2626
name: FastAsyncWorldEdit-SNAPSHOT
27-
path: worldedit-bukkit/build/libs/FastAsyncWorldEdit-Bukkit-*.jar
27+
path: worldedit-bukkit/build/libs/FastAsyncWorldEdit-*.jar

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ jobs:
7070
uses: actions/upload-artifact@v3
7171
with:
7272
name: FastAsyncWorldEdit-Bukkit-SNAPSHOT
73-
path: worldedit-bukkit/build/libs/FastAsyncWorldEdit-Bukkit-*.jar
73+
path: worldedit-bukkit/build/libs/FastAsyncWorldEdit-*.jar
7474
- name: Publish to Modrinth
7575
if: ${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/main'}}
76-
run: ./gradlew modrinth
76+
run: ./gradlew publishMods
7777
env:
7878
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}

.github/workflows/upload-release-assets.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ jobs:
2121
- name: Upload Release Assets
2222
uses: AButler/[email protected]
2323
with:
24-
files: 'worldedit-bukkit/build/libs/FastAsyncWorldEdit-Bukkit-*.jar'
24+
files: 'worldedit-bukkit/build/libs/FastAsyncWorldEdit-*.jar'
2525
repo-token: ${{ secrets.GITHUB_TOKEN }}
2626
release-tag: ${{ github.event.release.tag_name }}

buildSrc/src/main/kotlin/AdapterConfig.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ fun Project.applyPaperweightAdapterConfiguration() {
2020
tasks.named("assemble") {
2121
dependsOn("reobfJar")
2222
}
23+
24+
tasks.named("javadoc") {
25+
enabled = false
26+
}
2327
}

buildSrc/src/main/kotlin/PlatformConfig.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.gradle.kotlin.dsl.named
1212
import org.gradle.kotlin.dsl.provideDelegate
1313
import org.gradle.kotlin.dsl.register
1414
import org.gradle.kotlin.dsl.the
15+
import org.gradle.kotlin.dsl.withType
1516
import org.gradle.plugins.signing.SigningExtension
1617

1718
fun Project.applyPlatformAndCoreConfiguration() {
@@ -132,7 +133,7 @@ fun Project.applyPlatformAndCoreConfiguration() {
132133
}
133134

134135
fun Project.applyShadowConfiguration() {
135-
tasks.named<ShadowJar>("shadowJar") {
136+
tasks.withType<ShadowJar>().configureEach {
136137
dependencies {
137138
include(project(":worldedit-libs:core"))
138139
include(project(":worldedit-libs:${project.name.replace("worldedit-", "")}"))

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mockito = "5.14.2"
5151

5252
# Gradle plugins
5353
pluginyml = "0.6.0"
54-
minotaur = "2.8.7"
54+
mod-publish-plugin = "0.7.4"
5555

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

128128
[plugins]
129129
pluginyml = { id = "net.minecrell.plugin-yml.bukkit", version.ref = "pluginyml" }
130-
minotaur = { id = "com.modrinth.minotaur", version.ref = "minotaur" }
130+
mod-publish-plugin = { id = "me.modmuss50.mod-publish-plugin", version.ref = "mod-publish-plugin" }

worldedit-bukkit/build.gradle.kts

Lines changed: 87 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22
import io.papermc.paperweight.userdev.attribute.Obfuscation
3+
import me.modmuss50.mpp.ReleaseType
34

45
plugins {
56
`java-library`
6-
alias(libs.plugins.minotaur)
7+
alias(libs.plugins.mod.publish.plugin)
78
}
89

910
project.description = "Bukkit"
@@ -47,21 +48,26 @@ val localImplementation = configurations.create("localImplementation") {
4748
}
4849

4950
val adapters = configurations.create("adapters") {
50-
description = "Adapters to include in the JAR"
51+
description = "Adapters to include in the JAR (Mojmap)"
5152
isCanBeConsumed = false
5253
isCanBeResolved = true
5354
shouldResolveConsistentlyWith(configurations["runtimeClasspath"])
5455
attributes {
55-
attribute(Obfuscation.OBFUSCATION_ATTRIBUTE,
56-
if ((project.findProperty("enginehub.obf.none") as String?).toBoolean()) {
57-
objects.named(Obfuscation.NONE)
58-
} else {
59-
objects.named(Obfuscation.OBFUSCATED)
60-
}
61-
)
56+
attribute(Obfuscation.OBFUSCATION_ATTRIBUTE, objects.named(Obfuscation.NONE))
6257
}
6358
}
6459

60+
val adaptersReobf = configurations.create("adaptersReobf") {
61+
description = "Adapters to include in the JAR (Spigot-Mapped)"
62+
isCanBeConsumed = false
63+
isCanBeResolved = true
64+
shouldResolveConsistentlyWith(configurations["runtimeClasspath"])
65+
attributes {
66+
attribute(Obfuscation.OBFUSCATION_ATTRIBUTE, objects.named(Obfuscation.OBFUSCATED))
67+
}
68+
extendsFrom(adapters)
69+
}
70+
6571
dependencies {
6672
// Modules
6773
api(projects.worldeditCore)
@@ -141,9 +147,37 @@ tasks.named<Jar>("jar") {
141147

142148
addJarManifest(WorldEditKind.Plugin, includeClasspath = true)
143149

150+
tasks.register<ShadowJar>("reobfShadowJar") {
151+
archiveFileName.set("${rootProject.name}-Bukkit-${project.version}.${archiveExtension.getOrElse("jar")}")
152+
configurations = listOf(
153+
project.configurations.runtimeClasspath.get(), // as is done by shadow for the default shadowJar
154+
adaptersReobf
155+
)
156+
157+
// as is done by shadow for the default shadowJar
158+
from(sourceSets.main.map { it.output })
159+
manifest.inheritFrom(tasks.jar.get().manifest)
160+
exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "module-info.class")
161+
162+
manifest {
163+
attributes(
164+
"FAWE-Plugin-Jar-Type" to "spigot"
165+
)
166+
}
167+
}
168+
144169
tasks.named<ShadowJar>("shadowJar") {
170+
archiveFileName.set("${rootProject.name}-Paper-${project.version}.${archiveExtension.getOrElse("jar")}")
145171
configurations.add(adapters)
146-
archiveFileName.set("${rootProject.name}-Bukkit-${project.version}.${archiveExtension.getOrElse("jar")}")
172+
manifest {
173+
attributes(
174+
"paperweight-mappings-namespace" to "mojang",
175+
"FAWE-Plugin-Jar-Type" to "mojang"
176+
)
177+
}
178+
}
179+
180+
tasks.withType<ShadowJar>().configureEach {
147181
dependencies {
148182
// In tandem with not bundling log4j, we shouldn't relocate base package here.
149183
// relocate("org.apache.logging", "com.sk89q.worldedit.log4j")
@@ -198,20 +232,51 @@ tasks.named<ShadowJar>("shadowJar") {
198232

199233
tasks.named("assemble").configure {
200234
dependsOn("shadowJar")
235+
dependsOn("reobfShadowJar")
201236
}
202237

203-
tasks {
204-
modrinth {
205-
token.set(System.getenv("MODRINTH_TOKEN"))
238+
publishMods {
239+
displayName.set("${project.version}")
240+
version.set("${project.version}")
241+
type.set(ReleaseType.STABLE)
242+
changelog.set("The changelog is available on GitHub: https://github.com/IntellectualSites/" +
243+
"FastAsyncWorldEdit/releases/tag/${project.version}")
244+
245+
val common = modrinthOptions {
246+
accessToken.set(System.getenv("MODRINTH_TOKEN"))
206247
projectId.set("fastasyncworldedit")
207-
versionName.set("${project.version}")
208-
versionNumber.set("${project.version}")
209-
versionType.set("release")
210-
uploadFile.set(file("build/libs/${rootProject.name}-Bukkit-${project.version}.jar"))
211-
gameVersions.addAll(listOf("1.20.2", "1.20.4", "1.20.6", "1.21.1", "1.21.3"))
212-
loaders.addAll(listOf("paper", "spigot"))
213-
changelog.set("The changelog is available on GitHub: https://github.com/IntellectualSites/" +
214-
"FastAsyncWorldEdit/releases/tag/${project.version}")
215-
syncBodyFrom.set(rootProject.file("README.md").readText())
248+
projectDescription.set(rootProject.file("README.md").readText())
216249
}
250+
251+
// We publish the reobfJar twice to ensure that the modrinth download menu picks the right jar for the platform regardless
252+
// of minecraft version.
253+
254+
val mojmapPaperVersions = listOf("1.20.6", "1.21.1", "1.21.3")
255+
val spigotMappedPaperVersions = listOf("1.20.2", "1.20.4")
256+
257+
// Mark reobfJar as spigot only for 1.20.5+
258+
modrinth("spigot") {
259+
from(common)
260+
file.set(tasks.named<ShadowJar>("reobfShadowJar").flatMap { it.archiveFile })
261+
minecraftVersions.set(mojmapPaperVersions)
262+
modLoaders.set(listOf("spigot"))
263+
}
264+
265+
// Mark reobfJar as spigot & paper for <1.20.5
266+
modrinth("spigotAndOldPaper") {
267+
from(common)
268+
file.set(tasks.named<ShadowJar>("reobfShadowJar").flatMap { it.archiveFile })
269+
minecraftVersions.set(spigotMappedPaperVersions)
270+
modLoaders.set(listOf("paper", "spigot"))
271+
}
272+
273+
// Mark mojang mapped jar as paper 1.20.5+ only
274+
modrinth {
275+
from(common)
276+
file.set(tasks.named<ShadowJar>("shadowJar").flatMap { it.archiveFile })
277+
minecraftVersions.set(mojmapPaperVersions)
278+
modLoaders.set(listOf("paper"))
279+
}
280+
281+
// dryRun.set(true) // For testing
217282
}

worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
import com.sk89q.worldedit.EditSession;
3333
import com.sk89q.worldedit.LocalSession;
3434
import com.sk89q.worldedit.WorldEdit;
35+
import com.sk89q.worldedit.WorldEditManifest;
3536
import com.sk89q.worldedit.bukkit.adapter.AdapterLoadException;
3637
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
3738
import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader;
39+
import com.sk89q.worldedit.bukkit.adapter.Refraction;
3840
import com.sk89q.worldedit.event.platform.CommandEvent;
3941
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
4042
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
@@ -90,7 +92,9 @@
9092
import java.nio.file.Paths;
9193
import java.util.List;
9294
import java.util.Locale;
95+
import java.util.Objects;
9396
import java.util.Optional;
97+
import java.util.jar.Attributes;
9498

9599
import static com.google.common.base.Preconditions.checkNotNull;
96100
import static com.sk89q.worldedit.internal.anvil.ChunkDeleter.DELCHUNKS_FILE_NAME;
@@ -131,6 +135,50 @@ public void onLoad() {
131135
}
132136
}
133137
//FAWE end
138+
//FAWE start
139+
final Attributes attributes = WorldEditManifest.readAttributes();
140+
Objects.requireNonNull(attributes, "Could not retrieve manifest attributes");
141+
final String type = attributes.getValue("FAWE-Plugin-Jar-Type");
142+
Objects.requireNonNull(type, "Could not determine plugin jar type");
143+
if (PaperLib.isPaper()) {
144+
if (PaperLib.getMinecraftVersion() < 20 || (PaperLib.getMinecraftVersion() == 20 && PaperLib.getMinecraftPatchVersion() < 5)) {
145+
if (type.equals("mojang") && !Refraction.isMojangMapped()) {
146+
throw new IllegalStateException(
147+
"""
148+
149+
**********************************************
150+
** You are using the wrong FAWE jar for your Minecraft version.
151+
** Download the correct FAWE jar from Modrinth: https://modrinth.com/plugin/fastasyncworldedit/
152+
**********************************************"""
153+
);
154+
}
155+
} else if (PaperLib.getMinecraftVersion() > 20 || (PaperLib.getMinecraftVersion() == 20 && PaperLib.getMinecraftPatchVersion() >= 5)) {
156+
if (type.equals("spigot")) {
157+
LOGGER.warn(
158+
"""
159+
160+
**********************************************
161+
** You are using the Spigot-mapped FAWE jar on a modern Paper version.
162+
** This will result in slower first-run times and wasted disk space from plugin remapping.
163+
** Download the Paper FAWE jar from Modrinth to avoid this: https://modrinth.com/plugin/fastasyncworldedit/
164+
**********************************************"""
165+
);
166+
}
167+
}
168+
} else {
169+
if (type.equals("mojang")) {
170+
throw new IllegalStateException(
171+
"""
172+
173+
**********************************************
174+
** You are attempting to run the Paper FAWE jar on a Spigot server.
175+
** Either switch to Paper (https://papermc.io), or download the correct FAWE jar for your platform
176+
** from Modrinth: https://modrinth.com/plugin/fastasyncworldedit/
177+
**********************************************"""
178+
);
179+
}
180+
}
181+
//FAWE end
134182

135183
INSTANCE = this;
136184

worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/Refraction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public static String pickName(String mojangName, String spigotName) {
4242
return IS_MOJANG_MAPPED ? mojangName : spigotName;
4343
}
4444

45+
public static boolean isMojangMapped() {
46+
return IS_MOJANG_MAPPED;
47+
}
48+
4549
private Refraction() {
4650
}
4751

0 commit comments

Comments
 (0)