New way of update checking
This commit is contained in:
@@ -75,8 +75,8 @@ public class Listeners implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
vm.playerVaultFile(player.getName());
|
||||
if(player.isOp() && PlayerVaults.UPDATE) {
|
||||
player.sendMessage(ChatColor.GREEN + "Version " + PlayerVaults.NAME + " of PlayerVaults is up for download!");
|
||||
player.sendMessage(ChatColor.GREEN + "http://dev.bukkit.org/server-mods/playervaults/ to view the changelog and download!");
|
||||
player.sendMessage(ChatColor.GREEN + "Version " + PlayerVaults.NEWVERSION + " of PlayerVaults is up for download!");
|
||||
player.sendMessage(ChatColor.GREEN + PlayerVaults.LINK + " to view the changelog and download!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ public class PlayerVaults extends JavaPlugin {
|
||||
public static PlayerVaults PLUGIN;
|
||||
public Logger log;
|
||||
public static boolean UPDATE = false;
|
||||
public static String NAME = "";
|
||||
public static String NEWVERSION = "";
|
||||
public static String LINK = "";
|
||||
Commands commands;
|
||||
public static Economy ECON = null;
|
||||
public static boolean DROP_ON_DEATH = false;
|
||||
@@ -44,14 +45,13 @@ public class PlayerVaults extends JavaPlugin {
|
||||
loadConfig();
|
||||
loadSigns();
|
||||
startMetrics();
|
||||
Updater u = new Updater(getDescription().getVersion());
|
||||
Updater u = new Updater();
|
||||
if(getConfig().getBoolean("check-update")) {
|
||||
try {
|
||||
if(u.getUpdate()) {
|
||||
UPDATE = true;
|
||||
NAME = u.getNewVersion();
|
||||
}
|
||||
} catch(Exception e) {
|
||||
} catch(IOException e) {
|
||||
log.log(Level.WARNING, "PlayerVaults: Failed to check for updates.");
|
||||
log.log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow.");
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -10,16 +10,16 @@ import java.util.TreeMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
|
||||
public class Updater extends PlayerVaults {
|
||||
|
||||
SortedMap<String, String> lang = new TreeMap<String, String>();
|
||||
String version;
|
||||
|
||||
public Updater(String version) {
|
||||
this.version = version;
|
||||
public Updater() {
|
||||
YamlConfiguration langConf = super.getLang();
|
||||
for(Lang item:Lang.values()) {
|
||||
if(langConf.getString(item.getPath()) == null) {
|
||||
@@ -35,45 +35,37 @@ public class Updater extends PlayerVaults {
|
||||
}
|
||||
}
|
||||
|
||||
String newVersion = "";
|
||||
|
||||
public String getNewVersion() {
|
||||
return this.newVersion;
|
||||
}
|
||||
|
||||
public boolean getUpdate() throws Exception {
|
||||
String version = this.version;
|
||||
URL url = new URL("http://dev.bukkit.org/server-mods/playervaults/files.rss");
|
||||
InputStreamReader isr = null;
|
||||
public boolean getUpdate() throws IOException {
|
||||
JSONObject json;
|
||||
try {
|
||||
isr = new InputStreamReader(url.openStream());
|
||||
} catch(UnknownHostException e) {
|
||||
return false;
|
||||
}
|
||||
BufferedReader in = new BufferedReader(isr);
|
||||
String line;
|
||||
int lineNum = 0;
|
||||
while ((line = in.readLine()) != null) {
|
||||
if(line.length() != line.replace("<title>", "").length()) {
|
||||
line = line.replaceAll("<title>", "").replaceAll("</title>", "").replaceAll(" ", "").substring(1);
|
||||
if(lineNum == 1) {
|
||||
this.newVersion = line;
|
||||
Integer newVer = Integer.parseInt(line.replace(".", ""));
|
||||
Integer oldVer = Integer.parseInt(version.replace(".", ""));
|
||||
if(oldVer < newVer) {
|
||||
return true;
|
||||
}
|
||||
else if(oldVer > newVer) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
lineNum = lineNum + 1;
|
||||
json = getInfo();
|
||||
String version = json.getString("dbo_version");
|
||||
String link = json.getString("link");
|
||||
PlayerVaults.LINK = link;
|
||||
if(!version.equalsIgnoreCase(super.getDescription().getVersion())) {
|
||||
return true;
|
||||
}
|
||||
} catch(JSONException e) {
|
||||
throw new IOException();
|
||||
}
|
||||
in.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
public JSONObject getInfo() throws IOException {
|
||||
URL url = new URL("http://api.bukget.org/3/plugins/bukkit/playervaults/latest");
|
||||
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) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user