Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: /help, /me, and /p commands can't work in non-English languages #3039

Merged
merged 9 commits into from
Jan 26, 2025
26 changes: 26 additions & 0 deletions TShockAPI/Localization/EnglishLanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ You should have received a copy of the GNU General Public License
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.Initializers;
using Terraria.Localization;
using Terraria.UI.Chat;

namespace TShockAPI.Localization
{
Expand All @@ -37,6 +39,8 @@ public static class EnglishLanguage

private static readonly Dictionary<int, string> Buffs = new Dictionary<int, string>();

private static readonly Dictionary<string,string> VanillaCommandsPrefixs = new Dictionary<string, string>();

internal static void Initialize()
{
var culture = Language.ActiveCulture;
Expand Down Expand Up @@ -71,6 +75,15 @@ internal static void Initialize()
var i = (int)field.GetValue(null);
Prefixs.Add(i, Lang.prefix[i].Value);
}

ChatInitializer.Load();
foreach (var command in ChatManager.Commands._localizedCommands)
{
if (VanillaCommandsPrefixs.ContainsKey(command.Value._name))
continue;
VanillaCommandsPrefixs.Add(command.Value._name,command.Key.Value);
}
ChatManager.Commands._localizedCommands.Clear();
}
finally
{
Expand Down Expand Up @@ -136,5 +149,18 @@ public static string GetBuffNameById(int id)

return null;
}

/// <summary>
/// Get vanilla command prefix in English
/// </summary>
/// <param name="name">vanilla command name</param>
/// <returns>vanilla command prefix in English</returns>
public static string GetCommandPrefixByName(string name)
{
string commandText;
if (VanillaCommandsPrefixs.TryGetValue(name, out commandText))
return commandText;
return null;
}
}
}
4 changes: 2 additions & 2 deletions TShockAPI/TShock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,11 +1505,11 @@ private void OnChat(ServerChatEventArgs args)
{
if (!String.IsNullOrEmpty(text))
{
text = item.Key.Value + ' ' + text;
text = EnglishLanguage.GetCommandPrefixByName(item.Value._name) + ' ' + text;
}
else
{
text = item.Key.Value;
text = EnglishLanguage.GetCommandPrefixByName(item.Value._name);
}
break;
}
Expand Down
5 changes: 4 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Use past tense when adding new entries; sign your name off when you add or chang
* In the constructor `stack` and `prefix` are now optional parameters.
* Fixed unable to transfer long response body for REST API. (@sgkoishi, #2925)
* Fixed the `/wind` command not being very helpful. (@punchready)
* Fixed /help, /me, and /p commands can't work in non-English languages. (@ACaiCat)

## TShock 5.2.1
* Updated `TSPlayer.GodMode`. (@AgaSpace)
Expand All @@ -102,7 +103,9 @@ Use past tense when adding new entries; sign your name off when you add or chang
* Added a property `TSPlayer.Hostile`, which gets pvp player mode. (@AgaSpace)
* Fixed bug where when the `UseSqlLogs` config property is true, an empty log file would still get created. (@ZakFahey)
* Fixed typo in `/gbuff`. (@sgkoishi, #2955)

* Rewrote the `.dockerignore` file into a denylist. (@timschumi)
* Added CI for Docker images. (@timschumi)
* Fixed Cursed Flares kicking players for invalid buff. (@Arthri)

## TShock 5.2
* An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK)
Expand Down
Loading