From aaa1a78051212de70f88b285c1a4c2cf3f25b698 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Mon, 2 Dec 2024 18:36:21 +0100 Subject: [PATCH] Fix /updates --- .../m724/tweaks/updater/UpdaterCommands.java | 35 +++++++++++-------- src/main/resources/strings.properties | 9 ++++- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/eu/m724/tweaks/updater/UpdaterCommands.java b/src/main/java/eu/m724/tweaks/updater/UpdaterCommands.java index 6671d9e..731255c 100644 --- a/src/main/java/eu/m724/tweaks/updater/UpdaterCommands.java +++ b/src/main/java/eu/m724/tweaks/updater/UpdaterCommands.java @@ -26,23 +26,26 @@ public class UpdaterCommands implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (UpdateChecker.lastChecked == null) { - sender.sendMessage("Not checked yet"); + sender.sendMessage(Language.getString("updatesNotChecked")); return true; } - String lastChecked = UpdateChecker.lastChecked.format(DateTimeFormatter.ISO_LOCAL_TIME); + String lastChecked = UpdateChecker.lastChecked.format(DateTimeFormatter.ofPattern("HH:mm")); int n = UpdateChecker.availableUpdates.size(); if (n > 0) { - BaseComponent[] components = UpdateChecker.availableUpdates.stream() - .map(u -> resourceToBaseComponent(u)) - .toArray(BaseComponent[]::new); - components = new ComponentBuilder(Language.getString("updateAvailableNotice").formatted(n) + "\n") - .append(components) - .create(); - sender.spigot().sendMessage(components); + sender.spigot().sendMessage( + new ComponentBuilder(Language.getString("updateAvailableNotice").formatted(n)).color(ChatColor.GRAY).build() + ); + + int i = 0; + for (VersionedResource v : UpdateChecker.availableUpdates) { + sender.spigot().sendMessage( + new ComponentBuilder(++i + ". ").color(ChatColor.GRAY).build(), resourceToBaseComponent(v) + ); + } } else { - sender.sendMessage("No available updates. Last checked: " + lastChecked); + sender.sendMessage(Language.getString("updatesNoUpdates").formatted(lastChecked)); } return true; @@ -50,12 +53,15 @@ public class UpdaterCommands implements CommandExecutor { private BaseComponent resourceToBaseComponent(VersionedResource v) { Color nameColor = Color.decode("#" + Integer.toHexString(v.resource().name().hashCode()).substring(0, 6)); - ComponentBuilder componentBuilder = new ComponentBuilder(v.resource().name()).color(ChatColor.of(nameColor)) + BaseComponent component = new ComponentBuilder(v.resource().name()).color(ChatColor.of(nameColor)) .append(" (").color(ChatColor.DARK_GRAY) .append(v.running().label()).color(ChatColor.GRAY) .append(" -> ").color(ChatColor.DARK_GRAY) .append(v.latest().label()).color(ChatColor.of(nameColor.brighter())) .append(")").color(ChatColor.DARK_GRAY) + .build(); + + component = new ComponentBuilder(component) .event( new ClickEvent( ClickEvent.Action.OPEN_URL, @@ -65,10 +71,11 @@ public class UpdaterCommands implements CommandExecutor { .event( new HoverEvent( HoverEvent.Action.SHOW_TEXT, - new Text("Click to open on SpigotMC \"%s\"".formatted(v.latest().description().title())) + new Text(Language.getString("updatesClickToOpen").formatted(v.latest().description().title())) ) - ); + ) + .build(); - return componentBuilder.build(); + return component; } } diff --git a/src/main/resources/strings.properties b/src/main/resources/strings.properties index 91462d8..2d26c1c 100644 --- a/src/main/resources/strings.properties +++ b/src/main/resources/strings.properties @@ -5,4 +5,11 @@ # updateAvailableNotice = Available updates (%d): -pomodoroEndKick = Break time! Come back in 5 minutes. \ No newline at end of file +pomodoroEndKick = Break time! Come back in 5 minutes. + +# Used in /updates +updatesNotChecked = Not checked yet +# %s is time as HH:mm +updatesNoUpdates = No available updates. Last checked: %s +# %s is update title +updatesClickToOpen = Click to open on SpigotMC "%s" \ No newline at end of file