Change it so when there is no connection we don't bug them. Also change it to use http instead of https, as https requires certain certificate info by linux.

This commit is contained in:
Myles 2016-03-06 10:46:38 +00:00
parent c4185e3056
commit 4124c3454e

View File

@ -19,7 +19,7 @@ import java.util.UUID;
public class UpdateUtil { public class UpdateUtil {
private final static String URL = "https://api.spiget.org/v1/resources/"; private final static String URL = "http://api.spiget.org/v1/resources/";
private final static int PLUGIN = 19254; private final static int PLUGIN = 19254;
public final static String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN; public final static String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN;
@ -69,9 +69,17 @@ public class UpdateUtil {
if (ViaVersion.getInstance().getVersion().equals("${project.version}")) { if (ViaVersion.getInstance().getVersion().equals("${project.version}")) {
return "You are using a debug/custom version, consider updating."; return "You are using a debug/custom version, consider updating.";
} }
String newestString = getNewestVersion();
if (newestString == null) {
if (console) {
return "Could not check for updates, check your connection.";
} else {
return null;
}
}
Version current = new Version(ViaVersion.getInstance().getVersion()); Version current = new Version(ViaVersion.getInstance().getVersion());
Version newest = new Version(getNewestVersion()); Version newest = new Version(newestString);
if (current.compareTo(newest) < 0) if (current.compareTo(newest) < 0)
return "There is a newer version available: " + newest.toString(); return "There is a newer version available: " + newest.toString();
else if (console) { else if (console) {
@ -81,7 +89,6 @@ public class UpdateUtil {
} }
private static String getNewestVersion() { private static String getNewestVersion() {
String result = "";
try { try {
URL url = new URL(URL + PLUGIN + "?" + System.currentTimeMillis()); URL url = new URL(URL + PLUGIN + "?" + System.currentTimeMillis());
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@ -97,12 +104,11 @@ public class UpdateUtil {
br.close(); br.close();
JsonParser parser = new JsonParser(); JsonParser parser = new JsonParser();
JsonObject statistics = (JsonObject) parser.parse(content); JsonObject statistics = (JsonObject) parser.parse(content);
result = statistics.get("version").getAsString(); return statistics.get("version").getAsString();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); return null;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); return null;
} }
return result;
} }
} }