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