Skip to content

Commit

Permalink
Added separate version check for CoreProtect Edge
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed Sep 30, 2024
1 parent de978fc commit 0f0c898
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/java/net/coreprotect/command/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -1298,16 +1298,23 @@ else if (corecommand.equals("migrate-db")) {

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
public void run() {
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));
Chat.sendMessage(user, Color.DARK_AQUA + Phrase.build(Phrase.LINK_DOWNLOAD, Color.WHITE, "www.coreprotect.net/download/"));
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();
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/net/coreprotect/thread/NetworkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -53,6 +54,10 @@ public static String latestVersion() {
return latestVersion;
}

public static String latestEdgeVersion() {
return latestEdgeVersion;
}

public static String donationKey() {
return donationKey;
}
Expand Down Expand Up @@ -282,10 +287,13 @@ else if (Files.isReadable(licensePath)) {

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");
Expand All @@ -296,6 +304,18 @@ else if (Files.isReadable(licensePath)) {
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
Expand Down Expand Up @@ -333,6 +353,31 @@ else if (Files.isReadable(licensePath)) {
}
}

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

0 comments on commit 0f0c898

Please sign in to comment.