Set different verbosity levels for the update messages

This commit is contained in:
Telesphoreo 2022-04-08 00:01:02 -05:00
parent 294f8db528
commit 898dace3c1
3 changed files with 17 additions and 11 deletions

View File

@ -38,7 +38,7 @@ public class PlexCMD extends PlexCommand
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
send(sender, mmString("<light_purple>Built by: <gold>" + Plex.build.author + " <light_purple>on <gold>" + Plex.build.date));
send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
plugin.getUpdateChecker().getUpdateStatusMessage(sender, true, true);
plugin.getUpdateChecker().getUpdateStatusMessage(sender, true, 2);
return null;
}
if (args[0].equalsIgnoreCase("reload"))
@ -95,7 +95,7 @@ public class PlexCMD extends PlexCommand
{
return messageComponent("noPermissionRank", "a developer");
}
if (!plugin.getUpdateChecker().getUpdateStatusMessage(sender, false, false))
if (!plugin.getUpdateChecker().getUpdateStatusMessage(sender, false, 0))
{
return mmString("<red>Plex is already up to date!");
}

View File

@ -17,7 +17,7 @@ public class UpdateCheckerService extends AbstractService
{
if (!newVersion)
{
if (plugin.getUpdateChecker().getUpdateStatusMessage(Bukkit.getConsoleSender(), false, false))
if (plugin.getUpdateChecker().getUpdateStatusMessage(Bukkit.getConsoleSender(), false, 1))
{
newVersion = true;
}

View File

@ -82,7 +82,10 @@ public class UpdateChecker extends PlexBase
}
}
public boolean getUpdateStatusMessage(CommandSender sender, boolean cached, boolean verbose)
// If verbose is 0, it will display nothing
// If verbose is 1, it will only display a message if there is an update available
// If verbose is 2, it will display all messages
public boolean getUpdateStatusMessage(CommandSender sender, boolean cached, int verbosity)
{
if (branch == null)
{
@ -112,30 +115,33 @@ public class UpdateChecker extends PlexBase
switch (distance)
{
case -1 -> {
if (verbose)
if (verbosity == 2)
{
sender.sendMessage(Component.text("There was an error checking for updates.").color(NamedTextColor.RED));
}
return false;
}
case 0 -> {
if (verbose)
if (verbosity == 2)
{
sender.sendMessage(Component.text("Your version of Plex is up to date!").color(NamedTextColor.GREEN));
sender.sendMessage(Component.text("Plex is up to date!").color(NamedTextColor.GREEN));
}
return false;
}
case -2 -> {
if (verbose)
if (verbosity == 2)
{
sender.sendMessage(Component.text("Unknown version, unable to check for updates.").color(NamedTextColor.RED));
}
return false;
}
default -> {
sender.sendMessage(Component.text("Your version of Plex is not up to date!", NamedTextColor.RED));
sender.sendMessage(Component.text("Download a new version at: " + DOWNLOAD_PAGE).color(NamedTextColor.RED));
sender.sendMessage(Component.text("Or run: /plex update").color(NamedTextColor.RED));
if (verbosity >= 1)
{
sender.sendMessage(Component.text("Plex is not up to date!", NamedTextColor.RED));
sender.sendMessage(Component.text("Download a new version at: " + DOWNLOAD_PAGE).color(NamedTextColor.RED));
sender.sendMessage(Component.text("Or run: /plex update").color(NamedTextColor.RED));
}
return true;
}
}