Skip to content

Commit f19ac59

Browse files
committed
Remove dependencies
Update checker has been rewritten to use Java-native HTTP classes to fetch details and remove the redundant JSON dependency in favour of GSON which is already included
1 parent 33d6df3 commit f19ac59

2 files changed

Lines changed: 32 additions & 35 deletions

File tree

server/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ repositories {
1414

1515
dependencies {
1616
library("org.projectlombok:lombok:1.18.46")
17-
library("org.json:json:20251224")
1817
library("commons-io:commons-io:2.22.0")
1918
library("redis.clients:jedis:7.5.0")
2019
library("org.mariadb.jdbc:mariadb-java-client:3.5.8")
2120
library("com.zaxxer:HikariCP:7.0.2")
22-
library("org.apache.maven.resolver:maven-resolver-transport-http:1.9.27")
2321
library("org.jetbrains:annotations:26.1.0")
2422
compileOnly("io.papermc.paper:paper-api:26.1.2.build.+")
2523
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") {

server/src/main/java/dev/plex/util/UpdateChecker.java

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@
1919
import net.kyori.adventure.text.Component;
2020
import net.kyori.adventure.text.format.NamedTextColor;
2121
import org.apache.commons.io.FileUtils;
22-
import org.apache.http.HttpResponse;
23-
import org.apache.http.client.methods.HttpGet;
24-
import org.apache.http.impl.client.CloseableHttpClient;
25-
import org.apache.http.impl.client.HttpClients;
26-
import org.apache.http.util.EntityUtils;
2722
import org.bukkit.Bukkit;
2823
import org.bukkit.command.CommandSender;
2924
import org.json.JSONException;
30-
import org.json.JSONObject;
3125

3226
public class UpdateChecker implements PlexBase
3327
{
@@ -154,49 +148,54 @@ public boolean getUpdateStatusMessage(CommandSender sender, boolean cached, int
154148

155149
public void updateJar(CommandSender sender, String name, boolean module)
156150
{
157-
CloseableHttpClient client = HttpClients.createDefault();
158151
AtomicReference<String> url = new AtomicReference<>(DOWNLOAD_PAGE + name);
159152
if (!module)
160153
{
161154
url.set(url.get() + "/job/" + BRANCH);
162155
}
163156
PlexLog.debug(url.toString());
164-
HttpGet get = new HttpGet(url + "/lastSuccessfulBuild/api/json");
165157
try
166158
{
167-
HttpResponse response = client.execute(get);
168-
int statusCode = response.getStatusLine().getStatusCode();
159+
HttpURLConnection connection = (HttpURLConnection) URI.create(url + "/lastSuccessfulBuild/api/json").toURL().openConnection();
160+
int statusCode = connection.getResponseCode();
169161

170162
if (statusCode == HttpURLConnection.HTTP_OK)
171163
{
172-
JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
173-
JSONObject artifact = object.getJSONArray("artifacts").getJSONObject(0);
174-
String jarFile = artifact.getString("fileName");
175-
sender.sendMessage(PlexUtils.mmDeserialize("<green>Downloading latest JAR file: " + jarFile));
176-
File copyTo;
177-
if (!module)
164+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)))
178165
{
179-
copyTo = new File(Bukkit.getUpdateFolderFile(), jarFile);
180-
}
181-
else
182-
{
183-
copyTo = new File(plugin.getModulesFolder().getPath(), jarFile);
184-
}
185-
CompletableFuture.runAsync(() ->
186-
{
187-
try
166+
JsonObject object = new Gson().fromJson(reader, JsonObject.class);
167+
JsonObject artifact = object.getAsJsonArray("artifacts").asList().getFirst().getAsJsonObject();
168+
String jarFile = artifact.get("fileName").getAsString();
169+
sender.sendMessage(PlexUtils.mmDeserialize("<green>Downloading latest JAR file: " + jarFile));
170+
File copyTo;
171+
if (!module)
188172
{
189-
FileUtils.copyURLToFile(
190-
URI.create(url + "/lastSuccessfulBuild/artifact/build/libs/" + jarFile).toURL(),
191-
copyTo
192-
);
193-
sender.sendMessage(PlexUtils.mmDeserialize("<green>New JAR file downloaded successfully."));
173+
copyTo = new File(Bukkit.getUpdateFolderFile(), jarFile);
194174
}
195-
catch (IOException e)
175+
else
196176
{
197-
e.printStackTrace();
177+
copyTo = new File(plugin.getModulesFolder().getPath(), jarFile);
198178
}
199-
});
179+
CompletableFuture.runAsync(() ->
180+
{
181+
try
182+
{
183+
FileUtils.copyURLToFile(
184+
URI.create(url + "/lastSuccessfulBuild/artifact/build/libs/" + jarFile).toURL(),
185+
copyTo
186+
);
187+
sender.sendMessage(PlexUtils.mmDeserialize("<green>New JAR file downloaded successfully."));
188+
}
189+
catch (IOException e)
190+
{
191+
e.printStackTrace();
192+
}
193+
});
194+
}
195+
catch (JsonSyntaxException | NumberFormatException e)
196+
{
197+
e.printStackTrace();
198+
}
200199
}
201200
else if (statusCode == HttpURLConnection.HTTP_NOT_FOUND)
202201
{

0 commit comments

Comments
 (0)