Attempt to fix updater

This commit is contained in:
Telesphoreo 2022-04-06 23:49:45 -05:00
parent ca18b12164
commit eaa40e7013
4 changed files with 22 additions and 49 deletions

View File

@ -40,7 +40,7 @@ public class PlexCMD extends PlexCommand
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh")); 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>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.")); send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
plugin.getUpdateChecker().getUpdateStatusMessage(sender, true); plugin.getUpdateChecker().getUpdateStatusMessage(sender, true, true);
return null; return null;
} }
if (args[0].equalsIgnoreCase("reload")) if (args[0].equalsIgnoreCase("reload"))
@ -88,7 +88,7 @@ public class PlexCMD extends PlexCommand
plugin.getModuleManager().loadAllModules(); plugin.getModuleManager().loadAllModules();
plugin.getModuleManager().loadModules(); plugin.getModuleManager().loadModules();
plugin.getModuleManager().enableModules(); plugin.getModuleManager().enableModules();
return componentFromString("All modules reloaded!"); return mmString("<green>All modules reloaded!");
} }
} }
else if (args[0].equalsIgnoreCase("update")) else if (args[0].equalsIgnoreCase("update"))
@ -97,9 +97,9 @@ public class PlexCMD extends PlexCommand
{ {
return messageComponent("noPermissionConsole"); return messageComponent("noPermissionConsole");
} }
if (!plugin.getUpdateChecker().getUpdateStatus(false)) if (!plugin.getUpdateChecker().getUpdateStatusMessage(sender, false, false))
{ {
return MiniMessage.miniMessage().deserialize("<red>Plex is already up to date!"); return mmString("<red>Plex is already up to date!");
} }
plugin.getUpdateChecker().updateJar(); plugin.getUpdateChecker().updateJar();
return null; return null;

View File

@ -47,11 +47,13 @@ public class ServiceManager
{ {
BukkitTask task = Bukkit.getScheduler().runTask(Plex.get(), service::run); BukkitTask task = Bukkit.getScheduler().runTask(Plex.get(), service::run);
service.setTaskId(task.getTaskId()); service.setTaskId(task.getTaskId());
} else if (service.isRepeating() && service.isAsynchronous()) }
else if (service.isRepeating() && service.isAsynchronous())
{ {
BukkitTask task = Bukkit.getScheduler().runTaskTimerAsynchronously(Plex.get(), service::run, 0, 20L * service.repeatInSeconds()); BukkitTask task = Bukkit.getScheduler().runTaskTimerAsynchronously(Plex.get(), service::run, 0, 20L * service.repeatInSeconds());
service.setTaskId(task.getTaskId()); service.setTaskId(task.getTaskId());
} else if (service.isRepeating() && !service.isAsynchronous()) }
else if (service.isRepeating() && !service.isAsynchronous())
{ {
BukkitTask task = Bukkit.getScheduler().runTaskTimer(Plex.get(), service::run, 0, 20L * service.repeatInSeconds()); BukkitTask task = Bukkit.getScheduler().runTaskTimer(Plex.get(), service::run, 0, 20L * service.repeatInSeconds());
service.setTaskId(task.getTaskId()); service.setTaskId(task.getTaskId());

View File

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

View File

@ -80,45 +80,7 @@ public class UpdateChecker extends PlexBase
} }
} }
public boolean getUpdateStatus(boolean cached) public boolean getUpdateStatusMessage(CommandSender sender, boolean cached, boolean verbose)
{
if (distance == -4)
{
distance = fetchDistanceFromGitHub("plexusorg/Plex", "master", Plex.build.head);
PlexLog.debug("Never checked for updates, checking now...");
}
else
{
// If the request isn't asked to be cached, fetch it
if (!cached)
{
distance = fetchDistanceFromGitHub("plexusorg/Plex", "master", Plex.build.head);
PlexLog.debug("We have checked for updates before, but this request was not asked to be cached.");
}
else
{
PlexLog.debug("We have checked for updates before, using cache.");
}
}
switch (distance)
{
case -1 -> {
return false;
}
case 0 -> {
return false;
}
case -2 -> {
return false;
}
default -> {
return true;
}
}
}
public boolean getUpdateStatusMessage(CommandSender sender, boolean cached)
{ {
// If it's -4, it hasn't checked for updates yet // If it's -4, it hasn't checked for updates yet
if (distance == -4) if (distance == -4)
@ -143,15 +105,24 @@ public class UpdateChecker extends PlexBase
switch (distance) switch (distance)
{ {
case -1 -> { case -1 -> {
if (verbose)
{
sender.sendMessage(Component.text("There was an error checking for updates.").color(NamedTextColor.RED)); sender.sendMessage(Component.text("There was an error checking for updates.").color(NamedTextColor.RED));
}
return false; return false;
} }
case 0 -> { case 0 -> {
if (verbose)
{
sender.sendMessage(Component.text("Your version of Plex is up to date!").color(NamedTextColor.GREEN)); sender.sendMessage(Component.text("Your version of Plex is up to date!").color(NamedTextColor.GREEN));
}
return false; return false;
} }
case -2 -> { case -2 -> {
if (verbose)
{
sender.sendMessage(Component.text("Unknown version, unable to check for updates.").color(NamedTextColor.RED)); sender.sendMessage(Component.text("Unknown version, unable to check for updates.").color(NamedTextColor.RED));
}
return false; return false;
} }
default -> { default -> {