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: Change versioning [Do not merge hannibal until it is time] #3123

Open
wants to merge 11 commits into
base: beta
Choose a base branch
from
Open
10 changes: 9 additions & 1 deletion root.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ plugins {

allprojects {
group = "at.hannibal2.skyhanni"
version = "0.28.Beta.21"

/**
* The version of the project.
* Major version
* Minor version
* Beta version
*/
version = "1.0.0"

repositories {
mavenCentral()
mavenLocal()
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.test.hotswap.HotswapSupport
import at.hannibal2.skyhanni.utils.MinecraftConsoleFilter.Companion.initLogging
import at.hannibal2.skyhanni.utils.NEUVersionCheck.checkIfNeuIsLoaded
import at.hannibal2.skyhanni.utils.system.ModVersion
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -108,9 +109,16 @@ class SkyHanniMod {

const val MODID = "skyhanni"

val modVersion: ModVersion by lazy {
ModVersion.fromString(Loader.instance().indexedModList[MODID]!!.version)
}

@JvmStatic
val version: String
get() = Loader.instance().indexedModList[MODID]!!.version
get() = modVersion.asString

val isBetaVersion: Boolean
get() = modVersion.isBeta

@JvmField
var feature: Features = Features()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import kotlin.concurrent.fixedRateTimer
import kotlin.reflect.KMutableProperty0

private fun GsonBuilder.registerIfBeta(create: TypeAdapterFactory): GsonBuilder {
return if (LorenzUtils.isBetaVersion()) {
return if (SkyHanniMod.isBetaVersion) {
registerTypeAdapterFactory(create)
} else this
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package at.hannibal2.skyhanni.data.jsonobjects.repo

import at.hannibal2.skyhanni.utils.system.ModVersion
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName

data class RepoErrorJson(
data class ChangedChatErrorsJson(
@Expose @SerializedName("changed_error_messages") val changedErrorMessages: List<RepoErrorData>,
)

data class RepoErrorData(
@Expose @SerializedName("message_exact") private var rawMessageExact: List<String>?,
@Expose @SerializedName("message_starts_with") private var rawMessageStartsWith: List<String>?,
@Expose @SerializedName("replace_message") var replaceMessage: String?,
@Expose @SerializedName("custom_message") var customMessage: String?,
@Expose @SerializedName("affected_versions") var affectedVersions: List<String> = listOf(),
@Expose @SerializedName("message_exact") private val rawMessageExact: List<String>?,
@Expose @SerializedName("message_starts_with") private val rawMessageStartsWith: List<String>?,
@Expose @SerializedName("replace_message") val replaceMessage: String?,
@Expose @SerializedName("custom_message") val customMessage: String?,
@Expose @SerializedName("affected_versions") val affectedVersions: List<String> = listOf(),
@Expose @SerializedName("fixed_in") val fixedIn: ModVersion?,
) {
val messageExact get() = rawMessageExact.orEmpty()
val messageStartsWith get() = rawMessageStartsWith.orEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ object UpdateManager {
}
}

fun isCurrentlyBeta(): Boolean {
return SkyHanniMod.version.contains("beta", ignoreCase = true)
}

private val config get() = SkyHanniMod.feature.about

fun reset() {
Expand All @@ -86,7 +82,7 @@ object UpdateManager {
}
logger.log("Starting update check")
val currentStream = config.updateStream.get()
if (currentStream != UpdateStream.BETA && (updateStream == UpdateStream.BETA || isCurrentlyBeta())) {
if (currentStream != UpdateStream.BETA && (updateStream == UpdateStream.BETA || SkyHanniMod.isBetaVersion)) {
config.updateStream = Property.of(UpdateStream.BETA)
updateStream = UpdateStream.BETA
}
Expand Down Expand Up @@ -184,7 +180,7 @@ object UpdateManager {
else -> currentStream
}

val switchingToBeta = updateStream == UpdateStream.BETA && (currentStream != UpdateStream.BETA || !UpdateManager.isCurrentlyBeta())
val switchingToBeta = updateStream == UpdateStream.BETA && (currentStream != UpdateStream.BETA || !SkyHanniMod.isBetaVersion)
if (switchingToBeta) {
ChatUtils.clickableChat(
"Are you sure you want to switch to beta? These versions may be less stable.",
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package at.hannibal2.skyhanni.test.command

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.jsonobjects.repo.ChangedChatErrorsJson
import at.hannibal2.skyhanni.data.jsonobjects.repo.RepoErrorData
import at.hannibal2.skyhanni.data.jsonobjects.repo.RepoErrorJson
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.StringUtils
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
Expand Down Expand Up @@ -129,7 +128,7 @@ object ErrorManager {
betaOnly: Boolean = false,
condition: () -> Boolean = { true },
) {
if (betaOnly && !LorenzUtils.isBetaVersion()) return
if (betaOnly && !SkyHanniMod.isBetaVersion) return
if (!ignoreErrorCache) {
val pair = if (throwable.stackTrace.isNotEmpty()) {
throwable.stackTrace[0].let { (it.fileName ?: "<unknown>") to it.lineNumber }
Expand Down Expand Up @@ -206,10 +205,10 @@ object ErrorManager {

@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<RepoErrorJson>("ChangedChatErrors")
val version = SkyHanniMod.version
val data = event.getConstant<ChangedChatErrorsJson>("ChangedChatErrors")
val version = SkyHanniMod.modVersion

repoErrors = data.changedErrorMessages.filter { version in it.affectedVersions }
repoErrors = data.changedErrorMessages.filter { it.fixedIn == null || version < it.fixedIn }
}

private fun buildExtraDataString(extraData: Array<out Pair<String, Any?>>): String {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import at.hannibal2.skyhanni.data.MiningAPI
import at.hannibal2.skyhanni.data.Perk
import at.hannibal2.skyhanni.data.TitleManager
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.features.misc.update.UpdateManager
import at.hannibal2.skyhanni.features.misc.visualwords.ModifyVisualWords
import at.hannibal2.skyhanni.features.nether.kuudra.KuudraAPI
import at.hannibal2.skyhanni.mixins.transformers.AccessorGuiEditSign
Expand Down Expand Up @@ -316,8 +315,6 @@ object LorenzUtils {

fun inMiningIsland() = IslandType.GOLD_MINES.isInIsland() || IslandType.DEEP_CAVERNS.isInIsland() || MiningAPI.inAdvancedMiningIsland()

fun isBetaVersion() = UpdateManager.isCurrentlyBeta()

private var lastGuiTime = SimpleTimeMark.farPast()

fun isAnyGuiActive(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import at.hannibal2.skyhanni.utils.LorenzRarity
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.json.SkyHanniTypeAdapters.registerTypeAdapter
import at.hannibal2.skyhanni.utils.system.ModVersion
import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
import com.google.gson.GsonBuilder
import io.github.notenoughupdates.moulconfig.observer.PropertyTypeAdapterFactory
Expand All @@ -29,6 +29,7 @@ object BaseGsonBuilder {
.registerTypeAdapter(NEUInternalName::class.java, SkyHanniTypeAdapters.INTERNAL_NAME.nullSafe())
.registerTypeAdapter(LorenzRarity::class.java, SkyHanniTypeAdapters.RARITY.nullSafe())
.registerTypeAdapter(IslandType::class.java, SkyHanniTypeAdapters.ISLAND_TYPE.nullSafe())
.registerTypeAdapter(ModVersion::class.java, SkyHanniTypeAdapters.MOD_VERSION.nullSafe())
.registerTypeAdapter(
SkyHanniTracker.DefaultDisplayMode::class.java,
SkyHanniTypeAdapters.TRACKER_DISPLAY_MODE.nullSafe(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark
import at.hannibal2.skyhanni.utils.system.ModVersion
import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
import com.google.gson.GsonBuilder
import com.google.gson.TypeAdapter
Expand Down Expand Up @@ -82,6 +83,11 @@ object SkyHanniTypeAdapters {
{ SkyblockStat.getValue(this.uppercase()) },
)

val MOD_VERSION: TypeAdapter<ModVersion> = SimpleStringTypeAdapter(
{ asString },
{ ModVersion.fromString(this) },
)

val TRACKER_DISPLAY_MODE = SimpleStringTypeAdapter.forEnum<SkyHanniTracker.DefaultDisplayMode>()
val ISLAND_TYPE = SimpleStringTypeAdapter.forEnum<IslandType>()
val RARITY = SimpleStringTypeAdapter.forEnum<LorenzRarity>()
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/system/ModVersion.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package at.hannibal2.skyhanni.utils.system

data class ModVersion(val major: Int, val minor: Int, val beta: Int) {

companion object {
fun fromString(version: String): ModVersion {

val parts = version.split('.')
return ModVersion(
parts.getOrNull(0)?.toIntOrNull() ?: 0,
parts.getOrNull(1)?.toIntOrNull() ?: 0,
parts.getOrNull(2)?.toIntOrNull() ?: 0,
)
}
}

val isBeta = beta != 0

val asString: String
get() = toString()

override fun toString(): String {
return "$major.$minor.$beta"
}

operator fun compareTo(other: ModVersion): Int {
return when {
major != other.major -> major.compareTo(other.major)
minor != other.minor -> minor.compareTo(other.minor)
else -> beta.compareTo(other.beta)
}
}
}
Loading