Skip to content

Commit

Permalink
UpdateHandler changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkeJohn committed Jan 8, 2022
1 parent 13bfced commit fde65b1
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main/java/taintedmagic/common/handler/UpdateHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,34 @@
import taintedmagic.common.TaintedMagic;

public class UpdateHandler {
private static String currentVersion = TaintedMagic.VERSION;
private static String newestVersion;
public static String updateStatus = null;
private static String latestVersion = null;
public static String message = null;

public static void checkForUpdate () {
getNewestVersion();

if (newestVersion != null) {
if (newestVersion.equalsIgnoreCase(currentVersion)) {
if (latestVersion != null) {
if (TaintedMagic.VERSION.equals("@VERSION@")) {
message = String.format("%sTainted Magic is running in DEV!", EnumChatFormatting.GREEN);
TaintedMagic.logger.info("Tainted Magic is running in DEV!");
}
else if (!newestVersion.equalsIgnoreCase(currentVersion)) {
updateStatus = EnumChatFormatting.RED + "Tainted Magic is out of date! The latest version is "
+ EnumChatFormatting.GREEN + newestVersion;
else if (!latestVersion.equalsIgnoreCase(TaintedMagic.VERSION)) {
message = String.format("%sTainted Magic is out of date! The latest version is %s%s", EnumChatFormatting.RED,
EnumChatFormatting.GREEN, latestVersion);
TaintedMagic.logger.warn("Mod out of date! You're still running {} ... the latest version is {}",
currentVersion, newestVersion);
TaintedMagic.VERSION, latestVersion);
}
}
else {
updateStatus = EnumChatFormatting.RED + "Tainted Magic failed to connect to the update server!";
message = String.format("%sTainted Magic failed to connect to the update server!", EnumChatFormatting.RED);
}
}

private static void getNewestVersion () {
try {
final URL url = new URL("https://raw.githubusercontent.com/yorkeJohn/Tainted-Magic/master/version.txt");
final Scanner scan = new Scanner(url.openStream());
newestVersion = scan.next();
latestVersion = scan.next();
scan.close();
}
catch (final MalformedURLException e) {
Expand Down

0 comments on commit fde65b1

Please sign in to comment.