Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ChatCommandProcessor.cs
Go to the documentation of this file.
2using System.Linq;
6
7namespace Terraria.Chat;
8
10{
12
14
16
18
20 {
22 string commandKey = "ChatCommand." + cacheableAttribute.Name;
24 _commands[chatCommandId] = new T();
26 {
28 }
29 else
30 {
31 commandKey += "_";
32 LocalizedText[] array = Language.FindAll((string key, LocalizedText text) => key.StartsWith(commandKey));
33 foreach (LocalizedText key2 in array)
34 {
36 }
37 }
38 return this;
39 }
40
41 public void AddAlias(LocalizedText text, NetworkText result)
42 {
43 _aliases[text] = result;
44 }
45
46 public void ClearAliases()
47 {
49 }
50
52 {
54 ChatCommandId key = ChatCommandId.FromType<T>();
56 return this;
57 }
58
60 {
61 string text = message.Text.ToLower();
62 string value = command.Value;
63 if (!text.StartsWith(value))
64 {
65 return false;
66 }
67 if (text.Length == value.Length)
68 {
69 return true;
70 }
71 return text[value.Length] == ' ';
72 }
73
75 {
76 string value = command.Value;
77 if (!messageText.StartsWith(value))
78 {
79 return "";
80 }
81 if (messageText.Length == value.Length)
82 {
83 return "";
84 }
85 if (messageText[value.Length] == ' ')
86 {
87 return messageText.Substring(value.Length + 1);
88 }
89 return "";
90 }
91
93 {
94 ChatMessage message = new ChatMessage(text);
96 ChatCommandId value = keyValuePair.Value;
97 if (keyValuePair.Key != null)
98 {
99 message.SetCommand(value);
100 message.Text = RemoveCommandPrefix(message.Text, keyValuePair.Key);
101 _commands[value].ProcessOutgoingMessage(message);
102 }
103 else
104 {
105 bool flag = false;
107 while (keyValuePair2.Key != null)
108 {
109 flag = true;
110 message = new ChatMessage(keyValuePair2.Value.ToString());
112 }
113 if (flag)
114 {
115 return CreateOutgoingMessage(message.Text);
116 }
117 }
118 return message;
119 }
120
122 {
123 if (_commands.TryGetValue(message.CommandId, out var value))
124 {
125 value.ProcessIncomingMessage(message.Text, (byte)clientId);
126 message.Consume();
127 }
128 else if (_defaultCommand != null)
129 {
131 message.Consume();
132 }
133 }
134}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
readonly Dictionary< ChatCommandId, IChatCommand > _commands
ChatCommandProcessor AddDefaultCommand< T >()
static string RemoveCommandPrefix(string messageText, LocalizedText command)
void AddAlias(LocalizedText text, NetworkText result)
ChatMessage CreateOutgoingMessage(string text)
readonly Dictionary< LocalizedText, ChatCommandId > _localizedCommands
readonly Dictionary< LocalizedText, NetworkText > _aliases
static bool HasLocalizedCommand(ChatMessage message, LocalizedText command)
void ProcessIncomingMessage(ChatMessage message, int clientId)
void SetCommand(ChatCommandId commandId)
static LocalizedText[] FindAll(Regex regex)
Definition Language.cs:55
static LocalizedText GetText(string key)
Definition Language.cs:10
static bool Exists(string key)
Definition Language.cs:45
void ProcessIncomingMessage(string text, byte clientId)