From 86fa6f890019eef8d474b485552dfb8f00a4415d Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Sat, 10 Feb 2024 02:09:44 +0000 Subject: [PATCH] Add update warning to /sf versions (#4096) --- pom.xml | 2 +- .../commands/subcommands/VersionsCommand.java | 18 ++++++++++++-- .../core/services/UpdaterService.java | 24 +++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 48e7d9db9..73c46273c 100644 --- a/pom.xml +++ b/pom.xml @@ -349,7 +349,7 @@ com.github.baked-libs.dough dough-api - fcdbd45aa0 + 1108163a49 compile diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java index da4b8d4e0..24abb7364 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java @@ -65,11 +65,25 @@ class VersionsCommand extends SubCommand { .append(serverSoftware) .color(ChatColor.GREEN) .append(" " + Bukkit.getVersion() + '\n') - .color(ChatColor.DARK_GREEN) + .color(ChatColor.DARK_GREEN); + + builder .append("Slimefun ") .color(ChatColor.GREEN) - .append(Slimefun.getVersion() + '\n') + .append(Slimefun.getVersion()) .color(ChatColor.DARK_GREEN); + if (!Slimefun.getUpdater().isLatestVersion()) { + builder + .append(" (").color(ChatColor.GRAY) + .append("Update available").color(ChatColor.RED).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text( + "Your Slimefun version is out of date!\n" + + "Please update to get the latest bug fixes and performance improvements.\n" + + "Please do not report any bugs without updating first." + ))) + .append(")").color(ChatColor.GRAY); + } + + builder.append("\n"); // @formatter:on if (Slimefun.getMetricsService().getVersion() != null) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/UpdaterService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/UpdaterService.java index b556789a9..ac21007fc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/UpdaterService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/UpdaterService.java @@ -1,6 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.services; import java.io.File; +import java.util.concurrent.ExecutionException; import java.util.logging.Level; import javax.annotation.Nonnull; @@ -110,6 +111,29 @@ public class UpdaterService { return -1; } + public int getLatestVersion() { + if (updater != null && updater.getLatestVersion().isDone()) { + PrefixedVersion version; + try { + version = updater.getLatestVersion().get(); + return version.getVersionNumber(); + } catch (InterruptedException | ExecutionException e) { + return -1; + } + } + + return -1; + } + + public boolean isLatestVersion() { + if (getBuildNumber() == -1 || getLatestVersion() == -1) { + // We don't know if we're latest so just report we are + return true; + } + + return getBuildNumber() == getLatestVersion(); + } + /** * This will start the {@link UpdaterService} and check for updates. * If it can find an update it will automatically be installed.