ShowFileToUser shouldn't assume the file is in the TShock folder. Use the file path variables where we can. Use smart text instead of removing color parsing.
This commit is contained in:
parent
998bf71b96
commit
31794b6a27
2 changed files with 32 additions and 9 deletions
|
|
@ -4811,7 +4811,7 @@ namespace TShockAPI
|
|||
|
||||
private static void Rules(CommandArgs args)
|
||||
{
|
||||
TShock.Utils.ShowFileToUser(args.Player, "rules.txt");
|
||||
TShock.Utils.ShowFileToUser(args.Player, FileTools.RulesPath);
|
||||
}
|
||||
|
||||
private static void Whisper(CommandArgs args)
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ namespace TShockAPI
|
|||
/// <summary>instance - an instance of the utils class</summary>
|
||||
private static readonly Utils instance = new Utils();
|
||||
|
||||
private Regex byteRegex = new Regex("%\\s*(?<r>\\d{1,3})\\s*,\\s*(?<g>\\d{1,3})\\s*,\\s*(?<b>\\d{1,3})\\s*%");
|
||||
/// <summary> This regex will look for the old MotD format for colors and replace them with the new chat format. </summary>
|
||||
private Regex motdColorRegex = new Regex(@"\%\s*(?<r>\d{1,3})\s*,\s*(?<g>\d{1,3})\s*,\s*(?<b>\d{1,3})\s*\%(?<text>((?!\%\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\%).)*)");
|
||||
|
||||
/// <summary>Utils - Creates a utilities object.</summary>
|
||||
private Utils() {}
|
||||
|
|
@ -699,7 +700,7 @@ namespace TShockAPI
|
|||
{
|
||||
string foo = "";
|
||||
bool containsOldFormat = false;
|
||||
using (var tr = new StreamReader(Path.Combine(TShock.SavePath, file)))
|
||||
using (var tr = new StreamReader(file))
|
||||
{
|
||||
while ((foo = tr.ReadLine()) != null)
|
||||
{
|
||||
|
|
@ -710,18 +711,40 @@ namespace TShockAPI
|
|||
|
||||
foo = foo.Replace("%map%", (TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName));
|
||||
foo = foo.Replace("%players%", String.Join(",", GetPlayers(false)));
|
||||
if (byteRegex.IsMatch(foo) && !containsOldFormat)
|
||||
|
||||
string newFoo = ReplaceDeprecatedColorCodes(foo);
|
||||
if (newFoo != foo && !containsOldFormat)
|
||||
{
|
||||
TShock.Log.ConsoleInfo($"You are using an old color format in file {file}.");
|
||||
TShock.Log.ConsoleInfo("To send coloured text please use Terraria's inbuilt format of: [c/#hex:text].");
|
||||
TShock.Log.ConsoleInfo("For example: [c/ff00aa:This is a message!].");
|
||||
containsOldFormat = true;
|
||||
}
|
||||
foo = newFoo;
|
||||
|
||||
player.SendMessage(foo, Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string with deprecated %###,###,###% formats replaced with the new chat format colors.
|
||||
/// </summary>
|
||||
/// <param name="input">The input string</param>
|
||||
/// <returns>A replaced version of the input with the new chat color format.</returns>
|
||||
private string ReplaceDeprecatedColorCodes(string input)
|
||||
{
|
||||
String tempString = input;
|
||||
Match match = null;
|
||||
|
||||
while ((match = motdColorRegex.Match(tempString)).Success)
|
||||
{
|
||||
tempString = tempString.Replace(match.Groups[0].Value, String.Format("[c/{0:X2}{1:X2}{2:X2}:{3}]", Int32.Parse(match.Groups["r"].Value), Int32.Parse(match.Groups["g"].Value), Int32.Parse(match.Groups["b"].Value), match.Groups["text"]));
|
||||
}
|
||||
|
||||
return tempString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a Group from the name of the group
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue