mirror of
https://github.com/GTNewHorizons/Tainted-Magic.git
synced 2026-11-18 11:19:24 +00:00
61 lines
1.6 KiB
Java
61 lines
1.6 KiB
Java
package taintedmagic.common.handler;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.net.URL;
|
|
import java.util.Scanner;
|
|
|
|
import taintedmagic.common.TaintedMagic;
|
|
import taintedmagic.common.lib.LibInfo;
|
|
import net.minecraft.util.EnumChatFormatting;
|
|
|
|
public class UpdateHandler
|
|
{
|
|
private static String currentVersion = LibInfo.VERSION;
|
|
private static String newestVersion;
|
|
public static String updateStatus = null;
|
|
public static boolean show = false;
|
|
|
|
public static void init ()
|
|
{
|
|
getNewestVersion();
|
|
|
|
if (newestVersion != null)
|
|
{
|
|
if (newestVersion.equalsIgnoreCase(currentVersion))
|
|
{
|
|
show = false;
|
|
}
|
|
else if (!newestVersion.equalsIgnoreCase(currentVersion))
|
|
{
|
|
show = true;
|
|
updateStatus = (EnumChatFormatting.RED + "Tainted Magic is out of date! The latest version is " + EnumChatFormatting.GREEN + newestVersion);
|
|
TaintedMagic.log.info("Mod out of date! You're still running: " + currentVersion + ", Latest Version: " + newestVersion);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
show = true;
|
|
updateStatus = (EnumChatFormatting.RED + "Tainted Magic failed to connect to update server!");
|
|
TaintedMagic.log.info("Failed to connect to update server...");
|
|
}
|
|
}
|
|
|
|
private static void getNewestVersion ()
|
|
{
|
|
try
|
|
{
|
|
URL url = new URL("https://raw.githubusercontent.com/yorkeJohn/Tainted-Magic/master/version.txt");
|
|
Scanner s = new Scanner(url.openStream());
|
|
newestVersion = s.next();
|
|
s.close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.printStackTrace();
|
|
TaintedMagic.log.info("Could not connect to GitHub repository!");
|
|
}
|
|
}
|
|
}
|