diff --git a/README.md b/README.md index 9f41633..90913bb 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,25 @@ Simply overwrite all plugin files and they will be reloaded automatically or jus ## Commands -There is currently one server-side command available for this plugin: +There is currently one server-side command available to use via the command line for this plugin: -### update_plugin +### um [check/update] [all/] -This command triggers the update process for all installed plugins. +This command triggers the update mechanism for all or one specific plugin. Examples: + +```bash +# check all plugins for updates (but do not update) +um check all + +# update all plugins (including "check all") +um update all + +# check specific plugin e.g. UpdateManager itself +um check UpdateManager + +# update specific plugin e.g. UpdateManager itself +um update UpdateManager +``` ## Configuration diff --git a/src/UpdateManager+Commands.cs b/src/UpdateManager+Commands.cs index f7578a3..fa5fd0f 100644 --- a/src/UpdateManager+Commands.cs +++ b/src/UpdateManager+Commands.cs @@ -1,19 +1,54 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; namespace UpdateManager { public partial class UpdateManager : BasePlugin { - [ConsoleCommand("update_plugins", "Updates all supported plugins")] - [CommandHelper(whoCanExecute: CommandUsage.SERVER_ONLY)] + [ConsoleCommand("um", "CS2 Update Manager")] + [RequiresPermissions("@updatemanager/admin")] + [CommandHelper(whoCanExecute: CommandUsage.SERVER_ONLY, minArgs: 2, usage: "[check/update] [all/]")] public void CommandUpdatePlugins(CCSPlayerController player, CommandInfo command) { + // arguments + var commandType = command.GetArg(1); + var pluginName = command.GetArg(2); + bool applyUpdate; + // check action + switch (commandType.ToLower()) + { + case "check": + applyUpdate = false; + break; + case "update": + applyUpdate = true; + break; + default: + command.ReplyToCommand("Invalid command. Usage: [check/update] [all/]"); + return; + } // update plugin list getPluginList(); - // check for updates - UpdateAllPlugins(true).GetAwaiter().GetResult(); + // check pluginName + if (pluginName == "all") + { + if (applyUpdate) command.ReplyToCommand(Localizer["command.update_all"]); + else command.ReplyToCommand(Localizer["command.check_all"]); + UpdateAllPlugins(applyUpdate).GetAwaiter().GetResult(); + return; + } + else if (_plugins.FirstOrDefault(x => x.Item1 == pluginName) != null) + { + if (applyUpdate) command.ReplyToCommand(Localizer["command.update"].Value.Replace("{plugin}", pluginName)); + else command.ReplyToCommand(Localizer["command.check"].Value.Replace("{plugin}", pluginName)); + UpdatePlugin(pluginName, applyUpdate).GetAwaiter().GetResult(); + } + else + { + command.ReplyToCommand(Localizer["command.plugin_not_found"].Value.Replace("{plugin}", pluginName)); + } } } } diff --git a/src/lang/de.json b/src/lang/de.json index db34d0f..a0bef96 100644 --- a/src/lang/de.json +++ b/src/lang/de.json @@ -6,5 +6,11 @@ "update.error": "[UpdateManager] Fehler beim Aktualisieren des Plugins {pluginName}: {error}", "update.available": "[UpdateManager] Neue Version verfügbar: {pluginName} v{latestVersion} (aktuell: v{pluginVersion})", "update.notfound": "[UpdateManager] {pluginName} v{pluginVersion} ist bereits die neueste Version", - "update.success": "[UpdateManager] Plugin {pluginName} aktualisiert von v{pluginVersion} auf v{latestVersion}" + "update.success": "[UpdateManager] Plugin {pluginName} aktualisiert von v{pluginVersion} auf v{latestVersion}", + "command.invalid": "[UpdateManager] Ungültiger Befehl. Verwendung: [check/update] [all/]", + "command.check_all": "[UpdateManager] Überprüfe {plugin} auf Aktualisierungen...", + "command.check": "[UpdateManager] Überprüfe {plugin} auf Aktualisierungen...", + "command.update_all": "[UpdateManager] Aktualisiere alle Plugins...", + "command.update": "[UpdateManager] Aktualisiere {plugin}...", + "command.plugin_not_found": "[UpdateManager] Plugin {plugin} nicht gefunden" } \ No newline at end of file diff --git a/src/lang/en.json b/src/lang/en.json index 1219d89..d40a6d8 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -7,5 +7,11 @@ "update.error": "[UpdateManager] Error while updating plugin {pluginName}: {error}", "update.available": "[UpdateManager] New version available: {pluginName} v{latestVersion} (current: v{pluginVersion})", "update.notfound": "[UpdateManager] {pluginName} v{pluginVersion} is already the newest version", - "update.success": "[UpdateManager] Plugin {pluginName} updated from v{pluginVersion} to v{latestVersion}" + "update.success": "[UpdateManager] Plugin {pluginName} updated from v{pluginVersion} to v{latestVersion}", + "command.invalid": "[UpdateManager] Invalid command. Usage: [check/update] [all/]", + "command.check_all": "[UpdateManager] Checking {plugin} for updates...", + "command.check": "[UpdateManager] Checking {plugin} for updates...", + "command.update_all": "[UpdateManager] Updating all plugins...", + "command.update": "[UpdateManager] Updating {plugin}...", + "command.plugin_not_found": "[UpdateManager] Plugin {plugin} not found" } \ No newline at end of file