From deb2116724eb7edfb1f1a942653d6bebc1bca84e Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Fri, 16 Dec 2022 09:37:06 -0800 Subject: [PATCH] Fix metrics reporting unknown paper version (#8683) Co-authored-by: BillyGalbreath --- patches/server/Paper-Metrics.patch | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/patches/server/Paper-Metrics.patch b/patches/server/Paper-Metrics.patch index 552d57fd5b..bc307c004e 100644 --- a/patches/server/Paper-Metrics.patch +++ b/patches/server/Paper-Metrics.patch @@ -619,7 +619,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + metrics.addCustomChart(new Metrics.SingleLineChart("players", () -> Bukkit.getOnlinePlayers().size())); + metrics.addCustomChart(new Metrics.SimplePie("online_mode", () -> Bukkit.getOnlineMode() ? "online" : "offline")); -+ metrics.addCustomChart(new Metrics.SimplePie("paper_version", () -> (Metrics.class.getPackage().getImplementationVersion() != null) ? Metrics.class.getPackage().getImplementationVersion() : "unknown")); ++ final String paperVersion; ++ final String implVersion = org.bukkit.craftbukkit.Main.class.getPackage().getImplementationVersion(); ++ if (implVersion != null) { ++ final String buildOrHash = implVersion.substring(implVersion.lastIndexOf('-') + 1); ++ paperVersion = "git-Paper-%s-%s".formatted(Bukkit.getServer().getMinecraftVersion(), buildOrHash); ++ } else { ++ paperVersion = "unknown"; ++ } ++ metrics.addCustomChart(new Metrics.SimplePie("paper_version", () -> paperVersion)); + + metrics.addCustomChart(new Metrics.DrilldownPie("java_version", () -> { + Map> map = new HashMap<>();