From 1f3a09d738b7923cae9621b515812f6538d7b81f Mon Sep 17 00:00:00 2001 From: White Date: Sat, 22 Apr 2017 18:24:02 +0930 Subject: [PATCH] Better workaround for Terraria chat commands, courtesy of @DeathCradle --- TShockAPI/TShock.cs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 4342473a..165b0e3e 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1443,13 +1443,25 @@ namespace TShockAPI string text = args.Text; - //This is a hacky way of bypassing Terraria's new chat command processing. - //_name is usually a private variable but the wonders of OTAPI make it available to us - if (args.CommandId._name == "Emote") + // Terraria now has chat commands on the client side. + // These commands remove the commands prefix (e.g. /me /playing) and send the command id instead + // In order for us to keep legacy code we must reverse this and get the prefix using the command id + foreach (var item in Terraria.UI.Chat.ChatManager.Commands._localizedCommands) { - text = "/me " + text; + if (item.Value._name == args.CommandId._name) + { + if (!String.IsNullOrEmpty(text)) + { + text = item.Key.Value + ' ' + text; + } + else + { + text = item.Key.Value; + } + break; + } } - + if ((text.StartsWith(Config.CommandSpecifier) || text.StartsWith(Config.CommandSilentSpecifier)) && !string.IsNullOrWhiteSpace(text.Substring(1))) {