mirror of
https://github.com/plexusorg/Plex.git
synced 2026-06-04 05:26:55 +00:00
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
This commit is contained in:
@@ -14,12 +14,10 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
library("org.projectlombok:lombok:1.18.46")
|
library("org.projectlombok:lombok:1.18.46")
|
||||||
library("org.json:json:20251224")
|
|
||||||
library("commons-io:commons-io:2.22.0")
|
library("commons-io:commons-io:2.22.0")
|
||||||
library("redis.clients:jedis:7.5.0")
|
library("redis.clients:jedis:7.5.0")
|
||||||
library("org.mariadb.jdbc:mariadb-java-client:3.5.8")
|
library("org.mariadb.jdbc:mariadb-java-client:3.5.8")
|
||||||
library("com.zaxxer:HikariCP:7.0.2")
|
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")
|
library("org.jetbrains:annotations:26.1.0")
|
||||||
compileOnly("io.papermc.paper:paper-api:26.1.2.build.+")
|
compileOnly("io.papermc.paper:paper-api:26.1.2.build.+")
|
||||||
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") {
|
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") {
|
||||||
|
|||||||
@@ -19,15 +19,9 @@ import lombok.NonNull;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.apache.commons.io.FileUtils;
|
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.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
public class UpdateChecker implements PlexBase
|
public class UpdateChecker implements PlexBase
|
||||||
{
|
{
|
||||||
@@ -154,49 +148,54 @@ public class UpdateChecker implements PlexBase
|
|||||||
|
|
||||||
public void updateJar(CommandSender sender, String name, boolean module)
|
public void updateJar(CommandSender sender, String name, boolean module)
|
||||||
{
|
{
|
||||||
CloseableHttpClient client = HttpClients.createDefault();
|
|
||||||
AtomicReference<String> url = new AtomicReference<>(DOWNLOAD_PAGE + name);
|
AtomicReference<String> url = new AtomicReference<>(DOWNLOAD_PAGE + name);
|
||||||
if (!module)
|
if (!module)
|
||||||
{
|
{
|
||||||
url.set(url.get() + "/job/" + BRANCH);
|
url.set(url.get() + "/job/" + BRANCH);
|
||||||
}
|
}
|
||||||
PlexLog.debug(url.toString());
|
PlexLog.debug(url.toString());
|
||||||
HttpGet get = new HttpGet(url + "/lastSuccessfulBuild/api/json");
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpResponse response = client.execute(get);
|
HttpURLConnection connection = (HttpURLConnection) URI.create(url + "/lastSuccessfulBuild/api/json").toURL().openConnection();
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = connection.getResponseCode();
|
||||||
|
|
||||||
if (statusCode == HttpURLConnection.HTTP_OK)
|
if (statusCode == HttpURLConnection.HTTP_OK)
|
||||||
{
|
{
|
||||||
JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)))
|
||||||
JSONObject artifact = object.getJSONArray("artifacts").getJSONObject(0);
|
|
||||||
String jarFile = artifact.getString("fileName");
|
|
||||||
sender.sendMessage(PlexUtils.mmDeserialize("<green>Downloading latest JAR file: " + jarFile));
|
|
||||||
File copyTo;
|
|
||||||
if (!module)
|
|
||||||
{
|
{
|
||||||
copyTo = new File(Bukkit.getUpdateFolderFile(), jarFile);
|
JsonObject object = new Gson().fromJson(reader, JsonObject.class);
|
||||||
}
|
JsonObject artifact = object.getAsJsonArray("artifacts").asList().getFirst().getAsJsonObject();
|
||||||
else
|
String jarFile = artifact.get("fileName").getAsString();
|
||||||
{
|
sender.sendMessage(PlexUtils.mmDeserialize("<green>Downloading latest JAR file: " + jarFile));
|
||||||
copyTo = new File(plugin.getModulesFolder().getPath(), jarFile);
|
File copyTo;
|
||||||
}
|
if (!module)
|
||||||
CompletableFuture.runAsync(() ->
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
FileUtils.copyURLToFile(
|
copyTo = new File(Bukkit.getUpdateFolderFile(), jarFile);
|
||||||
URI.create(url + "/lastSuccessfulBuild/artifact/build/libs/" + jarFile).toURL(),
|
|
||||||
copyTo
|
|
||||||
);
|
|
||||||
sender.sendMessage(PlexUtils.mmDeserialize("<green>New JAR file downloaded successfully."));
|
|
||||||
}
|
}
|
||||||
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("<green>New JAR file downloaded successfully."));
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (JsonSyntaxException | NumberFormatException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (statusCode == HttpURLConnection.HTTP_NOT_FOUND)
|
else if (statusCode == HttpURLConnection.HTTP_NOT_FOUND)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user