From c541d315defe3dac143983299b24a78bda106919 Mon Sep 17 00:00:00 2001 From: OakLoaf Date: Wed, 9 Oct 2024 10:59:40 +0100 Subject: [PATCH] Added option to disable updating downloading --- .../pluginupdater/command/PluginUpdaterCommand.java | 5 ++++- .../pluginupdater/command/UpdateSubCommand.java | 5 +++++ .../lushplugins/pluginupdater/config/ConfigManager.java | 8 +++++++- src/main/resources/config.yml | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/lushplugins/pluginupdater/command/PluginUpdaterCommand.java b/src/main/java/org/lushplugins/pluginupdater/command/PluginUpdaterCommand.java index cdb6c46..fecc506 100644 --- a/src/main/java/org/lushplugins/pluginupdater/command/PluginUpdaterCommand.java +++ b/src/main/java/org/lushplugins/pluginupdater/command/PluginUpdaterCommand.java @@ -17,7 +17,10 @@ public PluginUpdaterCommand() { addSubCommand(new ReloadSubCommand()); addSubCommand(new RunChecksSubCommand()); addSubCommand(new UnregisteredPluginsSubCommand()); - addSubCommand(new UpdateSubCommand()); + + if (PluginUpdater.getInstance().getConfigManager().shouldAllowDownloads()) { + addSubCommand(new UpdateSubCommand()); + } } @Override diff --git a/src/main/java/org/lushplugins/pluginupdater/command/UpdateSubCommand.java b/src/main/java/org/lushplugins/pluginupdater/command/UpdateSubCommand.java index 0b64be3..4c0e867 100644 --- a/src/main/java/org/lushplugins/pluginupdater/command/UpdateSubCommand.java +++ b/src/main/java/org/lushplugins/pluginupdater/command/UpdateSubCommand.java @@ -29,6 +29,11 @@ public UpdateSubCommand() { @Override public boolean execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, @NotNull String[] fullArgs) { + if (!PluginUpdater.getInstance().getConfigManager().shouldAllowDownloads()) { + ChatColorHandler.sendMessage(sender, "&#ff6969Update downloads have been disabled in the config"); + return true; + } + if (args[0].equalsIgnoreCase("all")) { UpdateHandler updateHandler = PluginUpdater.getInstance().getUpdateHandler(); AtomicInteger updateCount = new AtomicInteger(0); diff --git a/src/main/java/org/lushplugins/pluginupdater/config/ConfigManager.java b/src/main/java/org/lushplugins/pluginupdater/config/ConfigManager.java index 3c3cadb..d69c8e1 100644 --- a/src/main/java/org/lushplugins/pluginupdater/config/ConfigManager.java +++ b/src/main/java/org/lushplugins/pluginupdater/config/ConfigManager.java @@ -21,6 +21,7 @@ public class ConfigManager { private boolean checkOnStartup; + private boolean allowDownloads; private final Map plugins = new TreeMap<>(); private final HashMap messages = new HashMap<>(); @@ -33,7 +34,8 @@ public void reloadConfig() { plugin.reloadConfig(); FileConfiguration config = plugin.getConfig(); - checkOnStartup = config.getBoolean("check-updates-on-start"); + checkOnStartup = config.getBoolean("check-updates-on-start", true); + allowDownloads = config.getBoolean("allow-downloads", true); Collection dataSnapshot = new ArrayList<>(plugins.values()); for (PluginData snapshot : dataSnapshot) { @@ -127,6 +129,10 @@ public boolean shouldCheckOnStartup() { return checkOnStartup; } + public boolean shouldAllowDownloads() { + return allowDownloads; + } + public Set getPlugins() { return plugins.keySet(); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c9ca483..d6fc5a4 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,7 @@ # Whether to check for updates on server startup check-updates-on-start: true +# Set to 'false' to disable all download features of PluginUpdater +allow-downloads: true # To learn how to configure plugins that are on different platforms check out the wiki: https://github.com/OakLoaf/PluginUpdater/wiki/PluginUpdater-Plugin plugins: