From eaa40e70134d4b54157033e93a1f8e662782761e Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Wed, 6 Apr 2022 23:49:45 -0500 Subject: [PATCH] Attempt to fix updater --- .../java/dev/plex/command/impl/PlexCMD.java | 8 +-- .../dev/plex/services/ServiceManager.java | 6 +- .../services/impl/UpdateCheckerService.java | 2 +- .../java/dev/plex/util/UpdateChecker.java | 55 +++++-------------- 4 files changed, 22 insertions(+), 49 deletions(-) diff --git a/src/main/java/dev/plex/command/impl/PlexCMD.java b/src/main/java/dev/plex/command/impl/PlexCMD.java index ee3dcb9..957bd4d 100644 --- a/src/main/java/dev/plex/command/impl/PlexCMD.java +++ b/src/main/java/dev/plex/command/impl/PlexCMD.java @@ -40,7 +40,7 @@ public class PlexCMD extends PlexCommand send(sender, mmString("Authors: Telesphoreo, Taahh")); send(sender, mmString("Built by: " + Plex.build.author + " on " + Plex.build.date)); send(sender, mmString("Run /plex modules to see a list of modules.")); - plugin.getUpdateChecker().getUpdateStatusMessage(sender, true); + plugin.getUpdateChecker().getUpdateStatusMessage(sender, true, true); return null; } if (args[0].equalsIgnoreCase("reload")) @@ -88,7 +88,7 @@ public class PlexCMD extends PlexCommand plugin.getModuleManager().loadAllModules(); plugin.getModuleManager().loadModules(); plugin.getModuleManager().enableModules(); - return componentFromString("All modules reloaded!"); + return mmString("All modules reloaded!"); } } else if (args[0].equalsIgnoreCase("update")) @@ -97,9 +97,9 @@ public class PlexCMD extends PlexCommand { return messageComponent("noPermissionConsole"); } - if (!plugin.getUpdateChecker().getUpdateStatus(false)) + if (!plugin.getUpdateChecker().getUpdateStatusMessage(sender, false, false)) { - return MiniMessage.miniMessage().deserialize("Plex is already up to date!"); + return mmString("Plex is already up to date!"); } plugin.getUpdateChecker().updateJar(); return null; diff --git a/src/main/java/dev/plex/services/ServiceManager.java b/src/main/java/dev/plex/services/ServiceManager.java index 0faf424..10e9b83 100644 --- a/src/main/java/dev/plex/services/ServiceManager.java +++ b/src/main/java/dev/plex/services/ServiceManager.java @@ -47,11 +47,13 @@ public class ServiceManager { BukkitTask task = Bukkit.getScheduler().runTask(Plex.get(), service::run); 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()); 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()); service.setTaskId(task.getTaskId()); diff --git a/src/main/java/dev/plex/services/impl/UpdateCheckerService.java b/src/main/java/dev/plex/services/impl/UpdateCheckerService.java index 89662bd..494a801 100644 --- a/src/main/java/dev/plex/services/impl/UpdateCheckerService.java +++ b/src/main/java/dev/plex/services/impl/UpdateCheckerService.java @@ -17,7 +17,7 @@ public class UpdateCheckerService extends AbstractService { if (!newVersion) { - if (plugin.getUpdateChecker().getUpdateStatusMessage(Bukkit.getConsoleSender(), false)) + if (plugin.getUpdateChecker().getUpdateStatusMessage(Bukkit.getConsoleSender(), false, false)) { newVersion = true; } diff --git a/src/main/java/dev/plex/util/UpdateChecker.java b/src/main/java/dev/plex/util/UpdateChecker.java index a846f13..bafc58c 100644 --- a/src/main/java/dev/plex/util/UpdateChecker.java +++ b/src/main/java/dev/plex/util/UpdateChecker.java @@ -80,45 +80,7 @@ public class UpdateChecker extends PlexBase } } - public boolean getUpdateStatus(boolean cached) - { - 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) + public boolean getUpdateStatusMessage(CommandSender sender, boolean cached, boolean verbose) { // If it's -4, it hasn't checked for updates yet if (distance == -4) @@ -143,15 +105,24 @@ public class UpdateChecker extends PlexBase switch (distance) { case -1 -> { - sender.sendMessage(Component.text("There was an error checking for updates.").color(NamedTextColor.RED)); + if (verbose) + { + sender.sendMessage(Component.text("There was an error checking for updates.").color(NamedTextColor.RED)); + } return false; } case 0 -> { - sender.sendMessage(Component.text("Your version of Plex is up to date!").color(NamedTextColor.GREEN)); + if (verbose) + { + sender.sendMessage(Component.text("Your version of Plex is up to date!").color(NamedTextColor.GREEN)); + } return false; } case -2 -> { - sender.sendMessage(Component.text("Unknown version, unable to check for updates.").color(NamedTextColor.RED)); + if (verbose) + { + sender.sendMessage(Component.text("Unknown version, unable to check for updates.").color(NamedTextColor.RED)); + } return false; } default -> {