internal static void Add(ModCommand cmd) { if (!Commands.TryGetValue(cmd.Command, out List <ModCommand> cmdList)) { Commands.Add(cmd.Command, cmdList = new List <ModCommand>()); } cmdList.Add(cmd); }
/// <summary> /// Finds a command by name. Handles mod prefixing. Replies with error messages. /// </summary> /// <param name="mc">The found command, or null if an error was encountered.</param> /// <returns>True if a ModCommand was found, or an error message was replied. False if the command is unrecognized.</returns> internal static bool GetCommand(CommandCaller caller, string name, out ModCommand mc) { string modName = null; if (name.Contains(':')) { var split = name.Split(':'); modName = split[0]; name = split[1]; } mc = null; List <ModCommand> cmdList; if (!Commands.TryGetValue(name, out cmdList)) { return(false); } cmdList = cmdList.Where(c => Matches(c.Type, caller.CommandType)).ToList(); if (cmdList.Count == 0) { return(false); } if (modName != null) { Mod mod = ModLoader.GetMod(modName); if (mod == null) { caller.Reply("Unknown Mod: " + modName, Color.Red); } else { mc = cmdList.SingleOrDefault(c => c.mod == mod); if (mc == null) { caller.Reply("Mod: " + modName + " does not have a " + name + " command.", Color.Red); } } } else if (cmdList.Count > 1) { caller.Reply("Multiple definitions of command /" + name + ". Try:", Color.Red); foreach (var c in cmdList) { caller.Reply(c.mod.Name + ":" + c.Command, Color.LawnGreen); } } else { mc = cmdList[0]; } return(true); }