diff --git a/ee3_common/ee3/common/core/handlers/VersionCheckTickHandler.java b/ee3_common/ee3/common/core/handlers/VersionCheckTickHandler.java index 6608c45a..ce264c86 100644 --- a/ee3_common/ee3/common/core/handlers/VersionCheckTickHandler.java +++ b/ee3_common/ee3/common/core/handlers/VersionCheckTickHandler.java @@ -4,7 +4,9 @@ import java.util.EnumSet; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.ITickHandler; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.TickType; +import cpw.mods.fml.common.registry.LanguageRegistry; import ee3.common.core.helper.VersionHelper; import ee3.common.lib.Colours; import ee3.common.lib.ConfigurationSettings; @@ -13,7 +15,8 @@ import ee3.common.lib.Reference; /** * VersionCheckTickHandler * - * Class for notifying the player on their client when they get in game the outcome of the remote version check + * Class for notifying the player on their client when they get in game the + * outcome of the remote version check * * @author pahimar * @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html) @@ -21,37 +24,42 @@ import ee3.common.lib.Reference; */ public class VersionCheckTickHandler implements ITickHandler { - private static boolean initialized = false; - - @Override - public void tickStart(EnumSet type, Object... tickData) { } + private static boolean initialized = false; - @Override - public void tickEnd(EnumSet type, Object... tickData) { - if (ConfigurationSettings.ENABLE_VERSION_CHECK) { - if (!initialized) { - for (TickType tickType : type) { - if (tickType == TickType.CLIENT) { - if (FMLClientHandler.instance().getClient().currentScreen == null) { - initialized = true; - if (VersionHelper.result != VersionHelper.CURRENT){ - FMLClientHandler.instance().getClient().ingameGUI.getChatGUI().printChatMessage(Colours.VERSION_CHECK_PREFIX + "[" + Reference.MOD_NAME + "] " + VersionHelper.getResultMessage()); - } - } - } - } - } - } - } + @Override + public void tickStart(EnumSet type, Object... tickData) { - @Override - public EnumSet ticks() { - return EnumSet.of(TickType.CLIENT); - } + } + + @Override + public void tickEnd(EnumSet type, Object... tickData) { + + if (ConfigurationSettings.ENABLE_VERSION_CHECK) { + if (!initialized) { + for (TickType tickType : type) { + if (tickType == TickType.CLIENT) { + if (FMLClientHandler.instance().getClient().currentScreen == null) { + initialized = true; + if (VersionHelper.result == VersionHelper.OUTDATED) { + FMLClientHandler.instance().getClient().ingameGUI.getChatGUI().printChatMessage(VersionHelper.getResultMessageForClient()); + } + } + } + } + } + } + } + + @Override + public EnumSet ticks() { + + return EnumSet.of(TickType.CLIENT); + } + + @Override + public String getLabel() { + + return Reference.MOD_NAME + ": " + this.getClass().getSimpleName(); + } - @Override - public String getLabel() { - return Reference.MOD_NAME + ": " + this.getClass().getSimpleName(); - } - } diff --git a/ee3_common/ee3/common/core/helper/VersionHelper.java b/ee3_common/ee3/common/core/helper/VersionHelper.java index 48d39417..37e67e00 100644 --- a/ee3_common/ee3/common/core/helper/VersionHelper.java +++ b/ee3_common/ee3/common/core/helper/VersionHelper.java @@ -1,131 +1,151 @@ package ee3.common.core.helper; -import java.io.BufferedReader; -import java.io.InputStreamReader; +import java.io.IOException; +import java.io.InputStream; import java.net.URL; +import java.util.Properties; import java.util.logging.Level; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.registry.LanguageRegistry; +import ee3.common.lib.Colours; import ee3.common.lib.ConfigurationSettings; import ee3.common.lib.Reference; +import ee3.common.lib.Strings; /** * VersionHelper * - * Contains methods for checking the version of the currently running instance of the mod against a remote version number authority. - * Meant to help users by notifying them if they are behind the latest published version of the mod + * Contains methods for checking the version of the currently running instance + * of the mod against a remote version number authority. Meant to help users by + * notifying them if they are behind the latest published version of the mod * * @author pahimar * @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html) * */ public class VersionHelper { - - // The (publicly available) remote version number authority file - private static final String REMOTE_VERSION_FILE = "https://dl.dropbox.com/u/25591134/EE3/version.txt"; - - // All possible results of the remote version number check - public static final byte UNINITIALIZED = 0; - public static final byte CURRENT = 1; - public static final byte OUTDATED = 2; - public static final byte CONNECTION_ERROR = 3; - - // Localization keys - private static final String VERSION_CHECK_DISABLED = "version.check_disabled"; - private static final String VERSION_CHECK_INIT_LOG_MESSAGE = "version.init_log_message"; - private static final String UNINITIALIZED_MESSAGE = "version.uninitialized"; - private static final String CURRENT_MESSAGE = "version.current"; - private static final String OUTDATED_MESSAGE = "version.outdated"; - private static final String CONNECTION_ERROR_MESSAGE = "version.connection_error"; - // Var to hold the result of the remote version check, initially set to uninitialized - public static byte result = UNINITIALIZED; - - /*** - * Checks the version of the currently running instance of the mod against the remote version authority, and sets the result of the check appropriately - */ - public static void checkVersion() { - try { - URL url = new URL(REMOTE_VERSION_FILE); - - InputStreamReader isr = new InputStreamReader(url.openStream()); - BufferedReader reader = new BufferedReader(isr); - - String line = null; - - // While we are not at the end of the file, fetch the next line in the file - while ((line = reader.readLine()) != null) { - // If the current line is for this version of Minecraft, read further - if (line.startsWith(Loader.instance().getMCVersionString())) { - // If the current line is also for this mod, read further - if (line.contains(Reference.CHANNEL_NAME)) { - // If the current line is also the same as the running version of the mod, set the result appropriately - if (line.endsWith(Reference.VERSION)) { - // Set the version check result to CURRENT - result = CURRENT; - - // Close the associated network resources - reader.close(); - isr.close(); - - return; - } - } - } - } - - // Since this mod version is not the current version, set the version check appropriately - result = OUTDATED; - - // Close the associated network resources - reader.close(); - isr.close(); - } catch (Exception e) { - // If we cannot connect to the remote version number authority, set the version check appropriately - e.printStackTrace(System.err); - result = CONNECTION_ERROR; - } - - } - - public static void logResult() { - if (ConfigurationSettings.ENABLE_VERSION_CHECK) { - LogHelper.log(Level.INFO, LanguageRegistry.instance().getStringLocalization(VERSION_CHECK_INIT_LOG_MESSAGE) + " " + REMOTE_VERSION_FILE); - if ((result == CURRENT) || (result == OUTDATED)) { - LogHelper.log(Level.INFO, getResultMessage()); - } - else { - LogHelper.log(Level.WARNING, getResultMessage()); - } - } - else { - LogHelper.log(Level.INFO, getResultMessage()); - } - } - - public static String getResultMessage() { - if (ConfigurationSettings.ENABLE_VERSION_CHECK) { - if (result == UNINITIALIZED) { - return LanguageRegistry.instance().getStringLocalization(UNINITIALIZED_MESSAGE); - } - else if (result == CURRENT) { - return LanguageRegistry.instance().getStringLocalization(CURRENT_MESSAGE); - } - else if (result == OUTDATED) { - return LanguageRegistry.instance().getStringLocalization(OUTDATED_MESSAGE); - } - else if (result == CONNECTION_ERROR) { - return LanguageRegistry.instance().getStringLocalization(CONNECTION_ERROR_MESSAGE); - } - else { - return null; - } - } - else { - return LanguageRegistry.instance().getStringLocalization(VERSION_CHECK_DISABLED); - } - } + // The (publicly available) remote version number authority file + private static final String REMOTE_VERSION_XML_FILE = "https://raw.github.com/pahimar/Equivalent-Exchange-3/master/version.xml"; + + public static Properties remoteVersionProperties = new Properties(); + + // All possible results of the remote version number check + public static final byte UNINITIALIZED = 0; + public static final byte CURRENT = 1; + public static final byte OUTDATED = 2; + public static final byte GENERAL_ERROR = 3; + + // Var to hold the result of the remote version check, initially set to uninitialized + public static byte result = UNINITIALIZED; + public static String remoteVersion = null; + public static String remoteUpdateLocation = null; + + /*** + * Checks the version of the currently running instance of the mod against + * the remote version authority, and sets the result of the check + * appropriately + */ + public static void checkVersion() { + + InputStream remoteVersionRepoStream = null; + + try { + URL remoteVersionURL = new URL(REMOTE_VERSION_XML_FILE); + remoteVersionRepoStream = remoteVersionURL.openStream(); + remoteVersionProperties.loadFromXML(remoteVersionRepoStream); + + String remoteVersionProperty = remoteVersionProperties.getProperty(Loader.instance().getMCVersionString()); + + if (remoteVersionProperty != null) { + remoteVersion = remoteVersionProperty.substring(0, remoteVersionProperty.indexOf("|")); + remoteUpdateLocation = remoteVersionProperty.substring(remoteVersionProperty.indexOf("|") + 1); + } + + if ((remoteVersion != null) && (remoteVersion.equals(Reference.VERSION))) { + result = CURRENT; + return; + } + + result = OUTDATED; + } + catch (IOException e) { + e.printStackTrace(); + } + finally { + if (result == UNINITIALIZED) { + result = GENERAL_ERROR; + } + + try { + if (remoteVersionRepoStream != null) { + remoteVersionRepoStream.close(); + } + } + catch (IOException ex) { + ex.printStackTrace(); + } + } + } + + public static void logResult() { + + if (ConfigurationSettings.ENABLE_VERSION_CHECK) { + LogHelper.log(Level.INFO, LanguageRegistry.instance().getStringLocalization(Strings.VERSION_CHECK_INIT_LOG_MESSAGE) + " " + REMOTE_VERSION_XML_FILE); + if ((result == CURRENT) || (result == OUTDATED)) { + LogHelper.log(Level.INFO, getResultMessage()); + } + else { + LogHelper.log(Level.WARNING, getResultMessage()); + } + } + else { + LogHelper.log(Level.INFO, getResultMessage()); + } + } + + public static String getResultMessage() { + + if (ConfigurationSettings.ENABLE_VERSION_CHECK) { + if (result == UNINITIALIZED) { + return LanguageRegistry.instance().getStringLocalization(Strings.UNINITIALIZED_MESSAGE); + } + else if (result == CURRENT) { + String returnString = LanguageRegistry.instance().getStringLocalization(Strings.CURRENT_MESSAGE); + returnString = returnString.replace("@REMOTE_MOD_VERSION@", remoteVersion); + returnString = returnString.replace("@MINECRAFT_VERSION@", Loader.instance().getMCVersionString()); + return returnString; + } + else if (result == OUTDATED) { + String returnString = LanguageRegistry.instance().getStringLocalization(Strings.OUTDATED_MESSAGE); + returnString = returnString.replace("@MOD_NAME@", Reference.MOD_NAME); + returnString = returnString.replace("@REMOTE_MOD_VERSION@", remoteVersion); + returnString = returnString.replace("@MINECRAFT_VERSION@", Loader.instance().getMCVersionString()); + returnString = returnString.replace("@MOD_UPDATE_LOCATION@", remoteUpdateLocation); + return returnString; + } + else if (result == GENERAL_ERROR) { + return LanguageRegistry.instance().getStringLocalization(Strings.GENERAL_ERROR_MESSAGE); + } + else { + return null; + } + } + else { + return LanguageRegistry.instance().getStringLocalization(Strings.VERSION_CHECK_DISABLED); + } + } + + public static String getResultMessageForClient() { + + String returnString = LanguageRegistry.instance().getStringLocalization(Strings.OUTDATED_MESSAGE); + returnString = returnString.replace("@MOD_NAME@", Colours.TEXT_COLOUR_PREFIX_YELLOW + Reference.MOD_NAME + Colours.TEXT_COLOUR_PREFIX_WHITE); + returnString = returnString.replace("@REMOTE_MOD_VERSION@", Colours.TEXT_COLOUR_PREFIX_YELLOW + VersionHelper.remoteVersion + Colours.TEXT_COLOUR_PREFIX_WHITE); + returnString = returnString.replace("@MINECRAFT_VERSION@", Colours.TEXT_COLOUR_PREFIX_YELLOW + Loader.instance().getMCVersionString() + Colours.TEXT_COLOUR_PREFIX_WHITE); + returnString = returnString.replace("@MOD_UPDATE_LOCATION@", Colours.TEXT_COLOUR_PREFIX_YELLOW + VersionHelper.remoteUpdateLocation + Colours.TEXT_COLOUR_PREFIX_WHITE); + return returnString; + } } diff --git a/ee3_common/ee3/common/lib/Colours.java b/ee3_common/ee3/common/lib/Colours.java index 070979e6..a65fe95f 100644 --- a/ee3_common/ee3/common/lib/Colours.java +++ b/ee3_common/ee3/common/lib/Colours.java @@ -14,6 +14,8 @@ public class Colours { public static final String PURE_RED = "ff0000"; /* Text colour related constants */ - public static final String VERSION_CHECK_PREFIX = "\u00a7e"; + public static final String TEXT_COLOUR_PREFIX_YELLOW = "\u00a7e"; + + public static final String TEXT_COLOUR_PREFIX_WHITE = "\u00a7f"; } diff --git a/ee3_common/ee3/common/lib/CustomItemRarity.java b/ee3_common/ee3/common/lib/CustomItemRarity.java index eb9e0ab3..51f0b6ae 100644 --- a/ee3_common/ee3/common/lib/CustomItemRarity.java +++ b/ee3_common/ee3/common/lib/CustomItemRarity.java @@ -53,4 +53,4 @@ public class CustomItemRarity { public static final String DISPLAY_NAME_EPIC = "Epic"; public static final String DISPLAY_NAME_LEGENDARY = "Legendary"; -} \ No newline at end of file +} diff --git a/ee3_common/ee3/common/lib/Reference.java b/ee3_common/ee3/common/lib/Reference.java index 6d344c9e..e5ef090e 100644 --- a/ee3_common/ee3/common/lib/Reference.java +++ b/ee3_common/ee3/common/lib/Reference.java @@ -23,13 +23,13 @@ public class Reference { public static final int SHIFTED_ID_RANGE_CORRECTION = 256; public static final String SERVER_PROXY_CLASS = "ee3.common.core.CommonProxy"; public static final String CLIENT_PROXY_CLASS = "ee3.client.core.ClientProxy"; - + /* Configuration related constants */ public static final String ENABLE_VERSION_CHECK = "enable_version_check"; public static final String ENABLE_SOUNDS = "enable_sounds"; public static final String ENABLE_PARTICLE_FX = "enable_particle_fx"; public static final String AUTO_RESOLVE_BLOCK_IDS = "auto_resolve_block_ids"; - + /* KeyBinding related constants */ public static final String KEYBINDING_EXTRA = "key.extra"; public static final int KEYBINDING_EXTRA_DEFAULT = 46; @@ -47,12 +47,12 @@ public class Reference { public static final String ITEM_SPRITE_SHEET = "ee3_items.png"; public static final String BLOCK_SPRITE_SHEET = "ee3_blocks.png"; public static final String CALCINATOR_TEXTURE_SHEET = "calcinator.png"; - + /* General Tile Entity related constants */ public static final String TE_GEN_OWNER_NBT_TAG_LABEL = "owner"; public static final String TE_GEN_STATE_NBT_TAG_LABEL = "state"; public static final String TE_GEN_DIRECTION_NBT_TAG_LABEL = "direction"; - + // TODO: Find a better spot for these public static final int BLOCK_RED_WATER_EFFECT_DURATION_BASE = 5; public static final int BLOCK_RED_WATER_EFFECT_DURATION_MODIFIER = 2; diff --git a/ee3_common/ee3/common/lib/Strings.java b/ee3_common/ee3/common/lib/Strings.java index 1a180f4b..8e31eda1 100644 --- a/ee3_common/ee3/common/lib/Strings.java +++ b/ee3_common/ee3/common/lib/Strings.java @@ -3,8 +3,14 @@ package ee3.common.lib; public class Strings { /* General text keys */ - public static final String TEXT_IMPURE = "text.impure"; - public static final String TEXT_PURE = "text.pure"; + + /* Version check related constants */ + public static final String VERSION_CHECK_DISABLED = "version.check_disabled"; + public static final String VERSION_CHECK_INIT_LOG_MESSAGE = "version.init_log_message"; + public static final String UNINITIALIZED_MESSAGE = "version.uninitialized"; + public static final String CURRENT_MESSAGE = "version.current"; + public static final String OUTDATED_MESSAGE = "version.outdated"; + public static final String GENERAL_ERROR_MESSAGE = "version.general_error"; /* Gui related constants */ public static final String GUI_CALCINATOR_NAME = "gui.calcinator.name"; diff --git a/resources/ee3/lang/en_US.xml b/resources/ee3/lang/en_US.xml index 233decf6..66e55db6 100644 --- a/resources/ee3/lang/en_US.xml +++ b/resources/ee3/lang/en_US.xml @@ -21,12 +21,10 @@ Calcinator Calcinator Equivalent Exchange 3 - Impure - Pure - Initializing version check against the remote version authority file, located at - The version check did not complete successfully (version check did not initialize properly) - You are currently using the most up to date version for your version of Minecraft - You are currently using an out of date version; consider updating here - http://goo.gl/Ria2V - Error connecting to the remote version authority file (check your Internet connection?) + Initializing remote version check against remote version authority, located at + Remote version check failed to initialize properly + Currently using the most up to date version (@REMOTE_MOD_VERSION@) of Equivalent Exchange 3 for @MINECRAFT_VERSION@ + A new @MOD_NAME@ version exists (@REMOTE_MOD_VERSION@) for @MINECRAFT_VERSION@. Get it here: @MOD_UPDATE_LOCATION@ + Error checking the remote version authority file Remote version check disabled, skipping