Skip to content

Commit ffdbcfa

Browse files
committed
fix version sorting
1 parent 58123dd commit ffdbcfa

File tree

3 files changed

+54
-31
lines changed

3 files changed

+54
-31
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
- [x] Client brand based blacklisting
1010
- [x] Username based blacklisting
1111
- [x] IP based blacklisting
12-
- [x] Modular multi-platform support
13-
- [x] JSON5 based configuration
1412
- [x] Kick message customization
1513
- [x] Blacklist MOTD customization
1614
- [x] MiniMessage and legacy formattings supported
@@ -20,6 +18,11 @@
2018
- [ ] Subscribe to an auto-updating blacklist
2119
- [ ] Reverse blacklist (whitelist)
2220

21+
<h2>Changes from v1</h2>
22+
23+
- [x] Modular multi-platform support
24+
- [x] JSON5 based configuration
25+
2326
<h2>Download</h2>
2427
The latest release can be found at <b><a href="https://github.com/WebMCDevelopment/originblacklist/releases/latest/">https://github.com/WebMCDevelopment/originblacklist/releases/latest/</a></b>
2528

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ val PLUGIN_NAME = "OriginBlacklist"
1313
val PLUGIN_IDEN = "originblacklist"
1414
val PLUGIN_DOMN = "xyz.webmc"
1515
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
16-
val PLUGIN_VERS = "2.0.3"
16+
val PLUGIN_VERS = "2.0.4"
1717
val PLUGIN_SITE = "https://github.com/WebMCDevelopment/$PLUGIN_IDEN"
1818
val PLUGIN_DEPA = listOf("EaglercraftXServer")
1919
val PLUGIN_DEPB = listOf("EaglercraftXServer")

src/main/java/xyz/webmc/originblacklist/base/util/UpdateChecker.java

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,62 @@ public static final String checkForUpdate(final String repo, final Semver curren
3131
String ret = null;
3232
Json5Element element = json5.parse(reader);
3333
reader.close();
34+
35+
Json5Object rel = null;
36+
Json5Object snap = null;
37+
3438
if (element instanceof Json5Array) {
3539
final Json5Array arr = element.getAsJson5Array();
36-
if (arr.size() > 0) {
37-
for (int i = 0; i < Math.min(2, arr.size()); i++) {
38-
element = arr.get(i);
39-
if (element instanceof Json5Object) {
40-
final Json5Object obj = element.getAsJson5Object();
41-
if (allowSnapshots || !obj.get("prerelease").getAsBoolean()) {
42-
final String tag = obj.get("tag_name").getAsString();
43-
final Semver ver = new Semver(tag.startsWith("v") ? tag.substring(1) : tag);
44-
String comm;
45-
try {
46-
comm = ver.getBuild().get(0).trim();
47-
} catch (Throwable t) {
48-
comm = "";
49-
}
50-
if (ver.isGreaterThan(currentVersion) || (allowSnapshots && currentVersion.diff(ver) == VersionDiff.BUILD && OriginBlacklist.isNonNull(comm) && !BuildInfo.get("git_cm_hash").startsWith(comm))) {
51-
element = obj.get("assets");
52-
if (element instanceof Json5Array) {
53-
final Json5Array aArr = element.getAsJson5Array();
54-
if (aArr.size() > 0) {
55-
element = aArr.get(0);
56-
if (element instanceof Json5Object) {
57-
final Json5Object vObj = element.getAsJson5Object();
58-
ret = vObj.get("browser_download_url").getAsString();
59-
break;
60-
}
61-
}
62-
}
63-
}
40+
for (int i = 0; i < arr.size(); i++) {
41+
element = arr.get(i);
42+
if (element instanceof Json5Object) {
43+
final Json5Object obj = element.getAsJson5Object();
44+
if (!obj.has("published_at")) {
45+
continue;
46+
}
47+
final boolean pre = obj.get("prerelease").getAsBoolean();
48+
if (!pre) {
49+
if (rel == null || obj.get("published_at").getAsString().compareTo(rel.get("published_at").getAsString()) > 0) {
50+
rel = obj;
51+
}
52+
} else {
53+
if (snap == null || obj.get("published_at").getAsString().compareTo(snap.get("published_at").getAsString()) > 0) {
54+
snap = obj;
6455
}
6556
}
57+
}
58+
continue;
59+
}
60+
61+
for (int i = 0; i < 2; i++) {
62+
final Json5Object obj = i == 0 ? rel : snap;
63+
if (obj == null || (i == 1 && !allowSnapshots)) {
6664
continue;
6765
}
66+
final String tag = obj.get("tag_name").getAsString();
67+
final Semver ver = new Semver(tag.startsWith("v") ? tag.substring(1) : tag);
68+
String comm;
69+
try {
70+
comm = ver.getBuild().get(0).trim();
71+
} catch (Throwable t) {
72+
comm = "";
73+
}
74+
if (ver.isGreaterThan(currentVersion) || (allowSnapshots && currentVersion.diff(ver) == VersionDiff.BUILD && OriginBlacklist.isNonNull(comm) && !BuildInfo.get("git_cm_hash").startsWith(comm))) {
75+
element = obj.get("assets");
76+
if (element instanceof Json5Array) {
77+
final Json5Array aArr = element.getAsJson5Array();
78+
if (aArr.size() > 0) {
79+
element = aArr.get(0);
80+
if (element instanceof Json5Object) {
81+
ret = element.getAsJson5Object().get("browser_download_url").getAsString();
82+
break;
83+
}
84+
}
85+
}
86+
}
6887
}
6988
}
89+
7090
conn.disconnect();
7191
return ret;
7292
} catch (final Throwable t) {

0 commit comments

Comments
 (0)