diff --git a/server/build.gradle.kts b/server/build.gradle.kts index ebe9d58..66ea0b5 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -14,12 +14,10 @@ repositories { dependencies { library("org.projectlombok:lombok:1.18.46") - library("org.json:json:20251224") library("commons-io:commons-io:2.22.0") library("redis.clients:jedis:7.5.0") library("org.mariadb.jdbc:mariadb-java-client:3.5.8") library("com.zaxxer:HikariCP:7.0.2") - library("org.apache.maven.resolver:maven-resolver-transport-http:1.9.27") library("org.jetbrains:annotations:26.1.0") compileOnly("io.papermc.paper:paper-api:26.1.2.build.+") compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") { diff --git a/server/src/main/java/dev/plex/util/UpdateChecker.java b/server/src/main/java/dev/plex/util/UpdateChecker.java index 03bd5e8..4f871ef 100644 --- a/server/src/main/java/dev/plex/util/UpdateChecker.java +++ b/server/src/main/java/dev/plex/util/UpdateChecker.java @@ -19,15 +19,9 @@ import lombok.NonNull; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.apache.commons.io.FileUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.json.JSONException; -import org.json.JSONObject; public class UpdateChecker implements PlexBase { @@ -154,49 +148,54 @@ public class UpdateChecker implements PlexBase public void updateJar(CommandSender sender, String name, boolean module) { - CloseableHttpClient client = HttpClients.createDefault(); AtomicReference url = new AtomicReference<>(DOWNLOAD_PAGE + name); if (!module) { url.set(url.get() + "/job/" + BRANCH); } PlexLog.debug(url.toString()); - HttpGet get = new HttpGet(url + "/lastSuccessfulBuild/api/json"); try { - HttpResponse response = client.execute(get); - int statusCode = response.getStatusLine().getStatusCode(); + HttpURLConnection connection = (HttpURLConnection) URI.create(url + "/lastSuccessfulBuild/api/json").toURL().openConnection(); + int statusCode = connection.getResponseCode(); if (statusCode == HttpURLConnection.HTTP_OK) { - JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8)); - JSONObject artifact = object.getJSONArray("artifacts").getJSONObject(0); - String jarFile = artifact.getString("fileName"); - sender.sendMessage(PlexUtils.mmDeserialize("Downloading latest JAR file: " + jarFile)); - File copyTo; - if (!module) + try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) { - copyTo = new File(Bukkit.getUpdateFolderFile(), jarFile); - } - else - { - copyTo = new File(plugin.getModulesFolder().getPath(), jarFile); - } - CompletableFuture.runAsync(() -> - { - try + JsonObject object = new Gson().fromJson(reader, JsonObject.class); + JsonObject artifact = object.getAsJsonArray("artifacts").asList().getFirst().getAsJsonObject(); + String jarFile = artifact.get("fileName").getAsString(); + sender.sendMessage(PlexUtils.mmDeserialize("Downloading latest JAR file: " + jarFile)); + File copyTo; + if (!module) { - FileUtils.copyURLToFile( - URI.create(url + "/lastSuccessfulBuild/artifact/build/libs/" + jarFile).toURL(), - copyTo - ); - sender.sendMessage(PlexUtils.mmDeserialize("New JAR file downloaded successfully.")); + copyTo = new File(Bukkit.getUpdateFolderFile(), jarFile); } - catch (IOException e) + else { - e.printStackTrace(); + copyTo = new File(plugin.getModulesFolder().getPath(), jarFile); } - }); + CompletableFuture.runAsync(() -> + { + try + { + FileUtils.copyURLToFile( + URI.create(url + "/lastSuccessfulBuild/artifact/build/libs/" + jarFile).toURL(), + copyTo + ); + sender.sendMessage(PlexUtils.mmDeserialize("New JAR file downloaded successfully.")); + } + catch (IOException e) + { + e.printStackTrace(); + } + }); + } + catch (JsonSyntaxException | NumberFormatException e) + { + e.printStackTrace(); + } } else if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) {