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

Backend: Add Minecraft Version to jar file name #2941

Open
wants to merge 3 commits into
base: beta
Choose a base branch
from
Open
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: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ tasks.withType(JavaCompile::class) {

tasks.withType(org.gradle.jvm.tasks.Jar::class) {
archiveBaseName.set("SkyHanni")
archiveAppendix.set("mc${target.minecraftVersion.versionName}")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE // Why do we have this here? This only *hides* errors.
manifest.attributes.run {
this["Main-Class"] = "SkyHanniInstallerFrame"
Expand Down Expand Up @@ -384,6 +385,7 @@ preprocess {

blossom {
replaceToken("@MOD_VERSION@", version)
replaceToken("@MC_VERSION@", target.minecraftVersion.versionName)
}

val sourcesJar by tasks.creating(Jar::class) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package at.hannibal2.skyhanni.features.misc.update

import at.hannibal2.skyhanni.utils.system.PlatformUtils
import com.google.gson.JsonPrimitive
import moe.nea.libautoupdate.GithubReleaseUpdateData
import moe.nea.libautoupdate.GithubReleaseUpdateSource
import moe.nea.libautoupdate.UpdateData

/**
* This class is a custom implementation of the [GithubReleaseUpdateSource] that filters assets based on the mod's version.
*/
class CustomGithubReleaseUpdateSource(owner: String, repository: String) : GithubReleaseUpdateSource(owner, repository) {

override fun findAsset(release: GithubRelease?): UpdateData? {
release ?: return null

return release.assets.stream()
.filter { it.filterAsset() }
.map { it.createReleaseData(release) }
.findFirst().orElse(null)
}

private fun GithubRelease.Download.filterAsset(): Boolean {
name ?: return false
browserDownloadUrl ?: return false
if (!name.endsWith(".jar")) return false
return name.contains(PlatformUtils.MC_VERSION)
}

private fun GithubRelease.Download.createReleaseData(release: GithubRelease): GithubReleaseUpdateData {
return GithubReleaseUpdateData(
if (release.name == null) release.tagName else release.name,
JsonPrimitive(release.tagName),
null,
browserDownloadUrl,
release.body,
release.targetCommitish,
release.created_at,
release.publishedAt,
release.htmlUrl,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import io.github.notenoughupdates.moulconfig.processor.MoulConfigProcessor
import moe.nea.libautoupdate.CurrentVersion
import moe.nea.libautoupdate.PotentialUpdate
import moe.nea.libautoupdate.UpdateContext
import moe.nea.libautoupdate.UpdateSource
import moe.nea.libautoupdate.UpdateTarget
import moe.nea.libautoupdate.UpdateUtils
import net.minecraft.client.Minecraft
Expand Down Expand Up @@ -134,7 +133,7 @@ object UpdateManager {
}

private val context = UpdateContext(
UpdateSource.githubUpdateSource("hannibal002", "SkyHanni"),
CustomGithubReleaseUpdateSource("hannibal002", "SkyHanni"),
UpdateTarget.deleteAndSaveInTheSameFolder(UpdateManager::class.java),
object : CurrentVersion {
val normalDelegate = CurrentVersion.ofTag(SkyHanniMod.version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import net.minecraftforge.fml.common.ModContainer
*/
object PlatformUtils {

const val MC_VERSION = "@MC_VERSION@"

private val modPackages: Map<String, ModContainer> by lazy {
Loader.instance().modList.flatMap { mod -> mod.ownedPackages.map { it to mod } }.toMap()
}
Expand Down
Loading