1 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
14 internal static readonly IDictionary<string, List<ModCommand>> Commands =
new Dictionary<string, List<ModCommand>>(StringComparer.OrdinalIgnoreCase);
18 if (Main.netMode == 2)
20 else if (Main.netMode == 0)
23 return (callerType & commandType) != 0;
27 List<ModCommand> cmdList;
28 if (!Commands.TryGetValue(cmd.
Command, out cmdList))
29 Commands.Add(cmd.
Command, cmdList =
new List<ModCommand>());
34 internal static void Unload() {
43 string modName = null;
44 if (name.Contains(
':')) {
45 var split = name.Split(
':');
52 List<ModCommand> cmdList;
53 if (!Commands.TryGetValue(name, out cmdList))
56 cmdList = cmdList.Where(c => Matches(c.Type, caller.
CommandType)).ToList();
57 if (cmdList.Count == 0)
60 if (modName != null) {
63 caller.
Reply(
"Unknown Mod: " + modName, Color.Red);
66 mc = cmdList.SingleOrDefault(c => c.mod == mod);
68 caller.
Reply(
"Mod: " + modName +
" does not have a " + name +
" command.", Color.Red);
71 else if (cmdList.Count > 1) {
72 caller.
Reply(
"Multiple definitions of command /" + name +
". Try:", Color.Red);
73 foreach (var c
in cmdList)
74 caller.
Reply(c.mod.Name +
":" + c.Command, Color.LawnGreen);
82 internal static bool HandleCommand(
string input,
CommandCaller caller) {
83 var args = input.TrimEnd().Split(
' ');
85 args = args.Skip(1).ToArray();
91 name = name.Substring(1);
95 if (!GetCommand(caller, name, out mc))
102 mc.
Action(caller, input, args);
107 caller.
Reply(ue.msg, ue.color);
109 caller.
Reply(
"Usage: " + mc.Usage, Color.Red);
115 var list =
new List<Tuple<string, string>>();
116 foreach (var entry
in Commands) {
117 var cmdList = entry.Value.Where(mc => Matches(mc.Type, type)).ToList();
118 foreach (var mc
in cmdList) {
120 if (cmdList.Count > 1)
121 cmd = mc.mod.Name +
":" + cmd;
123 list.Add(Tuple.Create(cmd, mc.Description));
CommandType
A flag enum representing context where this command operates.
abstract string Command
The desired text to trigger this command.
static bool Matches(CommandType commandType, CommandType callerType)
This serves as the central class which loads mods. It contains many static fields and methods related...
abstract void Action(CommandCaller caller, string input, string[] args)
The code that is executed when the command is triggered.
static List< Tuple< string, string > > GetHelp(CommandType type)
This serves as the central class from which ModCommand functions are supported and carried out...
Mod is an abstract class that you will override. It serves as a central place from which the mod's co...
This class represents a chat or console command. Use the CommandType to specify the scope of the comm...
static Mod GetMod(string name)
Gets the instance of the Mod with the specified name.
void Reply(string text, Color color=default(Color))
Use this to repond to the Player that invoked this command. This method handles writing to the consol...