diff options
author | Linnea Gräf <nea@nea.moe> | 2024-01-04 18:39:12 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-01-04 18:39:12 +0100 |
commit | d4eb7d8c5d49c8f958720050d133d828f482d85d (patch) | |
tree | 77ac594d2db1735e85403f8e2fe4bb2c227dba2b | |
parent | 61a5635e993b46d3ae2e76edd1b104987ff92a3f (diff) | |
download | neuhax-d4eb7d8c5d49c8f958720050d133d828f482d85d.tar.gz neuhax-d4eb7d8c5d49c8f958720050d133d828f482d85d.tar.bz2 neuhax-d4eb7d8c5d49c8f958720050d133d828f482d85d.zip |
Add auto updater
-rw-r--r-- | build.gradle.kts | 6 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/sky/NEUHax.kt | 4 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/sky/features/meta/AutoUpdate.kt | 64 |
3 files changed, 73 insertions, 1 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index cb03464..a37b4c5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,6 +33,7 @@ repositories { includeGroupByRegex("(com|io)\\.github\\..+") } } + maven("https://repo.nea.moe/releases/") maven("https://repo.spongepowered.org/maven/") maven("https://repo.polyfrost.cc/releases") // If you don't want to log in with your real minecraft account, remove this line @@ -63,8 +64,11 @@ dependencies { annotationProcessor("org.spongepowered:mixin:0.8.4-SNAPSHOT") // If you don't want to log in with your real minecraft account, remove this line runtimeOnly("me.djtheredstoner:DevAuth-forge-legacy:1.1.0") + shadowImpl("moe.nea:libautoupdate:1.2.0") - modCompileOnly(runtimeMod("com.github.notenoughupdates:notenoughupdates:a1b74ca22:all"){isTransitive=false}!!) {isTransitive = false} + modCompileOnly(runtimeMod("com.github.notenoughupdates:notenoughupdates:a1b74ca22:all") { + isTransitive = false + }!!) { isTransitive = false } } // Minecraft configuration: diff --git a/src/main/kotlin/moe/nea/sky/NEUHax.kt b/src/main/kotlin/moe/nea/sky/NEUHax.kt index 734fdab..6ae49f0 100644 --- a/src/main/kotlin/moe/nea/sky/NEUHax.kt +++ b/src/main/kotlin/moe/nea/sky/NEUHax.kt @@ -17,12 +17,14 @@ import moe.nea.sky.config.HaxConfigNeuConfig import moe.nea.sky.features.fopt.OptifineCustomItemCache import moe.nea.sky.features.gui.Enchanting import moe.nea.sky.features.gui.Melody +import moe.nea.sky.features.meta.AutoUpdate import moe.nea.sky.features.world.AutoFishing import moe.nea.sky.features.world.YawSnapping import moe.nea.sky.util.CommandActionRegistry import net.minecraft.launchwrapper.Launch import net.minecraftforge.client.ClientCommandHandler import net.minecraftforge.common.MinecraftForge +import net.minecraftforge.fml.common.Loader import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.Mod.EventHandler import net.minecraftforge.fml.common.event.FMLInitializationEvent @@ -37,6 +39,7 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent ) object NEUHax { + val version: String by lazy { Loader.instance().indexedModList[MODID]!!.version } val neuHaxConfig get() = (NotEnoughUpdates.INSTANCE.config as HaxConfigNeuConfig).neuHax val deobf by lazy { Launch.blackboard["fml.deobfuscatedEnvironment"] == true } @@ -52,6 +55,7 @@ object NEUHax { Enchanting, AutoFishing, YawSnapping, + AutoUpdate, Melody, OptifineCustomItemCache, ).forEach { diff --git a/src/main/kotlin/moe/nea/sky/features/meta/AutoUpdate.kt b/src/main/kotlin/moe/nea/sky/features/meta/AutoUpdate.kt new file mode 100644 index 0000000..070fe34 --- /dev/null +++ b/src/main/kotlin/moe/nea/sky/features/meta/AutoUpdate.kt @@ -0,0 +1,64 @@ +package moe.nea.sky.features.meta + +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.MC +import io.github.moulberry.notenoughupdates.util.MinecraftExecutor +import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute +import io.github.moulberry.notenoughupdates.util.brigadier.withHelp +import moe.nea.libautoupdate.CurrentVersion +import moe.nea.libautoupdate.UpdateContext +import moe.nea.libautoupdate.UpdateSource +import moe.nea.libautoupdate.UpdateTarget +import moe.nea.sky.MODID +import moe.nea.sky.NEUHax +import moe.nea.sky.util.showMessage +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import java.util.concurrent.CompletableFuture + +object AutoUpdate { + val updater = UpdateContext( + UpdateSource.mavenSource("https://repo.nea.moe/releases", "moe.nea", "neuhax"), + UpdateTarget.deleteAndSaveInTheSameFolder(AutoUpdate::class.java), + CurrentVersion.ofTag(NEUHax.version), + MODID + ) + + init { + updater.cleanup() + } + + var potentialUpdate = updater.checkUpdate("") + var notified = false + + @SubscribeEvent + fun onFirstPlayerInteraction(event: TickEvent.ClientTickEvent) { + if (notified) return + if (event.phase != TickEvent.Phase.START) return + val p = MC.thePlayer ?: return + val update = potentialUpdate.getNow(null) ?: return + notified = true + if (update.isUpdateAvailable) + p.showMessage { + text("§eUpdate found. From §c${update.context.currentVersion.display()} §eto §a${update.update.versionName}§e. Click to update at next restart.") + .clickable("Click to queue the update at your next restart") { + p.showMessage { text("§eDownloading update ${update.update.versionName}") } + CompletableFuture.supplyAsync { update.prepareUpdate() }.thenAcceptAsync({ + update.executePreparedUpdate() + p.showMessage { text("§eUpdate downloaded and queued for your next restart.") } + }, MinecraftExecutor.OnThread) + } + } + } + + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("nhupdate") { + thenExecute { + potentialUpdate = updater.checkUpdate("") + notified = false + } + }.withHelp("Update NEUHAX") + } + +}
\ No newline at end of file |