mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 09:37:37 +00:00
Merge branch 'master' of https://github.com/plexusorg/Plex
This commit is contained in:
commit
c6aa4cf0a4
16
Jenkinsfile
vendored
Normal file
16
Jenkinsfile
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
stages {
|
||||||
|
stage('build') {
|
||||||
|
steps {
|
||||||
|
sh './gradlew build javadoc publish --no-daemon'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
archiveArtifacts artifacts: 'build/libs/*.jar', fingerprint: true
|
||||||
|
deleteWs()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,7 @@ import java.util.stream.Collectors;
|
|||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
@ -96,6 +97,10 @@ public class PlexCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
return messageComponent("noPermissionConsole");
|
return messageComponent("noPermissionConsole");
|
||||||
}
|
}
|
||||||
|
if (!plugin.getUpdateChecker().getUpdateStatus(false))
|
||||||
|
{
|
||||||
|
return MiniMessage.miniMessage().deserialize("<red>Plex is already up to date!");
|
||||||
|
}
|
||||||
plugin.getUpdateChecker().updateJar();
|
plugin.getUpdateChecker().updateJar();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,6 @@ import com.google.gson.JsonObject;
|
|||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.PlexBase;
|
import dev.plex.PlexBase;
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import javax.annotation.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;
|
||||||
@ -23,11 +14,20 @@ import org.apache.http.client.methods.HttpGet;
|
|||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.util.FileUtil;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class UpdateChecker extends PlexBase
|
public class UpdateChecker extends PlexBase
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -80,6 +80,44 @@ public class UpdateChecker extends PlexBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getUpdateStatus(boolean cached)
|
||||||
|
{
|
||||||
|
if (distance == -4)
|
||||||
|
{
|
||||||
|
distance = fetchDistanceFromGitHub("plexusorg/Plex", "master", Plex.build.head);
|
||||||
|
PlexLog.debug("Never checked for updates, checking now...");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If the request isn't asked to be cached, fetch it
|
||||||
|
if (!cached)
|
||||||
|
{
|
||||||
|
distance = fetchDistanceFromGitHub("plexusorg/Plex", "master", Plex.build.head);
|
||||||
|
PlexLog.debug("We have checked for updates before, but this request was not asked to be cached.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlexLog.debug("We have checked for updates before, using cache.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (distance)
|
||||||
|
{
|
||||||
|
case -1 -> {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case 0 -> {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case -2 -> {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean getUpdateStatusMessage(CommandSender sender, boolean cached)
|
public boolean getUpdateStatusMessage(CommandSender sender, boolean cached)
|
||||||
{
|
{
|
||||||
// If it's -4, it hasn't checked for updates yet
|
// If it's -4, it hasn't checked for updates yet
|
||||||
@ -136,20 +174,23 @@ public class UpdateChecker extends PlexBase
|
|||||||
JSONObject artifact = object.getJSONArray("artifacts").getJSONObject(0);
|
JSONObject artifact = object.getJSONArray("artifacts").getJSONObject(0);
|
||||||
String name = artifact.getString("displayPath");
|
String name = artifact.getString("displayPath");
|
||||||
PlexLog.log("Downloading latest Plex jar file: " + name);
|
PlexLog.log("Downloading latest Plex jar file: " + name);
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() ->
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileUtils.copyURLToFile(
|
FileUtils.copyURLToFile(
|
||||||
new URL(DOWNLOAD_PAGE + "lastSuccessfulBuild/artifact/build/libs/" + name),
|
new URL(DOWNLOAD_PAGE + "lastSuccessfulBuild/artifact/build/libs/" + name),
|
||||||
new File(Plex.get().getDataFolder() + File.separator + "..", name)
|
new File(Bukkit.getUpdateFolderFile(), name)
|
||||||
);
|
);
|
||||||
PlexLog.log("Saved new jar. Please restart your server.");
|
PlexLog.log("Saved new jar. Please restart your server.");
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user