Skip to content

Commit c76c2e9

Browse files
committed
work in progress
1 parent f55179d commit c76c2e9

1 file changed

Lines changed: 139 additions & 1 deletion

File tree

plazma-server/paper-patches/features/0001-Rebrand.patch

Lines changed: 139 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22
From: IPECTER <ipectert@gmail.com>
3-
Date: Sat, 13 Sep 2025 15:41:50 +0900
3+
Date: Sat, 13 Sep 2025 16:43:41 +0900
44
Subject: [PATCH] Rebrand
55

66

@@ -26,6 +26,144 @@ index 212e0df38ae3ed0b06d147fb5e7e93ef556a0bdd..7439e51cd6215729cc5abdfd9c374f33
2626

2727
metrics.addCustomChart(new Metrics.DrilldownPie("java_version", () -> {
2828
Map<String, Map<String, Integer>> map = new HashMap<>();
29+
diff --git a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
30+
index a5a7334f7a1f147945079f20aa04b4f317d9e94c..a9e8a3642d7846cef4d039835596d27a4baf7115 100644
31+
--- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
32+
+++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
33+
@@ -36,9 +36,27 @@ public class PaperVersionFetcher implements VersionFetcher {
34+
private static final int DISTANCE_ERROR = -1;
35+
private static final int DISTANCE_UNKNOWN = -2;
36+
// Purpur start - Rebrand
37+
- private static final String DOWNLOAD_PAGE = "https://purpurmc.org/downloads";
38+
+ //private static final String DOWNLOAD_PAGE = "https://purpurmc.org/downloads"; // Plazma - Version Fetcher Jenkins Integration
39+
private static int distance = DISTANCE_UNKNOWN; public int distance() { return distance; }
40+
// Purpur end - Rebrand
41+
+ // Plazma start - Version Fetcher Jenkins Integration
42+
+ private static int latestBuildNumber = -1;
43+
+ private static int currentBuildNumber = -1;
44+
+
45+
+ private static final String JENKINS_BASE = "https://ci.codemc.io/job/PlazmaMC/job/Plazma";
46+
+ private static String jenkinsJobUrlForVersion(final String mcVersion) {
47+
+ try {
48+
+ // Jenkins multibranch encodes branch "ver/1.21.8" as job path segment "ver%252F1.21.8"
49+
+ final String branch = "ver/" + mcVersion;
50+
+ final String once = java.net.URLEncoder.encode(branch, StandardCharsets.UTF_8);
51+
+ final String twice = once.replace("%", "%25");
52+
+ return JENKINS_BASE + "/job/" + twice + "/";
53+
+ } catch (final Exception e) {
54+
+ LOGGER.error("Error building Jenkins job URL for version {}", mcVersion, e);
55+
+ return JENKINS_BASE + "/"; // fallback to base
56+
+ }
57+
+ }
58+
+ // Plazma end - Version Fetcher Jenkins Integration
59+
60+
@Override
61+
public long getCacheTime() {
62+
@@ -52,7 +70,7 @@ public class PaperVersionFetcher implements VersionFetcher {
63+
if (build.buildNumber().isEmpty() && build.gitCommit().isEmpty()) {
64+
updateMessage = text("You are running a development version without access to version information", color(0xFF5300));
65+
} else {
66+
- updateMessage = getUpdateStatusMessage("PurpurMC/Purpur", build); // Purpur - Rebrand
67+
+ updateMessage = getUpdateStatusMessage("PlazmaMC/Plazma", build); // Purpur - Rebrand // Plazma - Version Fetcher Jenkins Integration
68+
}
69+
final @Nullable Component history = this.getHistory();
70+
71+
@@ -61,9 +79,16 @@ public class PaperVersionFetcher implements VersionFetcher {
72+
73+
private static Component getUpdateStatusMessage(final String repo, final ServerBuildInfo build) {
74+
//int distance = DISTANCE_ERROR; // Purpur - use field - Rebrand
75+
+ // Plazma start - Version Fetcher Jenkins Integration
76+
+ String downloadPage = jenkinsJobUrlForVersion(build.minecraftVersionId());
77+
78+
final OptionalInt buildNumber = build.buildNumber();
79+
if (buildNumber.isPresent()) {
80+
+ // Plazma start - Version Fetcher Jenkins Integration
81+
+ currentBuildNumber = buildNumber.getAsInt();
82+
+ latestBuildNumber = -1; // reset before fetch
83+
+ // Plazma end - Version Fetcher Jenkins Integration
84+
+ // Prefer Jenkins (integrated) via fetchDistanceFromSiteApi
85+
distance = fetchDistanceFromSiteApi(build, buildNumber.getAsInt());
86+
} else {
87+
final Optional<String> gitBranch = build.gitBranch();
88+
@@ -72,38 +97,65 @@ public class PaperVersionFetcher implements VersionFetcher {
89+
distance = fetchDistanceFromGitHub(repo, gitBranch.get(), gitCommit.get());
90+
}
91+
}
92+
+ // Plazma end - Version Fetcher Jenkins Integration
93+
94+
- return switch (distance) {
95+
+ Component base = switch (distance) {
96+
case DISTANCE_ERROR -> text("* Error obtaining version information", NamedTextColor.RED); // Purpur - Rebrand
97+
case 0 -> text("* You are running the latest version", NamedTextColor.GREEN); // Purpur - Rebrand
98+
case DISTANCE_UNKNOWN -> text("* Unknown version", NamedTextColor.YELLOW); // Purpur - Rebrand
99+
default -> text("* You are " + distance + " version(s) behind", NamedTextColor.YELLOW) // Purpur - Rebrand
100+
.append(Component.newline())
101+
.append(text("Download the new version at: ")
102+
- .append(text(DOWNLOAD_PAGE, NamedTextColor.GOLD)
103+
+ .append(text(downloadPage, NamedTextColor.GOLD)
104+
.hoverEvent(text("Click to open", NamedTextColor.WHITE))
105+
- .clickEvent(ClickEvent.openUrl(DOWNLOAD_PAGE))));
106+
+ .clickEvent(ClickEvent.openUrl(downloadPage))));
107+
};
108+
+ // Plazma start - Version Fetcher Jenkins Integration
109+
+ if (currentBuildNumber >= 0 && latestBuildNumber >= 0) {
110+
+ base = Component.textOfChildren(
111+
+ base,
112+
+ Component.newline(),
113+
+ text("#" + currentBuildNumber + " #" + latestBuildNumber, NamedTextColor.GRAY)
114+
+ );
115+
+ }
116+
+ return base;
117+
+ // Plazma end - Version Fetcher Jenkins Integration
118+
}
119+
120+
+
121+
+
122+
private static int fetchDistanceFromSiteApi(final ServerBuildInfo build, final int jenkinsBuild) {
123+
+ // Plazma start - Version Fetcher Jenkins Integration
124+
+ // Jenkins-only: fetch latestSuccessfulBuild from Jenkins; no fallback
125+
+ final String jobUrl = jenkinsJobUrlForVersion(build.minecraftVersionId());
126+
+ final String api = jobUrl + "api/json?tree=lastSuccessfulBuild[number,url]";
127+
try {
128+
- try (final BufferedReader reader = Resources.asCharSource(
129+
- URI.create("https://api.purpurmc.org/v2/purpur/" + build.minecraftVersionId()).toURL(), // Purpur - Rebrand
130+
- StandardCharsets.UTF_8
131+
- ).openBufferedStream()) {
132+
- final JsonObject json = new Gson().fromJson(reader, JsonObject.class);
133+
- //final JsonArray builds = json.getAsJsonArray("builds"); // Purpur - Rebrand
134+
- final int latest = json.getAsJsonObject("builds").getAsJsonPrimitive("latest").getAsInt(); // Purpur - Rebrand
135+
+ final HttpURLConnection connection = (HttpURLConnection) URI.create(api).toURL().openConnection();
136+
+ connection.connect();
137+
+ if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
138+
+ return DISTANCE_ERROR;
139+
+ }
140+
+ try (final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
141+
+ final JsonObject obj = new Gson().fromJson(reader, JsonObject.class);
142+
+ if (!obj.has("lastSuccessfulBuild") || obj.get("lastSuccessfulBuild").isJsonNull()) {
143+
+ return DISTANCE_ERROR;
144+
+ }
145+
+ final JsonObject last = obj.getAsJsonObject("lastSuccessfulBuild");
146+
+ if (!last.has("number")) {
147+
+ return DISTANCE_ERROR;
148+
+ }
149+
+ final int latest = last.get("number").getAsInt();
150+
+ latestBuildNumber = latest;
151+
return latest - jenkinsBuild;
152+
- } catch (final JsonSyntaxException ex) {
153+
- LOGGER.error("Error parsing json from Purpur's downloads API", ex); // Purpur - Rebrand
154+
+ } catch (final JsonSyntaxException | NumberFormatException e) {
155+
+ LOGGER.error("Error parsing json from Jenkins API", e);
156+
return DISTANCE_ERROR;
157+
}
158+
} catch (final IOException e) {
159+
- LOGGER.error("Error while parsing version", e);
160+
+ LOGGER.error("Error while accessing Jenkins API", e);
161+
return DISTANCE_ERROR;
162+
}
163+
+ // Plazma end - Version Fetcher Jenkins Integration
164+
}
165+
166+
// Contributed by Techcable <Techcable@outlook.com> in GH-65
29167
diff --git a/src/main/java/com/destroystokyo/paper/console/PaperConsole.java b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
30168
index bc7e4e5560708fea89c584b1d8b471f4966f311a..8f0773004ce8adb854b5d5e2235488a7a6bce22b 100644
31169
--- a/src/main/java/com/destroystokyo/paper/console/PaperConsole.java

0 commit comments

Comments
 (0)