Do a lot of work on the updater, make it compatible with dev builds
This commit is contained in:
@@ -101,19 +101,22 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
Updater u = new Updater();
|
if (getConfig().getBoolean("check-update")) {
|
||||||
if (getConfig().getBoolean("check-update")) {
|
if (getConfig().getBoolean("check-update")) {
|
||||||
try {
|
try {
|
||||||
if (u.getUpdate(getDescription().getVersion())) {
|
Updater u = new Updater(getDescription().getVersion());
|
||||||
UPDATE = true;
|
if (UPDATE = u.getUpdate()) {
|
||||||
|
LINK = u.getLink();
|
||||||
|
NEWVERSION = u.getNewVersion();
|
||||||
}
|
}
|
||||||
} catch(IOException e) {
|
} catch(Exception e) {
|
||||||
log.log(Level.WARNING, "PlayerVaults: Failed to check for updates.");
|
getLogger().log(Level.WARNING, "Failed to check for updates.");
|
||||||
log.log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow.");
|
getLogger().log(Level.WARNING, "Report this stack trace to gomeow.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}.runTaskAsynchronously(this);
|
}.runTaskAsynchronously(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,67 +3,48 @@ package com.drtshock.playervaults.util;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.SortedMap;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import org.json.JSONObject;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import com.drtshock.playervaults.PlayerVaults;
|
import org.w3c.dom.Document;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
/**
|
public class Updater {
|
||||||
* A class for updating the lang.yml and checking for updates at DBO.
|
|
||||||
*/
|
|
||||||
public class Updater extends PlayerVaults {
|
|
||||||
|
|
||||||
SortedMap<String, String> lang = new TreeMap<String, String>();
|
public Updater(String v) throws SAXException, IOException, ParserConfigurationException {
|
||||||
|
oldVersion = v.substring(0, 5);
|
||||||
/**
|
HttpURLConnection connection = (HttpURLConnection) new URL("http://dev.bukkit.org/projects/playervaults/files.rss").openConnection();
|
||||||
* Check whether or not there is a new update.
|
connection.setConnectTimeout(10000);
|
||||||
* @param currentVersion The current running version.
|
connection.setReadTimeout(10000);
|
||||||
* @return Whether or not an update is available.
|
connection.setUseCaches(false);
|
||||||
* @throws IOException Oh no!
|
Document feed = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(connection.getInputStream());
|
||||||
*/
|
newVersion = feed.getElementsByTagName("title").item(1).getTextContent().substring(1);
|
||||||
public boolean getUpdate(String currentVersion) throws IOException {
|
String link = feed.getElementsByTagName("link").item(1).getTextContent();
|
||||||
JSONObject json;
|
this.link = new BufferedReader(new InputStreamReader(new URL("http://is.gd/create.php?format=simple&url=" + link).openStream())).readLine();
|
||||||
try {
|
if(v.contains("SNAPSHOT") && !newVersion.equals(oldVersion)) {
|
||||||
json = getInfo();
|
update = false;
|
||||||
String version = json.getString("dbo_version");
|
return;
|
||||||
String link = json.getString("link");
|
|
||||||
PlayerVaults.NEWVERSION = version;
|
|
||||||
String goodLink = new BufferedReader(new InputStreamReader(new URL("http://is.gd/create.php?format=simple&url=" + link).openStream())).readLine();
|
|
||||||
PlayerVaults.LINK = goodLink;
|
|
||||||
if (!version.equalsIgnoreCase(currentVersion)) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
} catch(JSONException e) {
|
update = !newVersion.equals(oldVersion);
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private String oldVersion;
|
||||||
* Get the information about versions from DBO.
|
private String newVersion;
|
||||||
* @return The information in JSON.
|
private String link;
|
||||||
* @throws IOException Oh no!
|
private boolean update;
|
||||||
*/
|
|
||||||
public JSONObject getInfo() throws IOException {
|
public boolean getUpdate() {
|
||||||
URL url = new URL("http://api.bukget.org/3/plugins/bukkit/playervaults/latest");
|
return update;
|
||||||
BufferedReader in = null;
|
|
||||||
try {
|
|
||||||
in = new BufferedReader(new InputStreamReader(url.openStream()));
|
|
||||||
} catch(UnknownHostException e) {
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
JSONObject json;
|
|
||||||
try {
|
|
||||||
json = new JSONObject(in.readLine()).getJSONArray("versions").getJSONObject(0);
|
|
||||||
in.close();
|
|
||||||
return json;
|
|
||||||
} catch(JSONException e) {
|
|
||||||
throw new IOException("Oh no!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getNewVersion() {
|
||||||
|
return newVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLink() {
|
||||||
|
return link;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user