Merge pull request #3039 from ACaiCat/general-devel

fix: /help, /me, and /p commands can't work in non-English languages
This commit is contained in:
Lucas Nicodemus 2025-01-26 09:44:08 +09:00 committed by GitHub
commit 92c3f0086d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 3 deletions

View file

@ -20,7 +20,9 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.Initializers;
using Terraria.Localization;
using Terraria.UI.Chat;
namespace TShockAPI.Localization
{
@ -37,6 +39,8 @@ namespace TShockAPI.Localization
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;
@ -71,6 +75,15 @@ namespace TShockAPI.Localization
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
{
@ -136,5 +149,18 @@ namespace TShockAPI.Localization
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;
}
}
}

View file

@ -1505,11 +1505,11 @@ namespace TShockAPI
{
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;
}

View file

@ -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)
@ -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)