From 9898123e05d096467b0c0afa59ad028e9257409d Mon Sep 17 00:00:00 2001 From: Sparkling Comet Date: Sat, 14 Oct 2023 22:49:06 +0200 Subject: [PATCH] Add build number from Jenkins to startup splash message --- .../java/org/shanerx/tradeshop/TradeShop.java | 10 ++++----- .../commandrunners/AdminSubCommand.java | 1 - .../commandrunners/BasicTextSubCommand.java | 1 - .../utils/versionmanagement/Updater.java | 21 +++++++++++++++++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/shanerx/tradeshop/TradeShop.java b/src/main/java/org/shanerx/tradeshop/TradeShop.java index 0a23ac04..4281f313 100644 --- a/src/main/java/org/shanerx/tradeshop/TradeShop.java +++ b/src/main/java/org/shanerx/tradeshop/TradeShop.java @@ -91,18 +91,18 @@ public void onEnable() { registration(); - getSettingManager().updateSkipHoppers(); + getVarManager().getSettingManager().updateSkipHoppers(); - getSigns(); - getStorages(); - getListManager(); + getVarManager().getSigns(); + getVarManager().getStorages(); + getVarManager().getListManager(); if (Setting.CHECK_UPDATES.getBoolean()) { new Thread(() -> getUpdater().checkCurrentVersion()).start(); } if (Setting.ALLOW_METRICS.getBoolean()) { - getMetricsManager(); + getVarManager().getMetricsManager(); getLogger().info("Metrics successfully initialized!"); } else { getLogger().warning("Metrics are disabled! Please consider enabling them to support the authors!"); diff --git a/src/main/java/org/shanerx/tradeshop/commands/commandrunners/AdminSubCommand.java b/src/main/java/org/shanerx/tradeshop/commands/commandrunners/AdminSubCommand.java index e43b0011..bcd856e7 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/commandrunners/AdminSubCommand.java +++ b/src/main/java/org/shanerx/tradeshop/commands/commandrunners/AdminSubCommand.java @@ -26,7 +26,6 @@ package org.shanerx.tradeshop.commands.commandrunners; import org.bukkit.Bukkit; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.shanerx.tradeshop.TradeShop; import org.shanerx.tradeshop.commands.SubCommand; diff --git a/src/main/java/org/shanerx/tradeshop/commands/commandrunners/BasicTextSubCommand.java b/src/main/java/org/shanerx/tradeshop/commands/commandrunners/BasicTextSubCommand.java index a17e48c4..d22d445e 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/commandrunners/BasicTextSubCommand.java +++ b/src/main/java/org/shanerx/tradeshop/commands/commandrunners/BasicTextSubCommand.java @@ -25,7 +25,6 @@ package org.shanerx.tradeshop.commands.commandrunners; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.shanerx.tradeshop.TradeShop; import org.shanerx.tradeshop.commands.CommandType; diff --git a/src/main/java/org/shanerx/tradeshop/utils/versionmanagement/Updater.java b/src/main/java/org/shanerx/tradeshop/utils/versionmanagement/Updater.java index a77edeae..25eb3d70 100644 --- a/src/main/java/org/shanerx/tradeshop/utils/versionmanagement/Updater.java +++ b/src/main/java/org/shanerx/tradeshop/utils/versionmanagement/Updater.java @@ -31,9 +31,13 @@ import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.MalformedURLException; +import java.net.URISyntaxException; import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.logging.Level; import java.util.logging.Logger; +import org.shanerx.tradeshop.TradeShop; public class Updater { @@ -85,6 +89,19 @@ public String getVersionComponent(SemVer semver) { public BuildType getBuildType() { return build; } + + public String buildNumberSuffix() { + try { + Path path = Paths.get(TradeShop.class.getProtectionDomain().getCodeSource().getLocation().toURI()); + String name = path.getFileName().toString(); + if (!name.matches(".+\\d+.jar$")) return ""; + String buildNum = name.substring(name.length() - 7, name.length() - 4); + return " build " + buildNum; + } catch (URISyntaxException e) { + e.printStackTrace(); + } + return ""; + } public RelationalStatus checkCurrentVersion() { try { @@ -106,11 +123,11 @@ public RelationalStatus checkCurrentVersion() { log.log(Level.WARNING, "[Updater] +------------------------------------------------+"); in.close(); return RelationalStatus.BEHIND; - } else if (rs == RelationalStatus.AHEAD) { + } else if (rs == RelationalStatus.AHEAD || getVersion().endsWith("DEV")) { log.log(Level.WARNING, "[Updater] +-----------------------------------------------------+"); log.log(Level.WARNING, "[Updater] You are running a developmental version of " + pdf.getName() + "!"); log.log(Level.WARNING, "[Updater] Most recent stable version: " + inputLine); - log.log(Level.WARNING, "[Updater] Current version: " + getVersion()); + log.log(Level.WARNING, "[Updater] Current version: " + getVersion() + buildNumberSuffix()); log.log(Level.WARNING, "[Updater] Please notice that the build may contain critical bugs!"); log.log(Level.WARNING, "[Updater] +-----------------------------------------------------+"); in.close();