diff --git a/MODSRC/vazkii/botania/client/core/proxy/ClientProxy.java b/MODSRC/vazkii/botania/client/core/proxy/ClientProxy.java index a52071c60..561ec849d 100644 --- a/MODSRC/vazkii/botania/client/core/proxy/ClientProxy.java +++ b/MODSRC/vazkii/botania/client/core/proxy/ClientProxy.java @@ -50,11 +50,14 @@ import vazkii.botania.common.block.tile.mana.TileSpreader; import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.core.helper.Vector3; import vazkii.botania.common.core.proxy.CommonProxy; +import vazkii.botania.common.core.version.CommandDownloadLatest; +import vazkii.botania.common.core.version.VersionChecker; import vazkii.botania.common.item.ModItems; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; public class ClientProxy extends CommonProxy { @@ -68,7 +71,9 @@ public class ClientProxy extends CommonProxy { MinecraftForge.EVENT_BUS.register(new CapeHandler()); if(ConfigHandler.boundBlockWireframe) MinecraftForge.EVENT_BUS.register(new BoundTileRenderer()); - + if(ConfigHandler.versionCheckEnabled) + new VersionChecker().init(); + initRenderers(); } @@ -98,7 +103,7 @@ public class ClientProxy extends CommonProxy { ShaderHelper.initShaders(); } - + @Override public void setEntryToOpen(LexiconEntry entry) { GuiLexicon.currentOpenLexicon = new GuiLexiconEntry(entry, new GuiLexiconIndex(entry.category)); diff --git a/MODSRC/vazkii/botania/common/Botania.java b/MODSRC/vazkii/botania/common/Botania.java index a301efed5..96c6ea722 100644 --- a/MODSRC/vazkii/botania/common/Botania.java +++ b/MODSRC/vazkii/botania/common/Botania.java @@ -23,6 +23,7 @@ import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLMissingMappingsEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.event.FMLServerStoppingEvent; @Mod(modid = LibMisc.MOD_ID, name = LibMisc.MOD_NAME, version = LibMisc.VERSION, dependencies = LibMisc.DEPENDENCIES) @@ -49,11 +50,16 @@ public class Botania { proxy.postInit(event); } + @EventHandler + public void serverStarting(FMLServerStartingEvent event) { + proxy.serverStarting(event); + } + @EventHandler public void serverStopping(FMLServerStoppingEvent event) { ManaNetworkHandler.instance.clear(); } - + @EventHandler public void missingMappings(FMLMissingMappingsEvent event) { AliasHandler.onMissingMappings(event); diff --git a/MODSRC/vazkii/botania/common/core/proxy/CommonProxy.java b/MODSRC/vazkii/botania/common/core/proxy/CommonProxy.java index 94b87e04b..06999f0ba 100644 --- a/MODSRC/vazkii/botania/common/core/proxy/CommonProxy.java +++ b/MODSRC/vazkii/botania/common/core/proxy/CommonProxy.java @@ -28,6 +28,7 @@ import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.core.handler.InternalMethodHandler; import vazkii.botania.common.core.handler.ManaNetworkHandler; import vazkii.botania.common.core.helper.Vector3; +import vazkii.botania.common.core.version.CommandDownloadLatest; import vazkii.botania.common.crafting.ModCrafingRecipes; import vazkii.botania.common.crafting.ModManaAlchemyRecipes; import vazkii.botania.common.crafting.ModManaInfusionRecipes; @@ -42,6 +43,7 @@ import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.network.NetworkRegistry; public class CommonProxy { @@ -83,6 +85,10 @@ public class CommonProxy { break; } } + + public void serverStarting(FMLServerStartingEvent event) { + event.registerServerCommand(new CommandDownloadLatest()); + } public void setEntryToOpen(LexiconEntry entry) { // NO-OP diff --git a/MODSRC/vazkii/botania/common/core/version/CommandDownloadLatest.java b/MODSRC/vazkii/botania/common/core/version/CommandDownloadLatest.java new file mode 100644 index 000000000..463a62818 --- /dev/null +++ b/MODSRC/vazkii/botania/common/core/version/CommandDownloadLatest.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, 11:43:13 PM (GMT)] + */ +package vazkii.botania.common.core.version; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.EnumChatFormatting; + +public class CommandDownloadLatest extends CommandBase { + + @Override + public String getCommandName() { + return "botania-download-latest"; + } + + @Override + public String getCommandUsage(ICommandSender var1) { + return "/botania-download-latest "; + } + + @Override + public void processCommand(ICommandSender var1, String[] var2) { + if(var2.length == 1) + if(VersionChecker.downloadedFile) + var1.addChatMessage(new ChatComponentTranslation("botania.versioning.downloadedAlready").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); + else if(VersionChecker.startedDownload) + var1.addChatMessage(new ChatComponentTranslation("botania.versioning.downloadingAlready").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); + else new ThreadDownloadMod("Botania " + var2[0] + ".jar"); + } + +} diff --git a/MODSRC/vazkii/botania/common/core/version/ThreadDownloadMod.java b/MODSRC/vazkii/botania/common/core/version/ThreadDownloadMod.java index a5c39156c..abe544e8b 100644 --- a/MODSRC/vazkii/botania/common/core/version/ThreadDownloadMod.java +++ b/MODSRC/vazkii/botania/common/core/version/ThreadDownloadMod.java @@ -11,32 +11,25 @@ */ 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; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.EnumChatFormatting; +import vazkii.botania.common.Botania; +import cpw.mods.fml.common.FMLCommonHandler; /** * @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; + String fileName; byte[] buffer = new byte[10240]; @@ -45,75 +38,72 @@ public class ThreadDownloadMod extends Thread { InputStream webReader; - public ThreadDownloadMod(String urlToFind, String modName) { - if (urlToFind == null) - return; + public ThreadDownloadMod(String fileName) { + setName("Botania Download File Thread"); + this.fileName = fileName; - 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 { + if(Minecraft.getMinecraft().thePlayer != null) + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation("botania.versioning.startingDownload", fileName).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GOLD))); + + VersionChecker.startedDownload = true; + + String domain = "vazkii.us"; // "localhost/xampp"; + String base = "http://" + domain + "/mod/Botania/"; + String file = fileName.replaceAll(" ", "%20"); + URL url = new URL(base + "dl.php?file=" + file); + + try { + url.openStream(); // Add to DL Counter + } catch(IOException e) { } + + url = new URL(base + "files/" + file); + webReader = url.openStream(); + + File dir = new File(".", "mods"); - File f = new File(dir, modName + ".jar"); + File f = new File(dir, fileName); f.createNewFile(); - System.out.println("[Botania] Starting to download file: " + modName + ".zip to " + f.getAbsolutePath() + "."); + + File botaniaFile = FMLCommonHandler.instance().findContainerFor(Botania.instance).getSource(); + if(!botaniaFile.isDirectory()) + botaniaFile.deleteOnExit(); + FileOutputStream outputStream = new FileOutputStream(f.getAbsolutePath()); - downloadStartTime = System.currentTimeMillis(); - - while ((bytesJustDownloaded = webReader.read(buffer)) > 0) { + 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", fileName).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN))); - if (Minecraft.getMinecraft().thePlayer != null) - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation("botania.versioning.doneDownloading", modName, (downloadFinishTime - downloadStartTime) / 1000)); + VersionChecker.downloadedFile = true; outputStream.close(); webReader.close(); - --amountOfDownloadResourceThreads; - downloadings.remove(modName); finalize(); - } catch (Throwable e) { + } catch(Throwable e) { e.printStackTrace(); - --amountOfDownloadResourceThreads; - downloadings.remove(modName); + sendError(); try { finalize(); - } catch (Throwable e1) { + } catch(Throwable e1) { e1.printStackTrace(); } } } + + private void sendError() { + if(Minecraft.getMinecraft().thePlayer != null) + Minecraft.getMinecraft().thePlayer.addChatComponentMessage(new ChatComponentTranslation("botania.versioning.error").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); + } } \ 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 index f91360fc8..be7299194 100644 --- a/MODSRC/vazkii/botania/common/core/version/ThreadVersionChecker.java +++ b/MODSRC/vazkii/botania/common/core/version/ThreadVersionChecker.java @@ -28,7 +28,7 @@ public class ThreadVersionChecker extends Thread { @Override public void run() { try { - URL url = new URL("http://raw.githubusercontent.com/Vazkii/Botania/master/version/" + MinecraftForge.MC_VERSION + ".txt"); + URL url = new URL("https://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(); diff --git a/MODSRC/vazkii/botania/common/core/version/VersionChecker.java b/MODSRC/vazkii/botania/common/core/version/VersionChecker.java index c365a6031..f47d7475e 100644 --- a/MODSRC/vazkii/botania/common/core/version/VersionChecker.java +++ b/MODSRC/vazkii/botania/common/core/version/VersionChecker.java @@ -12,6 +12,12 @@ package vazkii.botania.common.core.version; import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; +import net.minecraft.util.StatCollector; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent; @@ -23,6 +29,9 @@ public final class VersionChecker { public static String onlineVersion = ""; public static boolean triedToWarnPlayer = false; + public static boolean startedDownload = false; + public static boolean downloadedFile = false; + public void init() { new ThreadVersionChecker(); FMLCommonHandler.instance().bus().register(this); @@ -32,7 +41,16 @@ public final class VersionChecker { public void onTick(ClientTickEvent event) { if(doneChecking && event.phase == Phase.END && Minecraft.getMinecraft().thePlayer != null && !triedToWarnPlayer) { if(!onlineVersion.isEmpty()) { - // TODO + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + int onlineBuild = Integer.parseInt(onlineVersion.split("-")[1]); + int clientBuild = 39;//LibMisc.BUILD.contains("ANT") ? Integer.MAX_VALUE : Integer.parseInt(LibMisc.BUILD); TODO + if(onlineBuild > clientBuild) { + player.addChatComponentMessage(new ChatComponentTranslation("botania.versioning.flavour" + player.worldObj.rand.nextInt(16)).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.LIGHT_PURPLE))); + player.addChatComponentMessage(new ChatComponentTranslation("botania.versioning.outdated", clientBuild, onlineBuild)); + + IChatComponent component = IChatComponent.Serializer.func_150699_a(StatCollector.translateToLocal("botania.versioning.updateMessage").replaceAll("%version%", onlineVersion)); + player.addChatComponentMessage(component); + } } triedToWarnPlayer = true; diff --git a/MODSRC/vazkii/botania/common/lib/LibMisc.java b/MODSRC/vazkii/botania/common/lib/LibMisc.java index 334e008e4..013af3765 100644 --- a/MODSRC/vazkii/botania/common/lib/LibMisc.java +++ b/MODSRC/vazkii/botania/common/lib/LibMisc.java @@ -16,7 +16,8 @@ public final class LibMisc { // Mod Constants public static final String MOD_ID = "Botania"; public static final String MOD_NAME = MOD_ID; - public static final String VERSION = "ANT:VERSION-ANT:BUILD"; + public static final String BUILD = "ANT:BUILD"; + public static final String VERSION = "ANT:VERSION-" + BUILD; public static final String DEPENDENCIES = "required-after:Forge@[10.12.0.1065,);"; // Network Contants diff --git a/resources/assets/botania/lang/en_US.lang b/resources/assets/botania/lang/en_US.lang index c35eb35de..667b34ead 100644 --- a/resources/assets/botania/lang/en_US.lang +++ b/resources/assets/botania/lang/en_US.lang @@ -54,7 +54,29 @@ botania.rank4=&dS botania.rank5=&6SS # -- VERSION CHECKING -botania.versioning.doneDownloading=Finished downloading file: %s, took %i seconds. Reload your game to update. +botania.versioning.flavour0=NANI SORE!? BOTANIA IS OUTDATED!? +botania.versioning.flavour1=What do you mean Botania is outdated, you ignorant fool? +botania.versioning.flavour2=It's not like Botania wants to be outdated, b-b-BAKA! +botania.versioning.flavour3=Beam me up Scotty. We got a new Botania version. +botania.versioning.flavour4=The Botania update asks if you have you accepted Vazkii as your lord and saviour. +botania.versioning.flavour5=Hey, a Botania update, that's rare, isn't it? +botania.versioning.flavour6=What does the scouter say about the Botania update? +botania.versioning.flavour7=Oi mate, there's a new Botania update. Why am I australian? +botania.versioning.flavour8=Because having a life is too mainstream, here's a Botania update. +botania.versioning.flavour9=Thank you based Botania update. +botania.versioning.flavour10=Two hundred updates, that's why they call me Mister Fahrenheit. +botania.versioning.flavour11=Perry the Platypus, I present to you, Botania-update-inator. +botania.versioning.flavour12=Botania updated. #hoennconfirmed +botania.versioning.flavour13=You activated my Trap Card! I play Botania Update! +botania.versioning.flavour14=Let's play a drinking game. have a drink every time Botania updates. +botania.versioning.flavour15=Pay no attention to the Botania update behind the curtain. +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 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://vazkii.us/mod/Botania/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://vazkii.us/mod/Botania/changelog.php#%version%"}},"]"] +botania.versioning.startingDownload=Starting download of %s. Please do not remove your hard disk. +botania.versioning.doneDownloading=Finished downloading %s. Reload your game to update. +botania.versioning.downloadedAlready=You already downloaded the latest version. Reload your game to update. +botania.versioning.downloadingAlready=The update is already downloading, give it some time, will you? +botania.versioning.error=Woah! It seems like something went wrong while trying to download the Botania update. Check your FML log for more info. # BAUBLE TOOLTIPS botania.baubletype.amulet=Equippable in the &aAmulet&7 slot