Skip to content

Commit

Permalink
Add update warning to /sf versions (#4096)
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev authored Feb 10, 2024
1 parent da9c2ac commit 86fa6f8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
<dependency>
<groupId>com.github.baked-libs.dough</groupId>
<artifactId>dough-api</artifactId>
<version>fcdbd45aa0</version>
<version>1108163a49</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,25 @@ public void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args) {
.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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -110,6 +111,29 @@ public int getBuildNumber() {
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.
Expand Down

0 comments on commit 86fa6f8

Please sign in to comment.