From b4f8cbb28978d71d1a21d0d294862459c6c38cc7 Mon Sep 17 00:00:00 2001 From: 404Setup <153366651+404Setup@users.noreply.github.com> Date: Sun, 4 Aug 2024 12:50:01 +0800 Subject: [PATCH] re-provide version check --- ...sion-checking.patch => 0002-Rebrand.patch} | 173 ++++-------------- 1 file changed, 31 insertions(+), 142 deletions(-) rename patches/server/{0002-Rebrand-and-Disable-version-checking.patch => 0002-Rebrand.patch} (86%) diff --git a/patches/server/0002-Rebrand-and-Disable-version-checking.patch b/patches/server/0002-Rebrand.patch similarity index 86% rename from patches/server/0002-Rebrand-and-Disable-version-checking.patch rename to patches/server/0002-Rebrand.patch index 275133f..bd6ffea 100644 --- a/patches/server/0002-Rebrand-and-Disable-version-checking.patch +++ b/patches/server/0002-Rebrand.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: 404Setup <153366651+404Setup@users.noreply.github.com> Date: Wed, 29 May 2024 22:34:03 +0800 -Subject: [PATCH] Rebrand and Disable version checking +Subject: [PATCH] Rebrand diff --git a/src/main/java/com/destroystokyo/paper/Metrics.java b/src/main/java/com/destroystokyo/paper/Metrics.java @@ -27,156 +27,45 @@ index b52a805150e95d7d27403d3c18088b335a355011..4fa5ca79ea9c015fad4f814ab1e05190 metrics.addCustomChart(new Metrics.DrilldownPie("java_version", () -> { Map> map = new HashMap<>(); diff --git a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java -index 2f37873738ab542980d13f36356b04b4904e625b..a0094c7a35103e44670c9821219ddf70b38382fc 100644 +index 2f37873738ab542980d13f36356b04b4904e625b..ae4363b8cc247d6d659aa903b1077001eb9eaebd 100644 --- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java +++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java -@@ -1,41 +1,15 @@ - package com.destroystokyo.paper; - - import com.destroystokyo.paper.util.VersionFetcher; --import com.google.common.base.Charsets; --import com.google.common.io.Resources; --import com.google.gson.Gson; --import com.google.gson.JsonArray; --import com.google.gson.JsonElement; --import com.google.gson.JsonObject; --import com.google.gson.JsonSyntaxException; --import com.mojang.logging.LogUtils; --import io.papermc.paper.ServerBuildInfo; --import java.io.BufferedReader; --import java.io.IOException; --import java.io.InputStreamReader; --import java.net.HttpURLConnection; --import java.net.URI; --import java.util.Optional; --import java.util.OptionalInt; --import java.util.stream.StreamSupport; - import net.kyori.adventure.text.Component; --import net.kyori.adventure.text.event.ClickEvent; --import net.kyori.adventure.text.format.NamedTextColor; --import net.kyori.adventure.text.format.TextDecoration; - import org.checkerframework.checker.nullness.qual.NonNull; --import org.checkerframework.checker.nullness.qual.Nullable; - import org.checkerframework.framework.qual.DefaultQualifier; --import org.slf4j.Logger; - - import static net.kyori.adventure.text.Component.text; - import static net.kyori.adventure.text.format.TextColor.color; - - @DefaultQualifier(NonNull.class) - public class PaperVersionFetcher implements VersionFetcher { -- private static final Logger LOGGER = LogUtils.getClassLogger(); -- private static final int DISTANCE_ERROR = -1; -- private static final int DISTANCE_UNKNOWN = -2; +@@ -35,7 +35,7 @@ public class PaperVersionFetcher implements VersionFetcher { + private static final Logger LOGGER = LogUtils.getClassLogger(); + private static final int DISTANCE_ERROR = -1; + private static final int DISTANCE_UNKNOWN = -2; - private static final String DOWNLOAD_PAGE = "https://github.com/LuminolMC/Luminol"; //Luminol ++ private static final String DOWNLOAD_PAGE = "https://tranic.one/downloads/levelbukkit"; // Luminol // LevelBukkit @Override public long getCacheTime() { -@@ -44,103 +18,6 @@ public class PaperVersionFetcher implements VersionFetcher { - - @Override - public Component getVersionMessage(final String serverVersion) { -- final Component updateMessage; -- final ServerBuildInfo build = ServerBuildInfo.buildInfo(); -- if (build.buildNumber().isEmpty() && build.gitCommit().isEmpty()) { -- updateMessage = text("You are running a development version without access to version information", color(0xFF5300)); -- } else { +@@ -49,7 +49,7 @@ public class PaperVersionFetcher implements VersionFetcher { + if (build.buildNumber().isEmpty() && build.gitCommit().isEmpty()) { + updateMessage = text("You are running a development version without access to version information", color(0xFF5300)); + } else { - updateMessage = getUpdateStatusMessage("LuminolMC/Luminol", build); // Folia // Luminol -- } -- final @Nullable Component history = this.getHistory(); -- -- return history != null ? Component.textOfChildren(updateMessage, Component.newline(), history) : updateMessage; -- } -- -- private static Component getUpdateStatusMessage(final String repo, final ServerBuildInfo build) { -- int distance = DISTANCE_ERROR; -- -- final OptionalInt buildNumber = build.buildNumber(); -- if (buildNumber.isPresent()) { -- distance = fetchDistanceFromSiteApi(build, buildNumber.getAsInt()); -- } else { -- final Optional gitBranch = build.gitBranch(); -- final Optional gitCommit = build.gitCommit(); -- if (gitBranch.isPresent() && gitCommit.isPresent()) { -- distance = fetchDistanceFromGitHub(repo, gitBranch.get(), gitCommit.get()); -- } -- } -- -- return switch (distance) { -- case DISTANCE_ERROR -> text("Error obtaining version information", NamedTextColor.YELLOW); -- case 0 -> text("You are running the latest version", NamedTextColor.GREEN); -- case DISTANCE_UNKNOWN -> text("Unknown version", NamedTextColor.YELLOW); -- default -> text("You are " + distance + " version(s) behind", NamedTextColor.YELLOW) -- .append(Component.newline()) -- .append(text("Download the new version at: ") -- .append(text(DOWNLOAD_PAGE, NamedTextColor.GOLD) -- .hoverEvent(text("Click to open", NamedTextColor.WHITE)) -- .clickEvent(ClickEvent.openUrl(DOWNLOAD_PAGE)))); -- }; -- } -- -- private static int fetchDistanceFromSiteApi(final ServerBuildInfo build, final int jenkinsBuild) { -- try { -- try (final BufferedReader reader = Resources.asCharSource( ++ updateMessage = getUpdateStatusMessage("LevelTranic/LevelBukkit", build); // Folia // Luminol // LevelBukkit + } + final @Nullable Component history = this.getHistory(); + +@@ -86,7 +86,7 @@ public class PaperVersionFetcher implements VersionFetcher { + private static int fetchDistanceFromSiteApi(final ServerBuildInfo build, final int jenkinsBuild) { + try { + try (final BufferedReader reader = Resources.asCharSource( - URI.create("https://api.papermc.io/v2/projects/folia/versions/" + build.minecraftVersionId()).toURL(), // Folia -- Charsets.UTF_8 -- ).openBufferedStream()) { -- final JsonObject json = new Gson().fromJson(reader, JsonObject.class); -- final JsonArray builds = json.getAsJsonArray("builds"); -- final int latest = StreamSupport.stream(builds.spliterator(), false) -- .mapToInt(JsonElement::getAsInt) -- .max() -- .orElseThrow(); -- return latest - jenkinsBuild; -- } catch (final JsonSyntaxException ex) { ++ URI.create("https://mars.tranic.one/v2/projects/levelbukkit/versions/" + build.minecraftVersionId()).toURL(), // Folia // LevelBukkit + Charsets.UTF_8 + ).openBufferedStream()) { + final JsonObject json = new Gson().fromJson(reader, JsonObject.class); +@@ -97,7 +97,7 @@ public class PaperVersionFetcher implements VersionFetcher { + .orElseThrow(); + return latest - jenkinsBuild; + } catch (final JsonSyntaxException ex) { - LOGGER.error("Error parsing json from Paper's downloads API", ex); -- return DISTANCE_ERROR; -- } -- } catch (final IOException e) { -- LOGGER.error("Error while parsing version", e); -- return DISTANCE_ERROR; -- } -- } -- -- // Contributed by Techcable in GH-65 -- private static int fetchDistanceFromGitHub(final String repo, final String branch, final String hash) { -- try { -- final HttpURLConnection connection = (HttpURLConnection) URI.create("https://api.github.com/repos/%s/compare/%s...%s".formatted(repo, branch, hash)).toURL().openConnection(); -- connection.connect(); -- if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) return DISTANCE_UNKNOWN; // Unknown commit -- try (final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8))) { -- final JsonObject obj = new Gson().fromJson(reader, JsonObject.class); -- final String status = obj.get("status").getAsString(); -- return switch (status) { -- case "identical" -> 0; -- case "behind" -> obj.get("behind_by").getAsInt(); -- default -> DISTANCE_ERROR; -- }; -- } catch (final JsonSyntaxException | NumberFormatException e) { -- LOGGER.error("Error parsing json from GitHub's API", e); -- return DISTANCE_ERROR; -- } -- } catch (final IOException e) { -- LOGGER.error("Error while parsing version", e); -- return DISTANCE_ERROR; -- } -- } -- -- private @Nullable Component getHistory() { -- final VersionHistoryManager.@Nullable VersionData data = VersionHistoryManager.INSTANCE.getVersionData(); -- if (data == null) { -- return null; -- } -- -- final @Nullable String oldVersion = data.getOldVersion(); -- if (oldVersion == null) { -- return null; -- } -- -- return text("Previous version: " + oldVersion, NamedTextColor.GRAY, TextDecoration.ITALIC); -+ return text("You are running a development version without access to version information", color(0xFF5300)); - } - } ++ LOGGER.error("Error parsing json from downloads API", ex); + return DISTANCE_ERROR; + } + } catch (final IOException e) { diff --git a/src/main/java/io/papermc/paper/ServerBuildInfoImpl.java b/src/main/java/io/papermc/paper/ServerBuildInfoImpl.java index 673a81734a0903a0790f3007772642d3d9a044cc..47149c555468de95a3814cd967652fd583fd45d4 100644 --- a/src/main/java/io/papermc/paper/ServerBuildInfoImpl.java