diff options
author | Empa <42304516+ItsEmpa@users.noreply.github.com> | 2024-04-28 16:45:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-28 16:45:37 +0200 |
commit | c8d4beac252f66a4988a71cdc8aba60207252528 (patch) | |
tree | d4ba45c40a6cfe24d93db15b772eb2430f0fa2f3 /src/main/java/at | |
parent | ae9482ca94504e809c8effa02530fa4697845542 (diff) | |
download | skyhanni-c8d4beac252f66a4988a71cdc8aba60207252528.tar.gz skyhanni-c8d4beac252f66a4988a71cdc8aba60207252528.tar.bz2 skyhanni-c8d4beac252f66a4988a71cdc8aba60207252528.zip |
Feature: Update command (#1578)
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt | 27 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt | 17 |
2 files changed, 37 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 6212c35b0..0ba4da096 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.api.SkillAPI import at.hannibal2.skyhanni.config.ConfigFileType import at.hannibal2.skyhanni.config.ConfigGuiManager +import at.hannibal2.skyhanni.config.features.About.UpdateStream import at.hannibal2.skyhanni.data.ChatClickActionManager import at.hannibal2.skyhanni.data.ChatManager import at.hannibal2.skyhanni.data.GardenCropMilestonesCommunityFix @@ -54,6 +55,7 @@ import at.hannibal2.skyhanni.features.misc.MiscFeatures import at.hannibal2.skyhanni.features.misc.discordrpc.DiscordRPCManager import at.hannibal2.skyhanni.features.misc.limbo.LimboTimeTracker import at.hannibal2.skyhanni.features.misc.massconfiguration.DefaultConfigFeatures +import at.hannibal2.skyhanni.features.misc.update.UpdateManager import at.hannibal2.skyhanni.features.misc.visualwords.VisualWordGui import at.hannibal2.skyhanni.features.rift.area.westvillage.VerminTracker import at.hannibal2.skyhanni.features.slayer.SlayerProfitTracker @@ -368,6 +370,10 @@ object Commands { "shkingfix", "Reseting the local King Talisman Helper offset." ) { KingTalismanHelper.kingFix() } + registerCommand( + "shupdate", + "Updates the mod to the specified update stream." + ) { forceUpdate(it) } } private fun developersDebugFeatures() { @@ -586,6 +592,27 @@ object Commands { storage.outdatedItems.clear() } + private fun forceUpdate(args: Array<String>) { + val currentStream = SkyHanniMod.feature.about.updateStream.get() + val arg = args.firstOrNull() ?: "current" + val updateStream = when { + arg.equals("(?i)(?:full|release)s?".toRegex()) -> UpdateStream.RELEASES + arg.equals("(?i)(?:beta|latest)s?".toRegex()) -> UpdateStream.BETA + else -> currentStream + } + + if (updateStream == UpdateStream.BETA && (currentStream != UpdateStream.BETA || UpdateManager.isCurrentlyBeta())) { + ChatUtils.clickableChat( + "Are you sure you want to switch to beta? These versions may be less stable.", + onClick = { + UpdateManager.checkUpdate(true, updateStream) + } + ) + } else { + UpdateManager.checkUpdate(true, updateStream) + } + } + private fun registerCommand(name: String, description: String, function: (Array<String>) -> Unit) { if (commands.any { it.name.equals(name, ignoreCase = true) }) { error("The command '$name is already registered!'") diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt index 4c6919eea..44fa625e8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.features.misc.update import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.config.features.About +import at.hannibal2.skyhanni.config.features.About.UpdateStream import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.utils.ChatUtils @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.utils.LorenzLogger import com.google.gson.JsonElement import io.github.moulberry.notenoughupdates.util.ApiUtil import io.github.moulberry.notenoughupdates.util.MinecraftExecutor +import io.github.notenoughupdates.moulconfig.observer.Property import io.github.notenoughupdates.moulconfig.processor.MoulConfigProcessor import moe.nea.libautoupdate.CurrentVersion import moe.nea.libautoupdate.PotentialUpdate @@ -75,15 +76,15 @@ object UpdateManager { logger.log("Reset update state") } - fun checkUpdate() { + fun checkUpdate(forceDownload: Boolean = false, updateStream: UpdateStream = config.updateStream.get()) { if (updateState != UpdateState.NONE) { logger.log("Trying to perform update check while another update is already in progress") return } logger.log("Starting update check") - var updateStream = config.updateStream.get() - if (updateStream == About.UpdateStream.RELEASES && isCurrentlyBeta()) { - updateStream = About.UpdateStream.BETA + val currentStream = SkyHanniMod.feature.about.updateStream.get() + if (currentStream != UpdateStream.BETA && (updateStream == UpdateStream.BETA || isCurrentlyBeta())) { + config.updateStream = Property.of(UpdateStream.BETA) } activePromise = context.checkUpdate(updateStream.stream) .thenAcceptAsync({ @@ -95,8 +96,8 @@ object UpdateManager { potentialUpdate = it if (it.isUpdateAvailable) { updateState = UpdateState.AVAILABLE - if (config.fullAutoUpdates) { - ChatUtils.chat("§aSkyHanni found a new update: ${it.update.versionName}, starting to download now. ") + if (config.fullAutoUpdates || forceDownload) { + ChatUtils.chat("§aSkyHanni found a new update: ${it.update.versionName}, starting to download now.") queueUpdate() } else if (config.autoUpdates) { ChatUtils.chatAndOpenConfig( @@ -105,6 +106,8 @@ object UpdateManager { SkyHanniMod.feature.about::autoUpdates ) } + } else if (forceDownload) { + ChatUtils.chat("§aSkyHanni didn't find a new update.") } }, MinecraftExecutor.OnThread) } |