parent
2ded40ca0f
commit
aaa1a78051
2 changed files with 29 additions and 15 deletions
|
@ -26,23 +26,26 @@ public class UpdaterCommands implements CommandExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
if (UpdateChecker.lastChecked == null) {
|
if (UpdateChecker.lastChecked == null) {
|
||||||
sender.sendMessage("Not checked yet");
|
sender.sendMessage(Language.getString("updatesNotChecked"));
|
||||||
return true;
|
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();
|
int n = UpdateChecker.availableUpdates.size();
|
||||||
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
BaseComponent[] components = UpdateChecker.availableUpdates.stream()
|
sender.spigot().sendMessage(
|
||||||
.map(u -> resourceToBaseComponent(u))
|
new ComponentBuilder(Language.getString("updateAvailableNotice").formatted(n)).color(ChatColor.GRAY).build()
|
||||||
.toArray(BaseComponent[]::new);
|
);
|
||||||
components = new ComponentBuilder(Language.getString("updateAvailableNotice").formatted(n) + "\n")
|
|
||||||
.append(components)
|
int i = 0;
|
||||||
.create();
|
for (VersionedResource v : UpdateChecker.availableUpdates) {
|
||||||
sender.spigot().sendMessage(components);
|
sender.spigot().sendMessage(
|
||||||
|
new ComponentBuilder(++i + ". ").color(ChatColor.GRAY).build(), resourceToBaseComponent(v)
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("No available updates. Last checked: " + lastChecked);
|
sender.sendMessage(Language.getString("updatesNoUpdates").formatted(lastChecked));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -50,12 +53,15 @@ public class UpdaterCommands implements CommandExecutor {
|
||||||
|
|
||||||
private BaseComponent resourceToBaseComponent(VersionedResource v) {
|
private BaseComponent resourceToBaseComponent(VersionedResource v) {
|
||||||
Color nameColor = Color.decode("#" + Integer.toHexString(v.resource().name().hashCode()).substring(0, 6));
|
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(" (").color(ChatColor.DARK_GRAY)
|
||||||
.append(v.running().label()).color(ChatColor.GRAY)
|
.append(v.running().label()).color(ChatColor.GRAY)
|
||||||
.append(" -> ").color(ChatColor.DARK_GRAY)
|
.append(" -> ").color(ChatColor.DARK_GRAY)
|
||||||
.append(v.latest().label()).color(ChatColor.of(nameColor.brighter()))
|
.append(v.latest().label()).color(ChatColor.of(nameColor.brighter()))
|
||||||
.append(")").color(ChatColor.DARK_GRAY)
|
.append(")").color(ChatColor.DARK_GRAY)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
component = new ComponentBuilder(component)
|
||||||
.event(
|
.event(
|
||||||
new ClickEvent(
|
new ClickEvent(
|
||||||
ClickEvent.Action.OPEN_URL,
|
ClickEvent.Action.OPEN_URL,
|
||||||
|
@ -65,10 +71,11 @@ public class UpdaterCommands implements CommandExecutor {
|
||||||
.event(
|
.event(
|
||||||
new HoverEvent(
|
new HoverEvent(
|
||||||
HoverEvent.Action.SHOW_TEXT,
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,4 +5,11 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
updateAvailableNotice = Available updates (%d):
|
updateAvailableNotice = Available updates (%d):
|
||||||
pomodoroEndKick = Break time! Come back in 5 minutes.
|
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"
|
Loading…
Reference in a new issue