Skip to content

Commit

Permalink
improve(updater): optimize version checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Xzavier0722 committed Apr 20, 2022
1 parent 315f0e1 commit 020af67
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/main/java/ren/natsuyuk1/slimefunextra/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,30 @@ public static void checkUpdate() {
if (Slimefun.instance() != null) {
String latestVersionCode = node.getObject().getString("tag_name");

String currentYear = latestVersionCode.split("\\.")[0];
String currentMonth = latestVersionCode.split("\\.")[1];

// Get last string
String[] versionCodeSplit = currentVersion.split("-");
String actualVersionCode = versionCodeSplit[versionCodeSplit.length - 1];
String version = null;
for (String str : versionCodeSplit) {
if (str.startsWith("20")) {
String[] code = str.split("\\.");
if (code.length < 2) {
Slimefun.logger().warning("无法识别当前版本: " + currentVersion);
return;
}
version = code[0] + "." + code[1];
}
}

String year = actualVersionCode.split("\\.")[0];
String month = actualVersionCode.split("\\.")[1];
if (version == null) {
Slimefun.logger().warning("无法识别当前版本: " + currentVersion);
return;
}

if (Integer.parseInt(currentYear) > Integer.parseInt(year)
|| (Integer.parseInt(year) == Integer.parseInt(currentYear)
&& Integer.parseInt(currentMonth) > Integer.parseInt(month))) {
if (latestVersionCode.compareTo(version) > 0) {
Slimefun.logger().info("新版本 " + latestVersionCode + " 已发布,请前往 https://gitee.com/StarWishsama/Slimefun4/releases 更新.");
} else {
Slimefun.logger().info("你正在使用最新版本 " + currentVersion + ".");
}

}
}
} catch (Exception e) {
Expand Down

0 comments on commit 020af67

Please sign in to comment.