Allow specifying branch for update checking

This commit is contained in:
Telesphoreo 2022-04-07 15:59:09 -05:00
parent 1b7a06794b
commit 890f847c2f
2 changed files with 13 additions and 4 deletions

View File

@ -40,6 +40,7 @@ public class UpdateChecker extends PlexBase
* > 0 = Number of commits behind * > 0 = Number of commits behind
*/ */
private final String DOWNLOAD_PAGE = "https://ci.plex.us.org/job/Plex/"; private final String DOWNLOAD_PAGE = "https://ci.plex.us.org/job/Plex/";
private String branch = plugin.config.getString("update_branch");
private int distance = -4; private int distance = -4;
// Adapted from Paper // Adapted from Paper
@ -83,10 +84,15 @@ public class UpdateChecker extends PlexBase
public boolean getUpdateStatusMessage(CommandSender sender, boolean cached, boolean verbose) public boolean getUpdateStatusMessage(CommandSender sender, boolean cached, boolean verbose)
{ {
if (branch == null)
{
PlexLog.error("You did not specify a branch to use for update checking. Defaulting to master.");
branch = "master";
}
// If it's -4, it hasn't checked for updates yet // If it's -4, it hasn't checked for updates yet
if (distance == -4) if (distance == -4)
{ {
distance = fetchDistanceFromGitHub("plexusorg/Plex", "master", Plex.build.head); distance = fetchDistanceFromGitHub("plexusorg/Plex", branch, Plex.build.head);
PlexLog.debug("Never checked for updates, checking now..."); PlexLog.debug("Never checked for updates, checking now...");
} }
else else
@ -94,7 +100,7 @@ public class UpdateChecker extends PlexBase
// If the request isn't asked to be cached, fetch it // If the request isn't asked to be cached, fetch it
if (!cached) if (!cached)
{ {
distance = fetchDistanceFromGitHub("plexusorg/Plex", "master", Plex.build.head); distance = fetchDistanceFromGitHub("plexusorg/Plex", branch, Plex.build.head);
PlexLog.debug("We have checked for updates before, but this request was not asked to be cached."); PlexLog.debug("We have checked for updates before, but this request was not asked to be cached.");
} }
else else
@ -143,7 +149,7 @@ public class UpdateChecker extends PlexBase
public void updateJar(CommandSender sender) public void updateJar(CommandSender sender)
{ {
CloseableHttpClient client = HttpClients.createDefault(); CloseableHttpClient client = HttpClients.createDefault();
HttpGet get = new HttpGet(DOWNLOAD_PAGE + "job/master/lastSuccessfulBuild/api/json"); HttpGet get = new HttpGet(DOWNLOAD_PAGE + "job/" + branch + "/lastSuccessfulBuild/api/json");
try try
{ {
HttpResponse response = client.execute(get); HttpResponse response = client.execute(get);
@ -156,7 +162,7 @@ public class UpdateChecker extends PlexBase
try try
{ {
FileUtils.copyURLToFile( FileUtils.copyURLToFile(
new URL(DOWNLOAD_PAGE + "job/master/lastSuccessfulBuild/artifact/build/libs/" + name), new URL(DOWNLOAD_PAGE + "job/" + branch + "/lastSuccessfulBuild/artifact/build/libs/" + name),
new File(Bukkit.getUpdateFolderFile(), name) new File(Bukkit.getUpdateFolderFile(), name)
); );
sendMini(sender, "Saved new jar. Please restart your server."); sendMini(sender, "Saved new jar. Please restart your server.");

View File

@ -208,5 +208,8 @@ worlds:
stone: 16 stone: 16
bedrock: 1 bedrock: 1
# What branch should Plex fetch updates from?
update_branch: master
# Additional logging for debugging # Additional logging for debugging
debug: false debug: false