Remote version check implemented, now on to Localization

This commit is contained in:
pahimar 2012-09-25 15:01:39 -04:00
parent 051b51c5ba
commit cabe68356d
5 changed files with 171 additions and 5 deletions

View file

@ -36,7 +36,7 @@ public class KeyBindingHandler extends KeyBindingRegistry.KeyHandler {
@Override
public String getLabel() {
return Reference.MOD_NAME + " KeyBindingHandler";
return Reference.MOD_NAME + ": " + this.getClass().getSimpleName();
}
@Override

View file

@ -1,11 +1,13 @@
package ee3.common;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
@ -13,16 +15,18 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.TickRegistry;
import ee3.common.block.ModBlocks;
import ee3.common.core.CommonProxy;
import ee3.common.core.RecipesTransmutationStone;
import ee3.common.core.handlers.AddonHandler;
import ee3.common.core.handlers.ConfigurationHandler;
import ee3.common.core.handlers.CraftingHandler;
import ee3.common.core.handlers.EntityLivingHandler;
import ee3.common.core.handlers.ItemPickupHandler;
import ee3.common.core.handlers.PacketHandler;
import ee3.common.core.handlers.PlayerDestroyItemHandler;
import ee3.common.core.handlers.VersionCheckTickHandler;
import ee3.common.core.helper.VersionHelper;
import ee3.common.item.ModItems;
import ee3.common.lib.Reference;
@ -51,17 +55,23 @@ public class EquivalentExchange3 {
// Initialize the configuration
ConfigurationHandler.init(event.getSuggestedConfigurationFile());
// Conduct the version check
VersionHelper.checkVersion();
// Initialize the Version Check Tick Handler (Client only)
TickRegistry.registerTickHandler(new VersionCheckTickHandler(), Side.CLIENT);
// Register the KeyBinding Handler (Client only)
proxy.registerKeyBindingHandler();
// Register the Sound Handler (Client only)
proxy.registerSoundHandler();
}
@Init
public void load(FMLInitializationEvent event) {
// Initialize the custom item rarity types
proxy.initCustomRarityTypes();
@ -98,7 +108,7 @@ public class EquivalentExchange3 {
public void modsLoaded(FMLPostInitializationEvent event) {
// Initialize the Addon Handler
AddonHandler.init();
AddonHandler.init();
}
}

View file

@ -0,0 +1,5 @@
package ee3.common.core.handlers;
public class LocalizationHandler {
}

View file

@ -0,0 +1,42 @@
package ee3.common.core.handlers;
import java.util.EnumSet;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import ee3.common.core.helper.VersionHelper;
import ee3.common.lib.Reference;
public class VersionCheckTickHandler implements ITickHandler {
private static boolean initialized = false;
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) { }
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
if (!initialized) {
for (TickType tickType : type) {
if (tickType == TickType.CLIENT) {
if (FMLClientHandler.instance().getClient().currentScreen == null) {
initialized = true;
FMLClientHandler.instance().getClient().ingameGUI.getChatGUI().printChatMessage(VersionHelper.getResultMessage());
}
}
}
}
}
@Override
public EnumSet<TickType> ticks() {
return EnumSet.of(TickType.CLIENT);
}
@Override
public String getLabel() {
return Reference.MOD_NAME + ": " + this.getClass().getSimpleName();
}
}

View file

@ -0,0 +1,109 @@
package ee3.common.core.helper;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import ee3.common.lib.Reference;
/**
* 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
*
* @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;
// Var to hold the result of the remote version check
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
result = CONNECTION_ERROR;
}
logResult();
}
public static void logResult() {
if ((result == CURRENT) || (result == OUTDATED)) {
FMLCommonHandler.instance().getFMLLogger().fine(getResultMessage());
}
else {
FMLCommonHandler.instance().getFMLLogger().warning(getResultMessage());
}
}
public static String getResultMessage() {
if (result == UNINITIALIZED) {
return "Uninitialized";
}
else if (result == CURRENT) {
return "Current";
}
else if (result == OUTDATED) {
return "Outdated";
}
else if (result == CONNECTION_ERROR) {
return "Connection Error";
}
else {
return null;
}
}
}