Remove VersionFetcher && unnecessary LogManager.getLogger()
This commit is contained in:
172
patches/server/0017-Patina-Remove-VersionFetcher.patch
Normal file
172
patches/server/0017-Patina-Remove-VersionFetcher.patch
Normal file
@@ -0,0 +1,172 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Etil <81570777+etil2jz@users.noreply.github.com>
|
||||
Date: Sun, 19 Sep 2021 11:17:16 +0200
|
||||
Subject: [PATCH] (Patina) Remove VersionFetcher
|
||||
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
||||
deleted file mode 100644
|
||||
index 51d89d6bcbcc24a6be6a836263ebb1ed23e91cba..0000000000000000000000000000000000000000
|
||||
--- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
||||
+++ /dev/null
|
||||
@@ -1,142 +0,0 @@
|
||||
-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.*;
|
||||
-import net.kyori.adventure.text.Component;
|
||||
-import net.kyori.adventure.text.TextComponent;
|
||||
-import net.kyori.adventure.text.format.NamedTextColor;
|
||||
-import net.kyori.adventure.text.format.TextDecoration;
|
||||
-
|
||||
-import javax.annotation.Nonnull;
|
||||
-import javax.annotation.Nullable;
|
||||
-import java.io.*;
|
||||
-import java.net.HttpURLConnection;
|
||||
-import java.net.URL;
|
||||
-import java.util.stream.StreamSupport;
|
||||
-
|
||||
-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 @Nullable String mcVer;
|
||||
-
|
||||
- @Override
|
||||
- public long getCacheTime() {
|
||||
- return 720000;
|
||||
- }
|
||||
-
|
||||
- @Nonnull
|
||||
- @Override
|
||||
- public Component getVersionMessage(@Nonnull String serverVersion) {
|
||||
- String[] parts = serverVersion.substring("git-Airplane-".length()).split("[-\\s]"); // Tuinity
|
||||
- final Component updateMessage = getUpdateStatusMessage("TECHNOVE/Airplane", GITHUB_BRANCH_NAME, parts[0]); // Tuinity
|
||||
- final Component history = getHistory();
|
||||
-
|
||||
- return history != null ? TextComponent.ofChildren(updateMessage, Component.newline(), history) : updateMessage;
|
||||
- }
|
||||
-
|
||||
- private static @Nullable String getMinecraftVersion() {
|
||||
- if (mcVer == null) {
|
||||
- java.util.regex.Matcher matcher = VER_PATTERN.matcher(org.bukkit.Bukkit.getBukkitVersion());
|
||||
- if (matcher.find()) {
|
||||
- String result = matcher.group();
|
||||
- mcVer = result.substring(0, result.length() - 2); // strip 'R' anchor and trailing '-'
|
||||
- } else {
|
||||
- org.bukkit.Bukkit.getLogger().warning("Unable to match version to pattern! Report to PaperMC!");
|
||||
- org.bukkit.Bukkit.getLogger().warning("Pattern: " + VER_PATTERN.toString());
|
||||
- org.bukkit.Bukkit.getLogger().warning("Version: " + org.bukkit.Bukkit.getBukkitVersion());
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- return mcVer;
|
||||
- }
|
||||
-
|
||||
- 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);
|
||||
- //}
|
||||
-
|
||||
- switch (distance) {
|
||||
- case -1:
|
||||
- return Component.text("Error obtaining version information", NamedTextColor.YELLOW);
|
||||
- case 0:
|
||||
- return Component.text("You are running the latest version", NamedTextColor.GREEN);
|
||||
- case -2:
|
||||
- return Component.text("Unknown version", NamedTextColor.YELLOW);
|
||||
- default:
|
||||
- return Component.text("You are " + distance + " version(s) behind", NamedTextColor.YELLOW);
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- private static int fetchDistanceFromSiteApi(int jenkinsBuild, @Nullable String siteApiVersion) {
|
||||
- if (siteApiVersion == null) { return -1; }
|
||||
- try {
|
||||
- try (BufferedReader reader = Resources.asCharSource(
|
||||
- new URL("https://papermc.io/api/v2/projects/paper/versions/" + siteApiVersion),
|
||||
- Charsets.UTF_8
|
||||
- ).openBufferedStream()) {
|
||||
- JsonObject json = new Gson().fromJson(reader, JsonObject.class);
|
||||
- JsonArray builds = json.getAsJsonArray("builds");
|
||||
- int latest = StreamSupport.stream(builds.spliterator(), false)
|
||||
- .mapToInt(e -> e.getAsInt())
|
||||
- .max()
|
||||
- .getAsInt();
|
||||
- return latest - jenkinsBuild;
|
||||
- } catch (JsonSyntaxException ex) {
|
||||
- ex.printStackTrace();
|
||||
- return -1;
|
||||
- }
|
||||
- } catch (IOException e) {
|
||||
- e.printStackTrace();
|
||||
- return -1;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- // Contributed by Techcable <Techcable@outlook.com> in GH-65
|
||||
- private static int fetchDistanceFromGitHub(@Nonnull String repo, @Nonnull String branch, @Nonnull String hash) {
|
||||
- try {
|
||||
- HttpURLConnection connection = (HttpURLConnection) new URL("https://api.github.com/repos/" + repo + "/compare/" + branch + "..." + hash).openConnection();
|
||||
- connection.connect();
|
||||
- if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) return -2; // Unknown commit
|
||||
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8))) {
|
||||
- JsonObject obj = new Gson().fromJson(reader, JsonObject.class);
|
||||
- String status = obj.get("status").getAsString();
|
||||
- switch (status) {
|
||||
- case "identical":
|
||||
- return 0;
|
||||
- case "behind":
|
||||
- return obj.get("behind_by").getAsInt();
|
||||
- default:
|
||||
- return -1;
|
||||
- }
|
||||
- } catch (JsonSyntaxException | NumberFormatException e) {
|
||||
- e.printStackTrace();
|
||||
- return -1;
|
||||
- }
|
||||
- } catch (IOException e) {
|
||||
- e.printStackTrace();
|
||||
- return -1;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- @Nullable
|
||||
- private Component getHistory() {
|
||||
- final VersionHistoryManager.VersionData data = VersionHistoryManager.INSTANCE.getVersionData();
|
||||
- if (data == null) {
|
||||
- return null;
|
||||
- }
|
||||
-
|
||||
- final String oldVersion = data.getOldVersion();
|
||||
- if (oldVersion == null) {
|
||||
- return null;
|
||||
- }
|
||||
-
|
||||
- return Component.text("Previous version: " + oldVersion, NamedTextColor.GRAY, TextDecoration.ITALIC);
|
||||
- }
|
||||
-}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
index 72cfffd80ad76abe7cb16bc9133730338c07b6f6..fe059446a2860d52865c6db15ddd162ad69b0e38 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
@@ -392,10 +392,12 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
return com.destroystokyo.paper.PaperConfig.timingsServerName;
|
||||
}
|
||||
|
||||
- @Override
|
||||
+ /* // Patina
|
||||
+ @Override
|
||||
public com.destroystokyo.paper.util.VersionFetcher getVersionFetcher() {
|
||||
return new com.destroystokyo.paper.PaperVersionFetcher();
|
||||
}
|
||||
+ */
|
||||
|
||||
@Override
|
||||
public boolean isSupportedApiVersion(String apiVersion) {
|
||||
@@ -0,0 +1,28 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Etil <81570777+etil2jz@users.noreply.github.com>
|
||||
Date: Sun, 19 Sep 2021 11:23:50 +0200
|
||||
Subject: [PATCH] (Patina) Remove unnecessary `LogManager.getLogger()`
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
index a1f639651c6308c8329f93d1bbfb5dc4706de95d..3c272e6c7552cb5bc875cdaefc91aaac3751ec3a 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
@@ -164,7 +164,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
||||
@Override
|
||||
public synchronized void setSeed(long seed) {
|
||||
if (locked) {
|
||||
- LogManager.getLogger().error("Ignoring setSeed on Entity.SHARED_RANDOM", new Throwable());
|
||||
+ LOGGER.error("Ignoring setSeed on Entity.SHARED_RANDOM", new Throwable()); // Patina - LOGGER
|
||||
} else {
|
||||
super.setSeed(seed);
|
||||
locked = true;
|
||||
@@ -2317,7 +2317,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
||||
try {
|
||||
spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.valueOf(spawnReasonName);
|
||||
} catch (Exception ignored) {
|
||||
- LogManager.getLogger().error("Unknown SpawnReason " + spawnReasonName + " for " + this);
|
||||
+ LOGGER.error("Unknown SpawnReason " + spawnReasonName + " for " + this); // Patina - LOGGER
|
||||
}
|
||||
}
|
||||
if (spawnReason == null) {
|
||||
Reference in New Issue
Block a user