Example #1
0
        /// <summary>The method called when the user submits a core SMAPI command in the console.</summary>
        /// <param name="name">The command name.</param>
        /// <param name="arguments">The command arguments.</param>
        private void HandleCommand(string name, string[] arguments)
        {
            switch (name)
            {
            case "help":
                if (arguments.Any())
                {
                    Framework.Command result = this.CommandManager.Get(arguments[0]);
                    if (result == null)
                    {
                        this.Monitor.Log("There's no command with that name.", LogLevel.Error);
                    }
                    else
                    {
                        this.Monitor.Log($"{result.Name}: {result.Documentation}\n(Added by {result.ModName}.)", LogLevel.Info);
                    }
                }
                else
                {
#if SMAPI_1_x
                    this.Monitor.Log("The following commands are registered: " + string.Join(", ", this.CommandManager.GetAll().Select(p => p.Name)) + ".", LogLevel.Info);
                    this.Monitor.Log("For more information about a command, type 'help command_name'.", LogLevel.Info);
#else
                    string message = "The following commands are registered:\n";
                    IGrouping <string, string>[] groups = (from command in this.CommandManager.GetAll() orderby command.ModName, command.Name group command.Name by command.ModName).ToArray();
                    foreach (var group in groups)
                    {
                        string   modName      = group.Key;
                        string[] commandNames = group.ToArray();
                        message += $"{modName}:\n  {string.Join("\n  ", commandNames)}\n\n";
                    }
                    message += "For more information about a command, type 'help command_name'.";

                    this.Monitor.Log(message, LogLevel.Info);
#endif
                }
                break;

            case "reload_i18n":
                this.ReloadTranslations();
                this.Monitor.Log("Reloaded translation files for all mods. This only affects new translations the mods fetch; if they cached some text, it may not be updated.", LogLevel.Info);
                break;

            default:
                throw new NotSupportedException($"Unrecognise core SMAPI command '{name}'.");
            }
        }
Example #2
0
 /// <summary>The method called when the user submits the help command in the console.</summary>
 /// <param name="name">The command name.</param>
 /// <param name="arguments">The command arguments.</param>
 private void HandleHelpCommand(string name, string[] arguments)
 {
     if (arguments.Any())
     {
         Framework.Command result = this.CommandManager.Get(arguments[0]);
         if (result == null)
         {
             this.Monitor.Log("There's no command with that name.", LogLevel.Error);
         }
         else
         {
             this.Monitor.Log($"{result.Name}: {result.Documentation}\n(Added by {result.ModName}.)", LogLevel.Info);
         }
     }
     else
     {
         this.Monitor.Log("The following commands are registered: " + string.Join(", ", this.CommandManager.GetAll().Select(p => p.Name)) + ".", LogLevel.Info);
         this.Monitor.Log("For more information about a command, type 'help command_name'.", LogLevel.Info);
     }
 }