Make Updater work with our versioning setup.

This commit is contained in:
GJ 2013-09-13 11:46:55 -04:00
parent 4eba33a1c6
commit 3bc029a0de

View File

@ -437,30 +437,49 @@ public class Updater
if(type != UpdateType.NO_VERSION_CHECK) if(type != UpdateType.NO_VERSION_CHECK)
{ {
String version = plugin.getDescription().getVersion(); String version = plugin.getDescription().getVersion();
title = title.substring(6);
String[] oldTokens = version.replaceAll("(?i)(-)(.+?)(-)", "-").split("[.]|-b"); String[] oldTokens = version.split("-");
String[] newTokens = title.replaceAll("(?i)(-)(.+?)(-)", "-").split("[.]|-b"); String[] newTokens = title.split("-");
for (int i = 0; i < 4; i++) { int oldVersion = Integer.parseInt(oldTokens[0].replaceAll(".", ""));
Integer newVer = Integer.parseInt(newTokens[i]); int newVersion = Integer.parseInt(newTokens[0].replaceAll(".", ""));
Integer oldVer;
try { // Check versions
oldVer = Integer.parseInt(oldTokens[i]); if (oldVersion < newVersion) {
} return true;
catch (NumberFormatException e) {
plugin.getLogger().warning("Could not get information about this mcMMO version; perhaps you are running a custom one?");
result = UpdateResult.FAIL_NOVERSION;
return false;
}
if (oldVer < newVer) {
return true;
}
} }
result = Updater.UpdateResult.NO_UPDATE; // Check release vs. beta & dev
return false; if (newTokens.length == 0 && oldTokens.length == 2 && oldVersion == newVersion) {
return true;
}
// Check beta vs. dev
if (version.contains("dev") && title.contains("beta")) {
if (Integer.parseInt(oldTokens[1].substring(3)) < Integer.parseInt(newTokens[1].substring(4))) {
return true;
}
result = UpdateResult.NO_UPDATE;
return false;
}
// Check beta vs. beta
if (version.contains("beta") && title.contains("beta")) {
if (Integer.parseInt(oldTokens[1].substring(4)) < Integer.parseInt(newTokens[1].substring(4))) {
return true;
}
result = UpdateResult.NO_UPDATE;
return false;
}
if (oldTokens.length == 2 && !version.contains("beta") && !version.contains("dev")) {
plugin.getLogger().warning("Could not get information about this mcMMO version; perhaps you are running a custom one?");
result = UpdateResult.FAIL_NOVERSION;
return false;
}
} }
return true; return true;