Versioning system!
This commit is contained in:
parent
831981ee85
commit
34a42086d6
|
@ -26,6 +26,8 @@ import biomesoplenty.helpers.BonemealUse;
|
||||||
import biomesoplenty.helpers.CreativeTabsBOP;
|
import biomesoplenty.helpers.CreativeTabsBOP;
|
||||||
import biomesoplenty.helpers.EntitiesHelper;
|
import biomesoplenty.helpers.EntitiesHelper;
|
||||||
import biomesoplenty.helpers.Localizations;
|
import biomesoplenty.helpers.Localizations;
|
||||||
|
import biomesoplenty.helpers.TickHandlerClient;
|
||||||
|
import biomesoplenty.helpers.Version;
|
||||||
import biomesoplenty.integration.BOPCrossIntegration;
|
import biomesoplenty.integration.BOPCrossIntegration;
|
||||||
import biomesoplenty.world.WorldProviderBOPhell;
|
import biomesoplenty.world.WorldProviderBOPhell;
|
||||||
import biomesoplenty.world.WorldProviderPromised;
|
import biomesoplenty.world.WorldProviderPromised;
|
||||||
|
@ -44,8 +46,10 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||||
import cpw.mods.fml.common.network.NetworkMod;
|
import cpw.mods.fml.common.network.NetworkMod;
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||||
|
import cpw.mods.fml.common.registry.TickRegistry;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
|
||||||
@Mod(modid="BiomesOPlenty", name="Biomes O' Plenty", version="0.5.6", dependencies="after:Natura")
|
@Mod(modid="BiomesOPlenty", name="Biomes O' Plenty", version=Version.VERSION, dependencies="after:Natura")
|
||||||
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
|
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
|
||||||
public class BiomesOPlenty
|
public class BiomesOPlenty
|
||||||
{
|
{
|
||||||
|
@ -100,6 +104,8 @@ public class BiomesOPlenty
|
||||||
|
|
||||||
BOPConfiguration.init(event.getSuggestedConfigurationFile());
|
BOPConfiguration.init(event.getSuggestedConfigurationFile());
|
||||||
|
|
||||||
|
Version.check();
|
||||||
|
|
||||||
tabBiomesOPlenty = new CreativeTabsBOP(CreativeTabs.getNextID(),"tabBiomesOPlenty");
|
tabBiomesOPlenty = new CreativeTabsBOP(CreativeTabs.getNextID(),"tabBiomesOPlenty");
|
||||||
|
|
||||||
BOPPotions.init();
|
BOPPotions.init();
|
||||||
|
@ -159,5 +165,7 @@ public class BiomesOPlenty
|
||||||
public void postInit(FMLPostInitializationEvent event)
|
public void postInit(FMLPostInitializationEvent event)
|
||||||
{
|
{
|
||||||
BOPCrossIntegration.postInit();
|
BOPCrossIntegration.postInit();
|
||||||
|
|
||||||
|
TickRegistry.registerTickHandler(new TickHandlerClient(), Side.CLIENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@ package biomesoplenty.configuration;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import net.minecraft.potion.Potion;
|
import net.minecraft.potion.Potion;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
@ -12,6 +13,7 @@ import biomesoplenty.potions.PotionParalysis;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||||
|
|
||||||
public class BOPPotions
|
public class BOPPotions
|
||||||
|
@ -42,7 +44,7 @@ public class BOPPotions
|
||||||
|
|
||||||
private static void extendPotionsArray()
|
private static void extendPotionsArray()
|
||||||
{
|
{
|
||||||
System.out.println("[BiomesOPlenty] Extending Potions Array.");
|
FMLCommonHandler.instance().getFMLLogger().log(Level.INFO, "[BiomesOPlenty] Extending Potions Array.");
|
||||||
potionOffset = Potion.potionTypes.length;
|
potionOffset = Potion.potionTypes.length;
|
||||||
|
|
||||||
Potion[] potionTypes = new Potion[potionOffset + MAXNEWPOTIONS];
|
Potion[] potionTypes = new Potion[potionOffset + MAXNEWPOTIONS];
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package biomesoplenty.helpers;
|
package biomesoplenty.helpers;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||||
|
|
||||||
public class Localizations
|
public class Localizations
|
||||||
|
@ -15,7 +18,7 @@ public class Localizations
|
||||||
|
|
||||||
public static String getLocaleFromFileName(String fileName)
|
public static String getLocaleFromFileName(String fileName)
|
||||||
{
|
{
|
||||||
System.out.println("[BiomesOPlenty] Localizations loaded for " + fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('.')));
|
FMLCommonHandler.instance().getFMLLogger().log(Level.INFO, "[BiomesOPlenty] Localizations loaded for " + fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('.')));
|
||||||
return fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('.'));
|
return fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package biomesoplenty.helpers;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import cpw.mods.fml.common.ITickHandler;
|
||||||
|
import cpw.mods.fml.common.Loader;
|
||||||
|
import cpw.mods.fml.common.TickType;
|
||||||
|
|
||||||
|
public class TickHandlerClient implements ITickHandler
|
||||||
|
{
|
||||||
|
private boolean nagged;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
||||||
|
{
|
||||||
|
if (nagged)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EntityPlayer player = (EntityPlayer) tickData[0];
|
||||||
|
|
||||||
|
if (Version.needsUpdateNoticeAndMarkAsSeen())
|
||||||
|
{
|
||||||
|
player.sendChatToPlayer(String.format("\u00A7cA new version of Biomes O Plenty is available: %s for Minecraft %s", Version.getRecommendedVersion(), Loader.instance().getMinecraftModContainer().getVersion()));
|
||||||
|
|
||||||
|
for (String updateLine : Version.getChangelog())
|
||||||
|
{
|
||||||
|
player.sendChatToPlayer("\u00A79" + updateLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nagged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumSet<TickType> ticks()
|
||||||
|
{
|
||||||
|
return EnumSet.of(TickType.PLAYER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLabel()
|
||||||
|
{
|
||||||
|
return "BiomesOPlenty - Player update tick";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,206 @@
|
||||||
|
package biomesoplenty.helpers;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.Property;
|
||||||
|
import biomesoplenty.BiomesOPlenty;
|
||||||
|
import biomesoplenty.configuration.BOPConfiguration;
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
import cpw.mods.fml.common.Loader;
|
||||||
|
|
||||||
|
public class Version implements Runnable {
|
||||||
|
private static Version instance = new Version();
|
||||||
|
|
||||||
|
public enum EnumUpdateState
|
||||||
|
{
|
||||||
|
CURRENT, OUTDATED, CONNECTION_ERROR
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String VERSION = "0.5.6";
|
||||||
|
private static final String REMOTE_VERSION_FILE = "https://raw.github.com/BiomesOPlenty/BiomesOPlenty/master/version.txt";
|
||||||
|
private static final String REMOTE_CHANGELOG_ROOT = "https://raw.github.com/BiomesOPlenty/BiomesOPlenty/master/changelog/";
|
||||||
|
|
||||||
|
public static EnumUpdateState currentVersion = EnumUpdateState.CURRENT;
|
||||||
|
|
||||||
|
private static String recommendedVersion;
|
||||||
|
private static String[] cachedChangelog;
|
||||||
|
|
||||||
|
public static String getVersion()
|
||||||
|
{
|
||||||
|
return VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isOutdated()
|
||||||
|
{
|
||||||
|
return currentVersion == EnumUpdateState.OUTDATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean needsUpdateNoticeAndMarkAsSeen()
|
||||||
|
{
|
||||||
|
if (!isOutdated())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Property property = BOPConfiguration.config.get("Vars", "Seen Version", VERSION);
|
||||||
|
String seenVersion = property.getString();
|
||||||
|
|
||||||
|
if (recommendedVersion == null || recommendedVersion.equals(seenVersion))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
property.set(recommendedVersion);
|
||||||
|
|
||||||
|
BOPConfiguration.config.save();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getRecommendedVersion()
|
||||||
|
{
|
||||||
|
return recommendedVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void versionCheck()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
if ("0.0.0".equals(VERSION))
|
||||||
|
return;
|
||||||
|
|
||||||
|
String location = REMOTE_VERSION_FILE;
|
||||||
|
HttpURLConnection conn = null;
|
||||||
|
while (location != null && !location.isEmpty()) {
|
||||||
|
URL url = new URL(location);
|
||||||
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestProperty(
|
||||||
|
"User-Agent",
|
||||||
|
"Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)");
|
||||||
|
conn.connect();
|
||||||
|
location = conn.getHeaderField("Location");
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||||
|
conn.getInputStream()));
|
||||||
|
|
||||||
|
String line = null;
|
||||||
|
String mcVersion = Loader.instance().getMinecraftModContainer().getVersion();
|
||||||
|
|
||||||
|
while ((line = reader.readLine()) != null)
|
||||||
|
{
|
||||||
|
if (line.startsWith(mcVersion)) {
|
||||||
|
if (line.contains("BiomesOPlenty")) {
|
||||||
|
String[] tokens = line.split(":");
|
||||||
|
recommendedVersion = tokens[2];
|
||||||
|
|
||||||
|
if (line.endsWith(VERSION))
|
||||||
|
{
|
||||||
|
FMLCommonHandler.instance().getFMLLogger().log(Level.FINER, "[BiomesOPlenty] Using the latest version ["+ getVersion() + "] for Minecraft " + mcVersion);
|
||||||
|
|
||||||
|
currentVersion = EnumUpdateState.CURRENT;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FMLCommonHandler.instance().getFMLLogger().log(Level.WARNING,"[BiomesOPlenty] Using outdated version [" + VERSION + "] for Minecraft " + mcVersion + ". Consider updating.");
|
||||||
|
|
||||||
|
currentVersion = EnumUpdateState.OUTDATED;
|
||||||
|
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
FMLCommonHandler.instance().getFMLLogger().log(Level.WARNING, "[BiomesOPlenty] Unable to read from remote version authority.");
|
||||||
|
FMLCommonHandler.instance().getFMLLogger().log(Level.WARNING, e.toString());
|
||||||
|
|
||||||
|
currentVersion = EnumUpdateState.CONNECTION_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getChangelog()
|
||||||
|
{
|
||||||
|
if (cachedChangelog == null)
|
||||||
|
{
|
||||||
|
cachedChangelog = grabChangelog(recommendedVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cachedChangelog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] grabChangelog(String version)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
String location = REMOTE_CHANGELOG_ROOT + version + ".txt";
|
||||||
|
System.out.println(location);
|
||||||
|
HttpURLConnection conn = null;
|
||||||
|
while (location != null && !location.isEmpty()) {
|
||||||
|
URL url = new URL(location);
|
||||||
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)");
|
||||||
|
conn.connect();
|
||||||
|
location = conn.getHeaderField("Location");
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||||
|
conn.getInputStream()));
|
||||||
|
|
||||||
|
String line = null;
|
||||||
|
ArrayList<String> changelog = new ArrayList<String>();
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
if (line.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
changelog.add(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return changelog.toArray(new String[0]);
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
FMLCommonHandler.instance().getFMLLogger().log(Level.WARNING, "[BiomesOPlenty] Unable to read changelog from remote site.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new String[] { String.format("Unable to retrieve changelog for %s %s", "BiomesOPlenty", version) };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
currentVersion = null;
|
||||||
|
|
||||||
|
FMLCommonHandler.instance().getFMLLogger().log(Level.INFO, "[BiomesOPlenty] Beginning version check");
|
||||||
|
|
||||||
|
try {
|
||||||
|
while ((count < 3)
|
||||||
|
&& ((currentVersion == null) || (currentVersion == EnumUpdateState.CONNECTION_ERROR))) {
|
||||||
|
versionCheck();
|
||||||
|
count++;
|
||||||
|
|
||||||
|
if (currentVersion == EnumUpdateState.CONNECTION_ERROR) {
|
||||||
|
FMLCommonHandler.instance().getFMLLogger().log(Level.INFO, "[BiomesOPlenty] Version check attempt " + count + " failed, trying again in 10 seconds");
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentVersion == EnumUpdateState.CONNECTION_ERROR) {
|
||||||
|
FMLCommonHandler.instance().getFMLLogger().log(Level.INFO, "[BiomesOPlenty] Version check failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void check()
|
||||||
|
{
|
||||||
|
new Thread(instance).start();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1 @@
|
||||||
1.5.2:BiomesOPlenty:0.5.5
|
1.5.2:BiomesOPlenty:0.5.6
|
Loading…
Reference in New Issue