mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 04:02:50 +01:00
c0936a71bd
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 01aa02eb PR-858: Add LivingEntity#playHurtAnimation() 9421320f PR-884: Refinements to new ban API for improved compatibility and correctness 37a60b45 SPIGOT-6455, SPIGOT-7030, PR-750: Improve ban API 4eeb174b All smithing inventories are now the new smithing inventory f2bb168e PR-880: Add methods to get/set FallingBlock CancelDrop e7a807fa PR-879: Add Player#sendHealthUpdate() 692b8e96 SPIGOT-7370: Remove float value conversion in plugin.yml 2d033390 SPIGOT-7403: Add direct API for waxed signs 16a08373 PR-876: Add missing Raider API and 'no action ticks' CraftBukkit Changes: b60a95c8c PR-1189: Add LivingEntity#playHurtAnimation() 95c335c63 PR-1226: Fix VehicleEnterEvent not being called for certain entities 0a0fc3bee PR-1227: Refinements to new ban API for improved compatibility and correctness 0d0b1e5dc Revert bad change to PathfinderGoalSit causing all cats to sit 648196070 SPIGOT-6455, SPIGOT-7030, PR-1054: Improve ban API 31fe848d6 All smithing inventories are now the new smithing inventory 9a919a143 SPIGOT-7416: SmithItemEvent not firing in Smithing Table 9f64f0d22 PR-1221: Add methods to get/set FallingBlock CancelDrop 3be9ac171 PR-1220: Add Player#sendHealthUpdate() c1279f775 PR-1209: Clean up various patches c432e4397 Fix Raider#setCelebrating() implementation 504d96665 SPIGOT-7403: Add direct API for waxed signs c68c1f1b3 PR-1216: Add missing Raider API and 'no action ticks' 85b89c3dd Increase outdated build delay Spigot Changes: 9ebce8af Rebuild patches 64b565e6 Rebuild patches
101 lines
5 KiB
Diff
101 lines
5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Professor Bloodstone <git@bloodstone.dev>
|
|
Date: Sun, 20 Jun 2021 01:48:31 +0200
|
|
Subject: [PATCH] Add Git information to version command/on startup
|
|
|
|
|
|
diff --git a/src/main/java/io/papermc/paper/util/JarManifests.java b/src/main/java/io/papermc/paper/util/JarManifests.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..909617079db61b675cc7b60b44ef96b306076343
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/util/JarManifests.java
|
|
@@ -0,0 +1,37 @@
|
|
+package io.papermc.paper.util;
|
|
+
|
|
+import java.io.IOException;
|
|
+import java.io.InputStream;
|
|
+import java.net.URL;
|
|
+import java.util.Collections;
|
|
+import java.util.Map;
|
|
+import java.util.WeakHashMap;
|
|
+import java.util.jar.Manifest;
|
|
+import org.jetbrains.annotations.ApiStatus;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+
|
|
+@ApiStatus.Internal
|
|
+public final class JarManifests {
|
|
+ private JarManifests() {
|
|
+ }
|
|
+
|
|
+ private static final Map<ClassLoader, Manifest> MANIFESTS = Collections.synchronizedMap(new WeakHashMap<>());
|
|
+
|
|
+ public static @Nullable Manifest manifest(final @NotNull Class<?> clazz) {
|
|
+ return MANIFESTS.computeIfAbsent(clazz.getClassLoader(), classLoader -> {
|
|
+ final String classLocation = "/" + clazz.getName().replace(".", "/") + ".class";
|
|
+ final URL resource = clazz.getResource(classLocation);
|
|
+ if (resource == null) {
|
|
+ return null;
|
|
+ }
|
|
+ final String classFilePath = resource.toString().replace("\\", "/");
|
|
+ final String archivePath = classFilePath.substring(0, classFilePath.length() - classLocation.length());
|
|
+ try (final InputStream stream = new URL(archivePath + "/META-INF/MANIFEST.MF").openStream()) {
|
|
+ return new Manifest(stream);
|
|
+ } catch (final IOException ex) {
|
|
+ return null;
|
|
+ }
|
|
+ });
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
|
index 67c92e10b38af2ac45c1d9b6374695247bf1e7c3..627c04f5e71ad032760296092a65596b08807a55 100644
|
|
--- a/src/main/java/org/bukkit/Bukkit.java
|
|
+++ b/src/main/java/org/bukkit/Bukkit.java
|
|
@@ -56,6 +56,7 @@ import org.bukkit.util.CachedServerIcon;
|
|
import org.jetbrains.annotations.Contract;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
+import io.papermc.paper.util.JarManifests; // Paper
|
|
|
|
/**
|
|
* Represents the Bukkit core, for version and Server singleton handling
|
|
@@ -105,7 +106,25 @@ public final class Bukkit {
|
|
}
|
|
|
|
Bukkit.server = server;
|
|
- server.getLogger().info("This server is running " + getName() + " version " + getVersion() + " (Implementing API version " + getBukkitVersion() + ")");
|
|
+ // Paper start - add git information
|
|
+ server.getLogger().info(getVersionMessage());
|
|
+ }
|
|
+ /**
|
|
+ * Gets message describing the version server is running.
|
|
+ *
|
|
+ * @return message describing the version server is running
|
|
+ */
|
|
+ @NotNull
|
|
+ public static String getVersionMessage() {
|
|
+ final var manifest = JarManifests.manifest(Bukkit.getServer().getClass());
|
|
+ final String gitBranch = manifest == null ? null : manifest.getMainAttributes().getValue("Git-Branch");
|
|
+ final String gitCommit = manifest == null ? null : manifest.getMainAttributes().getValue("Git-Commit");
|
|
+ String branchMsg = " on " + gitBranch;
|
|
+ if ("master".equals(gitBranch) || "main".equals(gitBranch)) {
|
|
+ branchMsg = ""; // Don't show branch on main/master
|
|
+ }
|
|
+ return "This server is running " + getName() + " version " + getVersion() + " (Implementing API version " + getBukkitVersion() + ") (Git: " + gitCommit + branchMsg + ")";
|
|
+ // Paper end
|
|
}
|
|
|
|
/**
|
|
diff --git a/src/main/java/org/bukkit/command/defaults/VersionCommand.java b/src/main/java/org/bukkit/command/defaults/VersionCommand.java
|
|
index b50f614806f4634960d383e8a33f094c2f46935f..e40f017f87d6b6b4770501b106c76dc69ec69abb 100644
|
|
--- a/src/main/java/org/bukkit/command/defaults/VersionCommand.java
|
|
+++ b/src/main/java/org/bukkit/command/defaults/VersionCommand.java
|
|
@@ -240,7 +240,7 @@ public class VersionCommand extends BukkitCommand {
|
|
private void setVersionMessage(final @NotNull net.kyori.adventure.text.Component msg) {
|
|
lastCheck = System.currentTimeMillis();
|
|
final net.kyori.adventure.text.Component message = net.kyori.adventure.text.TextComponent.ofChildren(
|
|
- net.kyori.adventure.text.Component.text("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")", net.kyori.adventure.text.format.NamedTextColor.WHITE),
|
|
+ net.kyori.adventure.text.Component.text(Bukkit.getVersionMessage(), net.kyori.adventure.text.format.NamedTextColor.WHITE),
|
|
net.kyori.adventure.text.Component.newline(),
|
|
msg
|
|
);
|