Skip to content

Commit

Permalink
Added option to disable updating downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
OakLoaf committed Oct 9, 2024
1 parent 5d51a00 commit c541d31
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

public class ConfigManager {
private boolean checkOnStartup;
private boolean allowDownloads;
private final Map<String, PluginData> plugins = new TreeMap<>();
private final HashMap<String, String> messages = new HashMap<>();

Expand All @@ -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<PluginData> dataSnapshot = new ArrayList<>(plugins.values());
for (PluginData snapshot : dataSnapshot) {
Expand Down Expand Up @@ -127,6 +129,10 @@ public boolean shouldCheckOnStartup() {
return checkOnStartup;
}

public boolean shouldAllowDownloads() {
return allowDownloads;
}

public Set<String> getPlugins() {
return plugins.keySet();
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit c541d31

Please sign in to comment.