Added Version Checker integration and fixed changelog grabbing

This commit is contained in:
Dynious 2014-06-08 11:17:27 +02:00
parent daae576b87
commit b80c95ea03

View file

@ -15,7 +15,9 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import net.minecraft.command.ICommandSender; import net.minecraft.command.ICommandSender;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentText;
import cpw.mods.fml.common.event.FMLInterModComms;
import net.minecraftforge.common.config.Property; import net.minecraftforge.common.config.Property;
@ -45,6 +47,8 @@ public class Version implements Runnable {
private static Version instance = new Version(); private static Version instance = new Version();
private static boolean sentIMCOutdatedMessage = false;
public static String getVersion() { public static String getVersion() {
return VERSION; return VERSION;
} }
@ -54,7 +58,7 @@ public class Version implements Runnable {
} }
public static boolean needsUpdateNoticeAndMarkAsSeen() { public static boolean needsUpdateNoticeAndMarkAsSeen() {
if (!isOutdated()) { if (!isOutdated() || sentIMCOutdatedMessage) {
return false; return false;
} }
@ -124,6 +128,7 @@ public class Version implements Runnable {
BCLog.logger.warning("Using outdated version [" + VERSION + "] for Minecraft " + mcVersion BCLog.logger.warning("Using outdated version [" + VERSION + "] for Minecraft " + mcVersion
+ ". Consider updating to " + recommendedVersion + "."); + ". Consider updating to " + recommendedVersion + ".");
currentVersion = EnumUpdateState.OUTDATED; currentVersion = EnumUpdateState.OUTDATED;
sendIMCOutdatedMessage();
conn.disconnect(); conn.disconnect();
reader.close(); reader.close();
@ -145,7 +150,7 @@ public class Version implements Runnable {
public static String[] grabChangelog(String version) { public static String[] grabChangelog(String version) {
try { try {
String location = REMOTE_CHANGELOG_ROOT + "/" + version; String location = REMOTE_CHANGELOG_ROOT + version;
HttpURLConnection conn = null; HttpURLConnection conn = null;
while (location != null && !location.isEmpty()) { while (location != null && !location.isEmpty()) {
URL url = new URL(location); URL url = new URL(location);
@ -217,6 +222,25 @@ public class Version implements Runnable {
} }
public static void sendIMCOutdatedMessage() {
NBTTagCompound compound = new NBTTagCompound();
compound.setString("modDisplayName", "BuildCraft");
compound.setString("oldVersion", VERSION);
compound.setString("newVersion", getRecommendedVersion());
//TODO: Decide if we want to grab a direct link for easy updating (maybe from the Maven repo?)
compound.setString("updateUrl", "http://www.mod-buildcraft.com/download/");
compound.setBoolean("isDirectLink", false);
String changeLogString = "";
for (String changeLogLine : getChangelog()) {
changeLogString = changeLogString + changeLogLine + "\n";
}
compound.setString("changeLog", changeLogString);
sentIMCOutdatedMessage = FMLInterModComms.sendMessage("VersionChecker", "addUpdate", compound);
}
public static void displayChangelog(ICommandSender sender) { public static void displayChangelog(ICommandSender sender) {
int nb = 0; int nb = 0;
for (String updateLine : Version.getChangelog()) { for (String updateLine : Version.getChangelog()) {