Skip to content

Commit 7c9e380

Browse files
committed
Workaround update checker without json due to paper removal
Signed-off-by: Alexander Brandes <mc.cache@web.de>
1 parent febb8b2 commit 7c9e380

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ dependencies {
4949
implementation("org.bstats:bstats-bukkit")
5050
implementation("io.papermc:paperlib")
5151
implementation("com.intellectualsites.paster:Paster")
52+
53+
// Testing
54+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
55+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0")
56+
testImplementation("org.junit.platform:junit-platform-launcher:1.10.0")
57+
}
58+
59+
// Enable JUnit Platform for tests
60+
tasks.test {
61+
useJUnitPlatform()
5262
}
5363

5464
tasks.compileJava.configure {

src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperPlugin.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.thevoxelbox.voxelsniper.performer.PerformerRegistry;
1919
import com.thevoxelbox.voxelsniper.performer.property.PerformerProperties;
2020
import com.thevoxelbox.voxelsniper.sniper.SniperRegistry;
21+
import com.thevoxelbox.voxelsniper.update.UpdateCheckerParser;
2122
import com.thevoxelbox.voxelsniper.util.io.VoxelSniperResourceLoader;
2223
import io.papermc.lib.PaperLib;
2324

@@ -30,9 +31,6 @@
3031
import org.bukkit.plugin.PluginManager;
3132
import org.bukkit.plugin.java.JavaPlugin;
3233
import org.incendo.serverlib.ServerLib;
33-
import org.json.simple.JSONArray;
34-
import org.json.simple.JSONObject;
35-
import org.json.simple.JSONValue;
3634

3735
import java.io.BufferedReader;
3836
import java.io.File;
@@ -270,7 +268,8 @@ public CommandRegistry getCommandRegistry() {
270268
return this.commandRegistry;
271269
}
272270

273-
// Borrowed from Vault
271+
// Borrowed from Vault - Updated to workaround JSON removal from paper
272+
274273
private double updateCheck(double currentVersion) {
275274
try {
276275

@@ -280,18 +279,26 @@ private double updateCheck(double currentVersion) {
280279
conn.addRequestProperty("User-Agent", "FastAsyncVoxelSniper Update Checker");
281280
conn.setDoOutput(true);
282281
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
283-
final String response = reader.readLine();
284-
final JSONArray array = (JSONArray) JSONValue.parse(response);
282+
StringBuilder sb = new StringBuilder();
283+
String line;
284+
while ((line = reader.readLine()) != null) {
285+
sb.append(line);
286+
}
287+
final String response = sb.toString();
288+
289+
// Extract last name using UpdateCheckerParser to avoid JSON dependency
290+
String lastName = UpdateCheckerParser.extractLatestNameFromResponse(response);
285291

286-
if (array.isEmpty()) {
292+
if (lastName == null) {
287293
LOGGER.warn("No files found, or Feed URL is bad.");
288294
return currentVersion;
289295
}
290-
newVersionTitle =
291-
((String) ((JSONObject) array.getLast()).get("name")).replace("FastAsyncVoxelSniper", "").trim();
296+
newVersionTitle = lastName.replace("FastAsyncVoxelSniper", "").trim();
292297
return Double.parseDouble(newVersionTitle.replaceFirst("\\.", "").trim());
293298
} catch (IOException ignored) {
294299
LOGGER.error("Unable to connect to api.curseforge.com to check for updates. Improper firewall configuration?");
300+
} catch (NumberFormatException e) {
301+
LOGGER.warn("Unable to parse version string: {}", newVersionTitle, e);
295302
}
296303
return Double.NaN;
297304
}

0 commit comments

Comments
 (0)