2022-06-11 04:55:22 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Telesphoreo <me@telesphoreo.me>
Date: Sat, 26 Mar 2022 21:51:07 -0500
Subject: [PATCH] Change version fetcher to AMG
diff --git a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
2022-06-11 05:09:28 +00:00
index bf42969859545a8a520923ef1836ffa4a5cc24a0..322cd9bce402d5d34c7cb8813d05194826930c97 100644
2022-06-11 04:55:22 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
+++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
@@ -4,6 +4,8 @@ import com.destroystokyo.paper.util.VersionFetcher;
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import com.google.gson.*;
+import io.papermc.paper.util.JarManifests;
+import java.util.Map;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
2022-06-11 05:09:28 +00:00
@@ -16,11 +18,12 @@ import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.stream.StreamSupport;
+import org.bukkit.Bukkit;
2022-06-11 04:55:22 +00:00
public class PaperVersionFetcher implements VersionFetcher {
private static final java.util.regex.Pattern VER_PATTERN = java.util.regex.Pattern.compile("^([0-9\\.]*)\\-.*R"); // R is an anchor, will always give '-R' at end
- private static final String GITHUB_BRANCH_NAME = "master";
- private static final String DOWNLOAD_PAGE = "https://papermc.io/downloads";
+ private static final String GITHUB_BRANCH_NAME = getBranch();
+ private static final String DOWNLOAD_PAGE = "https://ci.plex.us.org/job/Scissors/job/" + GITHUB_BRANCH_NAME;
private static @Nullable String mcVer;
@Override
2022-06-11 05:09:28 +00:00
@@ -31,8 +34,8 @@ public class PaperVersionFetcher implements VersionFetcher {
2022-06-11 04:55:22 +00:00
@Nonnull
@Override
public Component getVersionMessage(@Nonnull String serverVersion) {
- String[] parts = serverVersion.substring("git-Paper-".length()).split("[-\\s]");
- final Component updateMessage = getUpdateStatusMessage("PaperMC/Paper", GITHUB_BRANCH_NAME, parts[0]);
+ String[] parts = serverVersion.substring("git-Scissors-".length()).split("[-\\s]");
+ final Component updateMessage = getUpdateStatusMessage("AtlasMediaGroup/Scissors", GITHUB_BRANCH_NAME, parts[0]);
final Component history = getHistory();
return history != null ? TextComponent.ofChildren(updateMessage, Component.newline(), history) : updateMessage;
2022-06-11 05:09:28 +00:00
@@ -54,15 +57,24 @@ public class PaperVersionFetcher implements VersionFetcher {
2022-06-11 04:55:22 +00:00
return mcVer;
}
+ // Scissors start - Allow getting git information
+ public static String getCommit() {
2022-06-11 05:09:28 +00:00
+ final var manifest = JarManifests.manifest(Bukkit.getServer().getClass());
+ return manifest.getMainAttributes().getValue("Git-Commit");
2022-06-11 04:55:22 +00:00
+ }
+
+ public static String getBranch() {
2022-06-11 05:09:28 +00:00
+ final var manifest = JarManifests.manifest(Bukkit.getServer().getClass());
+ return manifest.getMainAttributes().getValue("Git-Commit");
2022-06-11 04:55:22 +00:00
+ }
+ // Scissors end
+
private static Component getUpdateStatusMessage(@Nonnull String repo, @Nonnull String branch, @Nonnull String versionInfo) {
int distance;
- try {
- int jenkinsBuild = Integer.parseInt(versionInfo);
- distance = fetchDistanceFromSiteApi(jenkinsBuild, getMinecraftVersion());
- } catch (NumberFormatException ignored) {
- versionInfo = versionInfo.replace("\"", "");
- distance = fetchDistanceFromGitHub(repo, branch, versionInfo);
- }
+ // Scissors start - always use Git for version checking
+ versionInfo = getCommit();
+ distance = fetchDistanceFromGitHub(repo, branch, versionInfo);
+ // Scissors end
switch (distance) {
case -1: