Removed colour parsing from the ShowFileToUser method.
Also added an info log message if a file contains the old format. Fixes #1314
This commit is contained in:
parent
78a4185152
commit
09bbf8abe8
1 changed files with 11 additions and 15 deletions
|
|
@ -50,6 +50,8 @@ namespace TShockAPI
|
||||||
/// <summary>instance - an instance of the utils class</summary>
|
/// <summary>instance - an instance of the utils class</summary>
|
||||||
private static readonly Utils instance = new Utils();
|
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>Utils - Creates a utilities object.</summary>
|
/// <summary>Utils - Creates a utilities object.</summary>
|
||||||
private Utils() {}
|
private Utils() {}
|
||||||
|
|
||||||
|
|
@ -691,11 +693,12 @@ namespace TShockAPI
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Shows a file to the user.
|
/// Shows a file to the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="player">TSPlayer player</param>
|
/// <param name="player">Player the file contents will be sent to</param>
|
||||||
/// <param name="file">string filename reletave to savedir</param>
|
/// <param name="file">Filename relative to <see cref="TShock.SavePath"></see></param>
|
||||||
public void ShowFileToUser(TSPlayer player, string file)
|
public void ShowFileToUser(TSPlayer player, string file)
|
||||||
{
|
{
|
||||||
string foo = "";
|
string foo = "";
|
||||||
|
bool containsOldFormat = false;
|
||||||
using (var tr = new StreamReader(Path.Combine(TShock.SavePath, file)))
|
using (var tr = new StreamReader(Path.Combine(TShock.SavePath, file)))
|
||||||
{
|
{
|
||||||
while ((foo = tr.ReadLine()) != null)
|
while ((foo = tr.ReadLine()) != null)
|
||||||
|
|
@ -707,21 +710,14 @@ namespace TShockAPI
|
||||||
|
|
||||||
foo = foo.Replace("%map%", (TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName));
|
foo = foo.Replace("%map%", (TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName));
|
||||||
foo = foo.Replace("%players%", String.Join(",", GetPlayers(false)));
|
foo = foo.Replace("%players%", String.Join(",", GetPlayers(false)));
|
||||||
Regex reg = new Regex("%\\s*(?<r>\\d{1,3})\\s*,\\s*(?<g>\\d{1,3})\\s*,\\s*(?<b>\\d{1,3})\\s*%");
|
if (byteRegex.IsMatch(foo) && !containsOldFormat)
|
||||||
var matches = reg.Matches(foo);
|
|
||||||
Color c = Color.White;
|
|
||||||
foreach (Match match in matches)
|
|
||||||
{
|
{
|
||||||
byte r, g, b;
|
TShock.Log.ConsoleInfo($"You are using an old color format in file {file}.");
|
||||||
if (byte.TryParse(match.Groups["r"].Value, out r) &&
|
TShock.Log.ConsoleInfo("To send coloured text please use Terraria's inbuilt format of: [c/#hex:text].");
|
||||||
byte.TryParse(match.Groups["g"].Value, out g) &&
|
TShock.Log.ConsoleInfo("For example: [c/ff00aa:This is a message!].");
|
||||||
byte.TryParse(match.Groups["b"].Value, out b))
|
containsOldFormat = true;
|
||||||
{
|
|
||||||
c = new Color(r, g, b);
|
|
||||||
}
|
|
||||||
foo = foo.Remove(match.Index, match.Length);
|
|
||||||
}
|
}
|
||||||
player.SendMessage(foo, c);
|
player.SendMessage(foo, Color.White);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue