diff options
Diffstat (limited to 'src/main/kotlin')
-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 |
2 files changed, 68 insertions, 0 deletions
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 |