Fix regexp, period needs to be escaped. Use better exception handling.

This commit is contained in:
Nick Minkler 2013-12-24 13:23:35 -08:00
parent a64a341a35
commit c6903d5044

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.Collection; import java.util.Collection;
@ -526,9 +527,9 @@ public class Vault extends JavaPlugin {
} }
} }
public double updateCheck(double currentVersion) throws Exception { public double updateCheck(double currentVersion) {
final URL url = new URL("https://api.curseforge.com/servermods/files?projectids=33184");
try { try {
URL url = new URL("https://api.curseforge.com/servermods/files?projectids=33184");
URLConnection conn = url.openConnection(); URLConnection conn = url.openConnection();
conn.setReadTimeout(5000); conn.setReadTimeout(5000);
conn.addRequestProperty("User-Agent", "Vault Update Checker"); conn.addRequestProperty("User-Agent", "Vault Update Checker");
@ -542,12 +543,12 @@ public class Vault extends JavaPlugin {
return currentVersion; return currentVersion;
} }
// Pull the last version from the JSON // Pull the last version from the JSON
String version = ((String) ((JSONObject) array.get(array.size() - 1)).get("name")).replace("Vault", "").replaceFirst(".", "").trim(); String version = ((String) ((JSONObject) array.get(array.size() - 1)).get("name")).replace("Vault", "").replaceFirst("\\.", "").trim();
return Double.valueOf(version); return Double.valueOf(version);
} } catch (MalformedURLException e) {
catch (Exception localException) { e.printStackTrace();
// Dump the stack trace } catch (IOException e) {
localException.printStackTrace(); e.printStackTrace();
} }
return currentVersion; return currentVersion;
} }