Scissors/patches/server/0048-Change-version-fetcher-to-AMG.patch

90 lines
5.0 KiB
Diff
Raw Normal View History

2022-07-28 03:57:50 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Telesphoreo <me@telesphoreo.me>
2024-01-24 01:05:59 +00:00
Date: Tue, 23 Jan 2024 19:01:02 -0600
2022-07-28 03:57:50 +00:00
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
2024-01-24 01:05:59 +00:00
index 9d687da5bdf398bb3f6c84cdf1249a7213d09f2e..48dd50d0e443a59835e92616874c9856c7cbc401 100644
2022-07-28 03:57:50 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
+++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
2024-01-24 01:05:59 +00:00
@@ -4,6 +4,7 @@ import com.destroystokyo.paper.util.VersionFetcher;
2022-07-28 03:57:50 +00:00
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import com.google.gson.*;
+import io.papermc.paper.util.JarManifests; // Scissors
2022-07-28 03:57:50 +00:00
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
2024-01-24 01:05:59 +00:00
@@ -16,11 +17,12 @@ import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.stream.StreamSupport;
+import org.bukkit.Bukkit; // Scissors
2022-07-28 03:57:50 +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";
2023-04-07 20:48:19 +00:00
- private static final String DOWNLOAD_PAGE = "https://papermc.io/downloads/paper";
+ private static final String GITHUB_BRANCH_NAME = getBranch(); // Scissors
+ private static final String DOWNLOAD_PAGE = "https://ci.scissors.gg/job/Scissors/job/" + GITHUB_BRANCH_NAME; // Scissors
2022-07-28 03:57:50 +00:00
private static @Nullable String mcVer;
@Override
2023-04-07 20:48:19 +00:00
@@ -31,8 +33,8 @@ public class PaperVersionFetcher implements VersionFetcher {
2022-07-28 03:57:50 +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]"); // Scissors
+ final Component updateMessage = getUpdateStatusMessage("AtlasMediaGroup/Scissors", GITHUB_BRANCH_NAME, parts[0]); // Scissors
2022-07-28 03:57:50 +00:00
final Component history = getHistory();
return history != null ? TextComponent.ofChildren(updateMessage, Component.newline(), history) : updateMessage;
2023-04-07 20:48:19 +00:00
@@ -54,15 +56,24 @@ public class PaperVersionFetcher implements VersionFetcher {
2022-07-28 03:57:50 +00:00
return mcVer;
}
+ // Scissors start - Allow getting git information
+ public static String getCommit() {
+ final var manifest = JarManifests.manifest(Bukkit.getServer().getClass());
+ return manifest == null ? null : manifest.getMainAttributes().getValue("Git-Commit");
+ }
+
+ public static String getBranch() {
+ final var manifest = JarManifests.manifest(Bukkit.getServer().getClass());
+ return manifest == null ? null : manifest.getMainAttributes().getValue("Git-Branch");
+ }
+ // 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:
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
index c0538206a53f0e6d9b54bddde0259b89ac73d675..5ebb80ed81d9bbd4c69a14ccd0be6c67de2fcf0d 100644
2022-07-28 03:57:50 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
2024-01-24 01:05:59 +00:00
@@ -315,7 +315,7 @@ public class Main {
2022-07-28 03:57:50 +00:00
if (buildDate.before(deadline.getTime())) {
// Paper start - This is some stupid bullshit
System.err.println("*** Warning, you've not updated in a while! ***");
2023-04-07 20:48:19 +00:00
- System.err.println("*** Please download a new build as per instructions from https://papermc.io/downloads/paper ***"); // Paper
2024-01-24 01:05:59 +00:00
+ System.err.println("*** Please download a new build as per instructions from https://ci.scissors.gg/job/Scissors ***"); // Paper
2022-07-28 03:57:50 +00:00
//System.err.println("*** Server will start in 20 seconds ***");
//Thread.sleep(TimeUnit.SECONDS.toMillis(20));
2024-01-24 01:05:59 +00:00
// Paper end