TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ GetCommand()

static bool Terraria.ModLoader.CommandLoader.GetCommand ( CommandCaller caller,
string name,
out ModCommand mc )
inlinestaticpackage

Finds a command by name. Handles mod prefixing. Replies with error messages.

Parameters
callerHandles relaying the results of the command and narrows down the search by CommandType context
nameThe name of the command to retrieve
mcThe found command, or null if an error was encountered.
Returns
True if a ModCommand was found, or an error message was replied. False if the command is unrecognized.

Definition at line 52 of file CommandLoader.cs.

53 {
54 //IL_0114: Unknown result type (might be due to invalid IL or missing references)
55 //IL_008b: Unknown result type (might be due to invalid IL or missing references)
56 //IL_00e6: Unknown result type (might be due to invalid IL or missing references)
57 //IL_0154: Unknown result type (might be due to invalid IL or missing references)
58 string modName = null;
59 if (name.Contains(':'))
60 {
61 string[] array = name.Split(':');
62 modName = array[0];
63 name = array[1];
64 }
65 mc = null;
66 if (!Commands.TryGetValue(name, out var cmdList))
67 {
68 return false;
69 }
70 cmdList = cmdList.Where((ModCommand c) => Matches(c.Type, caller.CommandType)).ToList();
71 if (cmdList.Count == 0)
72 {
73 return false;
74 }
75 if (modName != null)
76 {
77 if (!ModLoader.TryGetMod(modName, out var mod))
78 {
79 caller.Reply("Unknown Mod: " + modName, Color.Red);
80 }
81 else
82 {
83 mc = cmdList.SingleOrDefault((ModCommand c) => c.Mod == mod);
84 if (mc == null)
85 {
86 caller.Reply("Mod: " + modName + " does not have a " + name + " command.", Color.Red);
87 }
88 }
89 }
90 else if (cmdList.Count > 1)
91 {
92 caller.Reply("Multiple definitions of command /" + name + ". Try:", Color.Red);
93 foreach (ModCommand c2 in cmdList)
94 {
95 caller.Reply(c2.Mod.Name + ":" + c2.Command, Color.LawnGreen);
96 }
97 }
98 else
99 {
100 mc = cmdList[0];
101 }
102 return true;
103 }
static bool Matches(CommandType commandType, CommandType callerType)

References Terraria.ModLoader.CommandLoader.Matches(), Terraria.ModLoader.ModType< TEntity, TModType >.Mod, Terraria.ModLoader.ModLoader.TryGetMod(), and Terraria.ModLoader.ModCommand.Type.

Referenced by Terraria.ModLoader.Default.HelpCommand.Action(), and Terraria.ModLoader.CommandLoader.HandleCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: