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

@ -1298,7 +1298,8 @@ public class CommandHandler implements CommandExecutor {
if (user.isOp() && versionAlert.get(user.getName()) == null) {
String latestVersion = NetworkHandler.latestVersion();
if (latestVersion != null) {
String latestEdgeVersion = NetworkHandler.latestEdgeVersion();
if (latestVersion != null || latestEdgeVersion != null) {
versionAlert.put(user.getName(), true);
class updateAlert implements Runnable {
@Override
@ -1306,9 +1307,15 @@ public class CommandHandler implements CommandExecutor {
try {
Thread.sleep(5000);
Chat.sendMessage(user, Color.WHITE + "----- " + Color.DARK_AQUA + Phrase.build(Phrase.UPDATE_HEADER, "CoreProtect" + (Util.isCommunityEdition() ? " " + ConfigHandler.COMMUNITY_EDITION : "")) + Color.WHITE + " -----");
Chat.sendMessage(user, Color.DARK_AQUA + Phrase.build(Phrase.UPDATE_NOTICE, Color.WHITE, "CoreProtect v" + latestVersion));
if (latestVersion != null) {
Chat.sendMessage(user, Color.DARK_AQUA + Phrase.build(Phrase.UPDATE_NOTICE, Color.WHITE, "CoreProtect CE v" + latestVersion));
Chat.sendMessage(user, Color.DARK_AQUA + Phrase.build(Phrase.LINK_DOWNLOAD, Color.WHITE, "www.coreprotect.net/download/"));
}
else {
Chat.sendMessage(user, Color.DARK_AQUA + Phrase.build(Phrase.UPDATE_NOTICE, Color.WHITE, "CoreProtect v" + latestEdgeVersion));
Chat.sendMessage(user, Color.DARK_AQUA + Phrase.build(Phrase.LINK_DOWNLOAD, Color.WHITE, "www.coreprotect.net/latest/"));
}
}
catch (Exception e) {
e.printStackTrace();
}

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();