Added separate version check for CoreProtect Edge

This commit is contained in:
Intelli 2024-09-29 18:40:05 -06:00
parent de978fce2c
commit 0f0c89845c
2 changed files with 55 additions and 3 deletions

View file

@ -42,6 +42,7 @@ public class NetworkHandler extends Language implements Runnable {
private boolean background = false;
private boolean translate = true;
private static String latestVersion = null;
private static String latestEdgeVersion = null;
private static String donationKey = null;
public NetworkHandler(boolean startup, boolean background) {
@ -53,6 +54,10 @@ public class NetworkHandler extends Language implements Runnable {
return latestVersion;
}
public static String latestEdgeVersion() {
return latestEdgeVersion;
}
public static String donationKey() {
return donationKey;
}
@ -282,10 +287,13 @@ public class NetworkHandler extends Language implements Runnable {
while (ConfigHandler.serverRunning) {
int status = 0;
int statusEdge = 0;
HttpURLConnection connection = null;
HttpURLConnection connectionEdge = null;
String version = Util.getPluginVersion();
try {
// CoreProtect Community Edition
URL url = new URL("http://update.coreprotect.net/version/");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
@ -296,6 +304,18 @@ public class NetworkHandler extends Language implements Runnable {
connection.setConnectTimeout(5000);
connection.connect();
status = connection.getResponseCode();
// CoreProtect Edge
url = new URL("http://update.coreprotect.net/version-edge/");
connectionEdge = (HttpURLConnection) url.openConnection();
connectionEdge.setRequestMethod("GET");
connectionEdge.setRequestProperty("Accept-Charset", "UTF-8");
connectionEdge.setRequestProperty("User-Agent", "CoreProtect/v" + version + " (by Intelli)");
connectionEdge.setDoOutput(true);
connectionEdge.setInstanceFollowRedirects(true);
connectionEdge.setConnectTimeout(5000);
connectionEdge.connect();
statusEdge = connectionEdge.getResponseCode();
}
catch (Exception e) {
// Unable to connect to update.coreprotect.net
@ -333,6 +353,31 @@ public class NetworkHandler extends Language implements Runnable {
}
}
if (statusEdge == 200) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(connectionEdge.getInputStream()));
String response = reader.readLine();
if (response.length() > 0 && response.length() < 10) {
String remoteVersion = response.replaceAll("[^0-9.]", "");
if (remoteVersion.contains(".")) {
boolean newVersion = Util.newVersion(version, remoteVersion);
if (newVersion) {
latestEdgeVersion = remoteVersion;
}
else {
latestEdgeVersion = null;
}
}
}
reader.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
try {
/* Stat gathering */
int port = Bukkit.getServer().getPort();