mirror of
https://github.com/GTNewHorizons/MagicBees.git
synced 2026-11-12 16:27:34 +00:00
remove version checker
This commit is contained in:
1 parent
97a45e8e0a
commit
189d305a31
3 files changed
-299
No files matched your search
@@ -77,7 +77,6 @@ public class MagicBees {
|
||||
CraftingManager.setupCrafting();
|
||||
CraftingManager.registerLiquidContainers();
|
||||
|
||||
VersionInfo.doVersionCheck();
|
||||
LogHelper.info("Postinit completed");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
package magicbees.main.utils;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
|
||||
import magicbees.main.Config;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.event.ClickEvent;
|
||||
import net.minecraft.event.HoverEvent;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
public class TickHandlerVersion {
|
||||
|
||||
private static int TICK_POLL_INTERVAL = 250;
|
||||
|
||||
private static class LazyHolder {
|
||||
private static final TickHandlerVersion instance = new TickHandlerVersion();
|
||||
}
|
||||
|
||||
private int ticksToPoll;
|
||||
private VersionInfo versionInfo;
|
||||
|
||||
private final ChatStyle newVersion =
|
||||
new ChatStyle().setColor(EnumChatFormatting.GOLD).setBold(true);
|
||||
private final ChatStyle description = new ChatStyle().setColor(EnumChatFormatting.GRAY);
|
||||
private final ChatStyle alert = new ChatStyle().setColor(EnumChatFormatting.RED);
|
||||
|
||||
private TickHandlerVersion() {
|
||||
ticksToPoll = TICK_POLL_INTERVAL;
|
||||
}
|
||||
|
||||
private void setVersionInfo(VersionInfo vInfo) {
|
||||
versionInfo = vInfo;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void tickStart(PlayerTickEvent evt) {
|
||||
if (evt.phase != Phase.START) {
|
||||
return;
|
||||
}
|
||||
if (ticksToPoll > 0) {
|
||||
ticksToPoll--;
|
||||
return;
|
||||
}
|
||||
ticksToPoll = TICK_POLL_INTERVAL;
|
||||
|
||||
if (versionInfo.versionCheckComplete) {
|
||||
unsubscribeFromBus();
|
||||
|
||||
if (updateNotificationsEnabledOrCriticalUpdate()) {
|
||||
sendNotificationToPlayer(evt.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendNotificationToPlayer(EntityPlayer player) {
|
||||
if (versionInfo.isCriticalUpdate()) {
|
||||
player.addChatMessage(
|
||||
new ChatComponentTranslation("magicbees.versioning.critical", versionInfo.getLatestVersion())
|
||||
.setChatStyle(alert));
|
||||
} else {
|
||||
player.addChatMessage(
|
||||
new ChatComponentTranslation("magicbees.versioning.newVersion", versionInfo.getLatestVersion())
|
||||
.setChatStyle(newVersion));
|
||||
}
|
||||
ChatStyle thisDescription = description.createShallowCopy();
|
||||
thisDescription.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, VersionInfo.DownloadURL));
|
||||
thisDescription.setChatHoverEvent(new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT, new ChatComponentText(versionInfo.getVersionDescription())));
|
||||
player.addChatMessage(
|
||||
new ChatComponentTranslation("magicbees.versioning.clickDownload").setChatStyle(thisDescription));
|
||||
}
|
||||
|
||||
private boolean updateNotificationsEnabledOrCriticalUpdate() {
|
||||
return (!Config.disableUpdateNotification || versionInfo.isCriticalUpdate())
|
||||
&& versionInfo.isNewVersionAvailable();
|
||||
}
|
||||
|
||||
private void subscribeToBus() {
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
}
|
||||
|
||||
private void unsubscribeFromBus() {
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
}
|
||||
|
||||
public static void go(VersionInfo vInfo) {
|
||||
LazyHolder.instance.setVersionInfo(vInfo);
|
||||
LazyHolder.instance.subscribeToBus();
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
||||
{
|
||||
if (sent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (modIndex < modVersionInfo.size()) {
|
||||
VersionInfo anInfo = modVersionInfo.get(modIndex);
|
||||
|
||||
if ((!Config.DisableUpdateNotification || anInfo.isCriticalUpdate()) && anInfo.isNewVersionAvailable())
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer) tickData[0];
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText("[" + anInfo.modName + "] A new version is available: " + anInfo.getLatestVersion()));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(anInfo.getVersionDescription()));
|
||||
}
|
||||
modIndex += 1;
|
||||
}
|
||||
else {
|
||||
sent = true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -1,13 +1,5 @@
|
||||
package magicbees.main.utils;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Using some of the VersionInfo code from cofh. (Thanks, Lemming!)
|
||||
*
|
||||
@@ -16,179 +8,8 @@ import java.util.logging.Logger;
|
||||
public class VersionInfo {
|
||||
public static final String ModName = "MagicBees";
|
||||
public static final String Version = "GRADLETOKEN_VERSION";
|
||||
public static final String VersionURL =
|
||||
"https://raw.githubusercontent.com/MagicBees/MagicBees/master/etc/version-1.7.txt";
|
||||
public static final String DownloadURL = "http://minecraft.curseforge.com/mc-mods/65764-magic-bees/files";
|
||||
public static final String GUI_FACTORY_CLASS = "magicbees.client.gui.GuiFactory";
|
||||
|
||||
public static final String Logo = "/gfx/magicbees/logo.png";
|
||||
|
||||
public static final String Depends =
|
||||
"required-after:Forestry@[4.2.5,);after:Thaumcraft;after:ExtraBees;after:EE3;after:ArsMagica;after:TConstruct;after:Railcraft;after:ThermalFoundation;after:ThermalExpansion;after:RedstoneArsenal;after:AWWayofTime;after:Botania;after:appliedenergistics2";
|
||||
|
||||
boolean criticalUpdate;
|
||||
boolean newVersion;
|
||||
boolean versionCheckComplete;
|
||||
|
||||
String latestModVersion;
|
||||
String description = "";
|
||||
|
||||
String modName;
|
||||
String modVersion;
|
||||
String releaseURL;
|
||||
|
||||
public static int[] parseVersion(String rawVersion) {
|
||||
ArrayList<Integer> versionTokens = new ArrayList<Integer>();
|
||||
String[] tokens = rawVersion.trim().split("[\\. ]");
|
||||
|
||||
for (int i = 0; i < tokens.length; ++i) {
|
||||
tokens[i] = tokens[i].trim();
|
||||
if (tokens[i].matches("[0-9]+")) {
|
||||
versionTokens.add(Integer.valueOf(tokens[i]));
|
||||
} else if (tokens[i].matches("[0-9]+[a-z]")) {
|
||||
String numberString = tokens[i].substring(0, tokens[i].length() - 1);
|
||||
versionTokens.add(Integer.valueOf(numberString));
|
||||
versionTokens.add(Character.getNumericValue(tokens[i].charAt(tokens[i].length() - 1)));
|
||||
}
|
||||
}
|
||||
|
||||
// Can't use versionTokens.toArray 'cause that returns an Integer[], not int[]
|
||||
int[] value = new int[versionTokens.size()];
|
||||
for (int i = 0; i < value.length; ++i) {
|
||||
value[i] = versionTokens.get(i).intValue();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static boolean beforeTargetVersion(String version, String target) {
|
||||
boolean result = false;
|
||||
int[] versionTokens = parseVersion(version);
|
||||
int[] targetTokens = parseVersion(target);
|
||||
|
||||
for (int i = 0; i < versionTokens.length && i < targetTokens.length; ++i) {
|
||||
if (versionTokens[i] < targetTokens[i]) {
|
||||
result = true;
|
||||
break;
|
||||
} else if (versionTokens[i] > targetTokens[i]) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == versionTokens.length - 1 && versionTokens.length < targetTokens.length) {
|
||||
// If the versions compared are the same, but target has an extra token, it's probably a "letter" build
|
||||
// and is ahead of this one.
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean afterTargetVersion(String version, String target) {
|
||||
boolean result = false;
|
||||
int[] versionTokens = parseVersion(version);
|
||||
int[] targetTokens = parseVersion(target);
|
||||
|
||||
for (int i = 0; i < versionTokens.length && i < targetTokens.length; ++i) {
|
||||
if (versionTokens[i] > targetTokens[i]) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public VersionInfo(String name, String version, String url) {
|
||||
modName = name;
|
||||
modVersion = latestModVersion = version;
|
||||
releaseURL = url;
|
||||
}
|
||||
|
||||
public VersionInfo(String name, String version, String url, Logger logger) {
|
||||
modName = name;
|
||||
modVersion = latestModVersion = version;
|
||||
releaseURL = url;
|
||||
}
|
||||
|
||||
public void checkForNewVersion() {
|
||||
Thread versionCheckThread = new VersionCheckThread();
|
||||
versionCheckThread.start();
|
||||
}
|
||||
|
||||
public String getCurrentVersion() {
|
||||
return modVersion;
|
||||
}
|
||||
|
||||
public String getLatestVersion() {
|
||||
return latestModVersion;
|
||||
}
|
||||
|
||||
public String getVersionDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean isCriticalUpdate() {
|
||||
return criticalUpdate;
|
||||
}
|
||||
|
||||
public boolean isNewVersionAvailable() {
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
public boolean isVersionCheckComplete() {
|
||||
return versionCheckComplete;
|
||||
}
|
||||
|
||||
private class VersionCheckThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String location = VersionURL;
|
||||
|
||||
HttpURLConnection connection = null;
|
||||
|
||||
// Used to "dereference" any location headers we may get.
|
||||
while (location != null && !location.isEmpty()) {
|
||||
URL url = new URL(location);
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestProperty(
|
||||
"User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17");
|
||||
connection.connect();
|
||||
location = connection.getHeaderField("Location");
|
||||
}
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
latestModVersion = reader.readLine();
|
||||
criticalUpdate = Boolean.parseBoolean(reader.readLine());
|
||||
while (reader.ready()) {
|
||||
description = description + reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
|
||||
if (beforeTargetVersion(modVersion, latestModVersion)) {
|
||||
FMLLog.info("An updated version of " + modName + " is available: " + latestModVersion
|
||||
+ ". You are currently using " + Version);
|
||||
newVersion = true;
|
||||
if (criticalUpdate) {
|
||||
LogHelper.info(
|
||||
"This update has been marked as CRITICAL and will ignore notification suppression.");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LogHelper.warn("Version check Failed: " + e.getMessage());
|
||||
}
|
||||
versionCheckComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void doVersionCheck() {
|
||||
VersionInfo versionInfo = new VersionInfo(ModName, Version, VersionURL);
|
||||
TickHandlerVersion.go(versionInfo);
|
||||
|
||||
VersionCheckThread thread = versionInfo.new VersionCheckThread();
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user