If server online less than 6 hours, ignore versions where the server is better than the site

This commit is contained in:
libraryaddict 2020-04-07 14:23:33 +12:00
parent a2262860d5
commit 8ff3c7c121
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4

View File

@ -12,6 +12,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
public class UpdateChecker {
@ -20,6 +21,7 @@ public class UpdateChecker {
private String latestVersion;
@Getter
private int latestSnapshot;
private final long started = System.currentTimeMillis();
public UpdateChecker(String resourceID) {
this.resourceID = resourceID;
@ -92,9 +94,37 @@ public class UpdateChecker {
return null;
}
private int reduceToNumber(String version) {
String[] split = version.split("\\.");
int num = 0;
for (int i = 0; i < split.length; i++) {
num += Integer.parseInt(split[i]) * ((split.length - i) * 10);
}
return num;
}
private boolean isNewerVersion(String currentVersion, String newVersion) {
currentVersion = currentVersion.replaceAll("(v)|(-SNAPSHOT)", "");
newVersion = newVersion.replaceAll("(v)|(-SNAPSHOT)", "");
// If the server has been online for less than 6 hours and both versions are 1.1.1 kind of versions
if (started + TimeUnit.HOURS.toMillis(6) > System.currentTimeMillis() &&
currentVersion.matches("[0-9]+(\\.[0-9]+)*") && newVersion.matches("[0-9]+(\\.[0-9]+)*")) {
int v1 = reduceToNumber(currentVersion);
int v2 = reduceToNumber(newVersion);
// If the current version is a higher version, and is only a higher version by 3 minor numbers
// Then we have a cache problem
if (v1 > v2 && v2 + 3 > v1) {
return false;
}
}
// Lets just ignore all this fancy logic, and say that if you're not on the current release, you're outdated!
return !currentVersion.replaceAll("(v)|(-SNAPSHOT)", "").equals(newVersion.replaceAll("(v)|(-SNAPSHOT)", ""));
return !currentVersion.equals(newVersion);
/*
// Remove 'v' and '-SNAPSHOT' from string, split by decimal points