From 309574adc7a940c281c93e9698c87d3864d59737 Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Tue, 6 Sep 2016 00:24:16 +0100 Subject: [PATCH] Listen scrub, this is my updater. --- .../java/vazkii/botania/common/Botania.java | 3 +- .../core/version/ThreadVersionChecker.java | 39 +++++++++++++++++++ .../common/core/version/VersionChecker.java | 32 +++++++-------- .../vazkii/botania/common/lib/LibMisc.java | 2 - .../resources/assets/botania/lang/en_US.lang | 2 +- 5 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 src/main/java/vazkii/botania/common/core/version/ThreadVersionChecker.java diff --git a/src/main/java/vazkii/botania/common/Botania.java b/src/main/java/vazkii/botania/common/Botania.java index 43946269c..f5051bca4 100644 --- a/src/main/java/vazkii/botania/common/Botania.java +++ b/src/main/java/vazkii/botania/common/Botania.java @@ -92,8 +92,7 @@ import vazkii.botania.common.network.PacketHandler; import vazkii.botania.common.world.SkyblockWorldEvents; import vazkii.botania.common.world.WorldTypeSkyblock; -@Mod(modid = LibMisc.MOD_ID, name = LibMisc.MOD_NAME, version = LibMisc.VERSION, dependencies = LibMisc.DEPENDENCIES, - guiFactory = LibMisc.GUI_FACTORY, acceptedMinecraftVersions = LibMisc.MC_VERSIONS, updateJSON = LibMisc.UPDATE_JSON) +@Mod(modid = LibMisc.MOD_ID, name = LibMisc.MOD_NAME, version = LibMisc.VERSION, dependencies = LibMisc.DEPENDENCIES, guiFactory = LibMisc.GUI_FACTORY) public class Botania { public static boolean gardenOfGlassLoaded = false; diff --git a/src/main/java/vazkii/botania/common/core/version/ThreadVersionChecker.java b/src/main/java/vazkii/botania/common/core/version/ThreadVersionChecker.java new file mode 100644 index 000000000..b4ffac40f --- /dev/null +++ b/src/main/java/vazkii/botania/common/core/version/ThreadVersionChecker.java @@ -0,0 +1,39 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [May 31, 2014, 10:31:46 PM (GMT)] + */ +package vazkii.botania.common.core.version; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; + +import net.minecraftforge.common.MinecraftForge; + +public class ThreadVersionChecker extends Thread { + + public ThreadVersionChecker() { + setName("Botania Version Checker Thread"); + setDaemon(true); + start(); + } + + @Override + public void run() { + try { + URL url = new URL("https://raw.githubusercontent.com/Vazkii/BotaniaV2/master/version/" + MinecraftForge.MC_VERSION + ".txt"); + BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream())); + VersionChecker.onlineVersion = r.readLine(); + r.close(); + } catch(Exception e) { + e.printStackTrace(); + } + VersionChecker.doneChecking = true; + } +} \ No newline at end of file diff --git a/src/main/java/vazkii/botania/common/core/version/VersionChecker.java b/src/main/java/vazkii/botania/common/core/version/VersionChecker.java index 8cc4ced28..98d786aec 100644 --- a/src/main/java/vazkii/botania/common/core/version/VersionChecker.java +++ b/src/main/java/vazkii/botania/common/core/version/VersionChecker.java @@ -11,20 +11,16 @@ package vazkii.botania.common.core.version; import net.minecraft.client.Minecraft; -import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; -import net.minecraftforge.common.ForgeVersion; +import net.minecraft.util.text.translation.I18n; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.ModContainer; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; -import vazkii.botania.common.lib.LibMisc; public final class VersionChecker { @@ -33,32 +29,34 @@ public final class VersionChecker { private static final int FLAVOUR_MESSAGES = 65; public static boolean doneChecking = false; + public static String onlineVersion = ""; private static boolean triedToWarnPlayer = false; public static boolean startedDownload = false; public static boolean downloadedFile = false; public static void init() { + new ThreadVersionChecker(); MinecraftForge.EVENT_BUS.register(VersionChecker.class); } @SubscribeEvent public static void onTick(ClientTickEvent event) { - if(!triedToWarnPlayer && event.phase == Phase.END && Minecraft.getMinecraft().thePlayer != null) { - ModContainer botaniaContainer = Loader.instance().getIndexedModList().get(LibMisc.MOD_ID); - ForgeVersion.CheckResult result = ForgeVersion.getResult(botaniaContainer); - - if(result.status != ForgeVersion.Status.PENDING) - triedToWarnPlayer = true; - - if(result.status == ForgeVersion.Status.OUTDATED) { + if(doneChecking && event.phase == Phase.END && Minecraft.getMinecraft().thePlayer != null && !triedToWarnPlayer) { + if(!onlineVersion.isEmpty()) { EntityPlayer player = Minecraft.getMinecraft().thePlayer; - player.addChatComponentMessage(new TextComponentTranslation("botania.versioning.flavour" + player.worldObj.rand.nextInt(FLAVOUR_MESSAGES)).setStyle(new Style().setColor(TextFormatting.LIGHT_PURPLE))); - player.addChatComponentMessage(new TextComponentTranslation("botania.versioning.outdated", botaniaContainer.getVersion(), result.target)); + int onlineBuild = Integer.parseInt(onlineVersion.split("-")[1]); + int clientBuild = 10;//LibMisc.BUILD.contains("GRADLE") ? Integer.MAX_VALUE : Integer.parseInt(LibMisc.BUILD); + if(onlineBuild > clientBuild) { + player.addChatComponentMessage(new TextComponentTranslation("botania.versioning.flavour" + player.worldObj.rand.nextInt(FLAVOUR_MESSAGES)).setStyle(new Style().setColor(TextFormatting.LIGHT_PURPLE))); + player.addChatComponentMessage(new TextComponentTranslation("botania.versioning.outdated", clientBuild, onlineBuild)); - ITextComponent component = ITextComponent.Serializer.jsonToComponent(I18n.format("botania.versioning.updateMessage", result.target)); - player.addChatComponentMessage(component); + ITextComponent component = ITextComponent.Serializer.fromJsonLenient(I18n.translateToLocal("botania.versioning.updateMessage").replaceAll("%version%", onlineVersion)); + player.addChatComponentMessage(component); + } } + + triedToWarnPlayer = true; } } diff --git a/src/main/java/vazkii/botania/common/lib/LibMisc.java b/src/main/java/vazkii/botania/common/lib/LibMisc.java index b943a2ce0..08ab4e5f0 100644 --- a/src/main/java/vazkii/botania/common/lib/LibMisc.java +++ b/src/main/java/vazkii/botania/common/lib/LibMisc.java @@ -18,8 +18,6 @@ public final class LibMisc { public static final String BUILD = "GRADLE:BUILD"; public static final String VERSION = "GRADLE:VERSION-" + BUILD; public static final String DEPENDENCIES = "required-after:Forge@[12.18.1.2053,];required-after:Baubles;after:Thaumcraft"; - public static final String MC_VERSIONS = "[1.10.2]"; - public static final String UPDATE_JSON = "https://raw.githubusercontent.com/williewillus/Botania/HEAD/version/update.json"; // Network Contants public static final String NETWORK_CHANNEL = MOD_ID; diff --git a/src/main/resources/assets/botania/lang/en_US.lang b/src/main/resources/assets/botania/lang/en_US.lang index 357e45bd5..6f0d7267a 100644 --- a/src/main/resources/assets/botania/lang/en_US.lang +++ b/src/main/resources/assets/botania/lang/en_US.lang @@ -423,7 +423,7 @@ botania.versioning.flavour62=Nine out of ten doctors recommend you update Botani botania.versioning.flavour63=The update bacons at midnight. botania.versioning.flavour64=A new Botania Update is out. And it's name is JOHN CENA! DOO DOO DOO DOO botania.versioning.outdated=You are running Botania build %s, the latest is build %s. -botania.versioning.updateMessage=["Click for... [",{"text":"Download","color":"green","hoverEvent":{"action":"show_text","value":{"text":"Click this to download the latest version","color":"green"}},"clickEvent":{"action":"open_url","value":"http://minecraft.curseforge.com/projects/botania-unofficial/files/latest"}},"] [",{"text":"Website","color":"green","hoverEvent":{"action":"show_text","value":{"text":"Click this to go to the mod's website","color":"green"}},"clickEvent":{"action":"open_url","value":"http://minecraft.curseforge.com/projects/botania-unofficial"}},"] [",{"text":"Changelog","color":"green","hoverEvent":{"action":"show_text","value":{"text":"Click this to go to the version's Changelog","color":"green"}},"clickEvent":{"action":"open_url","value":"https://github.com/williewillus/Botania/releases/tag/%s"}},"]"] +botania.versioning.updateMessage=["Click for... [",{"text":"Download","color":"green","hoverEvent":{"action":"show_text","value":{"text":"Click this to automatically download the latest version","color":"green"}},"clickEvent":{"action":"run_command","value":"/botania-download-latest %version%"}},"] [",{"text":"Website","color":"green","hoverEvent":{"action":"show_text","value":{"text":"Click this to go to the mod's website","color":"green"}},"clickEvent":{"action":"open_url","value":"http://botaniamod.net/downloads.php"}},"] [",{"text":"Changelog","color":"green","hoverEvent":{"action":"show_text","value":{"text":"Click this to go to the version's Changelog","color":"green"}},"clickEvent":{"action":"open_url","value":"http://botaniamod.net/changelog.php#%version%"}},"]"] botania.versioning.startingDownload=[{"text":"Starting download of %s. Please do not remove your hard disk. Enjoying ","color":"aqua"},{"text":"Botania","color":"green"},{"text":"? Consider supporting ","color":"aqua"},{"text":"Vazkii","color":"light_purple"},{"text":" on [","color":"aqua"},{"text":"Patreon","color":"gold","hoverEvent":{"action":"show_text","value":{"text":"Click this to go to Vazkii's Patreon","color":"light_purple"}},"clickEvent":{"action":"open_url","value":"http://www.patreon.com/Vazkii"}},{"text":"]!","color":"aqua"}] botania.versioning.doneDownloading=Finished downloading %s. Delete your old Botania .jar and reload your game to update. botania.versioning.downloadedAlready=You already downloaded the latest version. Close your game, delete the old version from your mods folder and load it again to update!