diff --git a/MODSRC/vazkii/botania/common/core/handler/ConfigHandler.java b/MODSRC/vazkii/botania/common/core/handler/ConfigHandler.java index 71a786d17..ae143790c 100644 --- a/MODSRC/vazkii/botania/common/core/handler/ConfigHandler.java +++ b/MODSRC/vazkii/botania/common/core/handler/ConfigHandler.java @@ -31,6 +31,7 @@ public final class ConfigHandler { public static boolean blockBreakParticles = true; public static boolean blockBreakParticlesTool = true; + public static boolean versionCheckEnabled = true; public static int spreaderPositionShift = 1; public static int flowerQuantity = 3; @@ -72,6 +73,9 @@ public final class ConfigHandler { desc = "Set to false to remove the block breaking particles from the Mana Shatterer, as there can be a good amount in higher levels."; blockBreakParticlesTool = loadPropBool("blockBreakingParticlesTool.enabled", desc, blockBreakParticlesTool); + desc = "Set to false to disable checking and alerting when new Botania versions come out."; + versionCheckEnabled = loadPropBool("versionChecking.enabled", desc, versionCheckEnabled); + desc = "Do not ever touch this value if not asked to. Possible symptoms of doing so include your head turning backwards, the appearance of Titans near the walls or you being trapped in a game of Sword Art Online."; spreaderPositionShift = loadPropInt("spreader.posShift", desc, spreaderPositionShift); diff --git a/MODSRC/vazkii/botania/common/core/handler/VersionChecker.java b/MODSRC/vazkii/botania/common/core/handler/VersionChecker.java deleted file mode 100644 index 07df129a5..000000000 --- a/MODSRC/vazkii/botania/common/core/handler/VersionChecker.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * 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 a - * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License - * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) - * - * File Created @ [May 31, 2014, 9:58:26 PM (GMT)] - */ -package vazkii.botania.common.core.handler; - -public final class VersionChecker { - -} diff --git a/MODSRC/vazkii/botania/common/core/version/ThreadDownloadMod.java b/MODSRC/vazkii/botania/common/core/version/ThreadDownloadMod.java new file mode 100644 index 000000000..a5c39156c --- /dev/null +++ b/MODSRC/vazkii/botania/common/core/version/ThreadDownloadMod.java @@ -0,0 +1,119 @@ +/** + * 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 a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [May 31, 2014, 10:22:44 PM (GMT)] + */ +package vazkii.botania.common.core.version; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.util.ChatComponentTranslation; + +/** + * @author Vazkii, TheWhiteWolves + */ +public class ThreadDownloadMod extends Thread { + + public static int amountOfDownloadResourceThreads = 0; + public static List downloadings = new LinkedList(); + + URL downloadUrl; + String modName; + + long downloadStartTime; + long downloadFinishTime; + + byte[] buffer = new byte[10240]; + + int totalBytesDownloaded; + int bytesJustDownloaded; + + InputStream webReader; + + public ThreadDownloadMod(String urlToFind, String modName) { + if (urlToFind == null) + return; + + setName("Botania Download File Thread " + ++amountOfDownloadResourceThreads); + + this.modName = modName; + try { + downloadUrl = getUrlFromFile(urlToFind); + downloadUrl.openConnection(); + webReader = downloadUrl.openStream(); + downloadings.add(modName); + } catch (IOException e) { + e.printStackTrace(); + } + setDaemon(true); + start(); + } + + URL getUrlFromFile(String file) { + URL url; + try { + url = new URL(file); + BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream())); + String s = r.readLine(); + r.close(); + return new URL(s); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + @Override + public void run() { + try { + File dir = new File(".", "mods"); + File f = new File(dir, modName + ".jar"); + f.createNewFile(); + System.out.println("[Botania] Starting to download file: " + modName + ".zip to " + f.getAbsolutePath() + "."); + FileOutputStream outputStream = new FileOutputStream(f.getAbsolutePath()); + + downloadStartTime = System.currentTimeMillis(); + + while ((bytesJustDownloaded = webReader.read(buffer)) > 0) { + outputStream.write(buffer, 0, bytesJustDownloaded); + buffer = new byte[10240]; + totalBytesDownloaded += bytesJustDownloaded; + } + + downloadFinishTime = System.currentTimeMillis(); + + if (Minecraft.getMinecraft().thePlayer != null) + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation("botania.versioning.doneDownloading", modName, (downloadFinishTime - downloadStartTime) / 1000)); + + outputStream.close(); + webReader.close(); + --amountOfDownloadResourceThreads; + downloadings.remove(modName); + finalize(); + } catch (Throwable e) { + e.printStackTrace(); + --amountOfDownloadResourceThreads; + downloadings.remove(modName); + try { + finalize(); + } catch (Throwable e1) { + e1.printStackTrace(); + } + } + } +} \ No newline at end of file diff --git a/MODSRC/vazkii/botania/common/core/version/ThreadVersionChecker.java b/MODSRC/vazkii/botania/common/core/version/ThreadVersionChecker.java new file mode 100644 index 000000000..f91360fc8 --- /dev/null +++ b/MODSRC/vazkii/botania/common/core/version/ThreadVersionChecker.java @@ -0,0 +1,40 @@ +/** + * 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 a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * 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("http://raw.githubusercontent.com/Vazkii/Botania/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; + } +} diff --git a/MODSRC/vazkii/botania/common/core/version/VersionChecker.java b/MODSRC/vazkii/botania/common/core/version/VersionChecker.java new file mode 100644 index 000000000..c365a6031 --- /dev/null +++ b/MODSRC/vazkii/botania/common/core/version/VersionChecker.java @@ -0,0 +1,42 @@ +/** + * 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 a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [May 31, 2014, 9:58:26 PM (GMT)] + */ +package vazkii.botania.common.core.version; + +import net.minecraft.client.Minecraft; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Phase; + +public final class VersionChecker { + + public static boolean doneChecking = false; + public static String onlineVersion = ""; + public static boolean triedToWarnPlayer = false; + + public void init() { + new ThreadVersionChecker(); + FMLCommonHandler.instance().bus().register(this); + } + + @SubscribeEvent + public void onTick(ClientTickEvent event) { + if(doneChecking && event.phase == Phase.END && Minecraft.getMinecraft().thePlayer != null && !triedToWarnPlayer) { + if(!onlineVersion.isEmpty()) { + // TODO + } + + triedToWarnPlayer = true; + } + } + +} diff --git a/build.xml b/build.xml index 02d8e8ff4..dfaf4736f 100644 --- a/build.xml +++ b/build.xml @@ -29,7 +29,7 @@ ${line.separator}${build.version}-${build.build_number}=${build.mc_version} - ${build.build_number} + ${build.version}-${build.build_number} diff --git a/resources/assets/botania/lang/en_US.lang b/resources/assets/botania/lang/en_US.lang index 459c2ce1c..c35eb35de 100644 --- a/resources/assets/botania/lang/en_US.lang +++ b/resources/assets/botania/lang/en_US.lang @@ -53,6 +53,9 @@ botania.rank3=&aA botania.rank4=&dS botania.rank5=&6SS +# -- VERSION CHECKING +botania.versioning.doneDownloading=Finished downloading file: %s, took %i seconds. Reload your game to update. + # BAUBLE TOOLTIPS botania.baubletype.amulet=Equippable in the &aAmulet&7 slot botania.baubletype.ring=Equippable in the &aRing&7 slot diff --git a/version/1.6.2.txt b/version/1.6.2.txt deleted file mode 100644 index 19c7bdba7..000000000 --- a/version/1.6.2.txt +++ /dev/null @@ -1 +0,0 @@ -16 \ No newline at end of file diff --git a/version/1.6.4.txt b/version/1.6.4.txt new file mode 100644 index 000000000..31970f148 --- /dev/null +++ b/version/1.6.4.txt @@ -0,0 +1 @@ +beta-16 \ No newline at end of file diff --git a/version/1.7.2.txt b/version/1.7.2.txt index 86ee83a4a..bf669ebbe 100644 --- a/version/1.7.2.txt +++ b/version/1.7.2.txt @@ -1 +1 @@ -40 \ No newline at end of file +beta-40 \ No newline at end of file