From 3ad99d0fcdc2945d32ee4690d00cabac42c327d6 Mon Sep 17 00:00:00 2001 From: Deathmax Date: Fri, 1 Jul 2011 20:41:53 +0800 Subject: [PATCH 1/4] Added /whisper (/tell) --- TShockAPI/Commands.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index e53473d4..999a8852 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -144,6 +144,8 @@ namespace TShockAPI ChatCommands.Add(new Command("p", "", PartyChat)); ChatCommands.Add(new Command("rules", "", Rules)); ChatCommands.Add(new Command("displaylogs", "logs", Rules)); + ChatCommands.Add(new Command("whisper", "whisper", Whisper)); + ChatCommands.Add(new Command("tell", "whisper", Whisper)); if (ConfigurationManager.DistributationAgent != "terraria-online") { ChatCommands.Add(new Command("kill", "kill", Kill)); @@ -1305,6 +1307,30 @@ namespace TShockAPI Tools.ShowFileToUser(args.Player, "rules.txt"); } + private static void Whisper(CommandArgs args) + { + if (args.Parameters.Count < 2) + { + args.Player.SendMessage("Invalid syntax! Proper syntax: /whisper ", Color.Red); + return; + } + + var players = Tools.FindPlayer(args.Parameters[0]); + if (players.Count == 0) + { + args.Player.SendMessage("Invalid player!", Color.Red); + } + else if (players.Count > 1) + { + args.Player.SendMessage("More than one player matched!", Color.Red); + } + else + { + var plr = players[0]; + plr.SendMessage("(Whisper From)" + "<" + args.Player.Name + ">" + args.Parameters[1], Color.MediumPurple); + args.Player.SendMessage("(Whisper To)" + "<" + plr.Name + ">" + args.Parameters[1], Color.MediumPurple); + } + } #endregion General Commands #region Cheat Commands From c7a4a00fa8b68bc4e3107b50372738068d062e80 Mon Sep 17 00:00:00 2001 From: Deathmax Date: Fri, 1 Jul 2011 20:53:15 +0800 Subject: [PATCH 2/4] /whisper now combines all arguments after player name --- TShockAPI/Commands.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 999a8852..88dcda7b 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1327,8 +1327,12 @@ namespace TShockAPI else { var plr = players[0]; - plr.SendMessage("(Whisper From)" + "<" + args.Player.Name + ">" + args.Parameters[1], Color.MediumPurple); - args.Player.SendMessage("(Whisper To)" + "<" + plr.Name + ">" + args.Parameters[1], Color.MediumPurple); + var msg = ""; + for (int i = 2; i < args.Parameters.Count; i++ ) + msg += args.Parameters[i] + " "; + msg = msg.TrimEnd(new char[] { ' ' }); + plr.SendMessage("(Whisper From)" + "<" + args.Player.Name + ">" + msg, Color.MediumPurple); + args.Player.SendMessage("(Whisper To)" + "<" + plr.Name + ">" + msg, Color.MediumPurple); } } #endregion General Commands From b4b54317d7727d27218fcc209c3065ea4dd639af Mon Sep 17 00:00:00 2001 From: Deathmax Date: Fri, 1 Jul 2011 20:53:59 +0800 Subject: [PATCH 3/4] /w is now an alias for /whisper --- TShockAPI/Commands.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 88dcda7b..ae093d78 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -145,6 +145,7 @@ namespace TShockAPI ChatCommands.Add(new Command("rules", "", Rules)); ChatCommands.Add(new Command("displaylogs", "logs", Rules)); ChatCommands.Add(new Command("whisper", "whisper", Whisper)); + ChatCommands.Add(new Command("w", "whisper", Whisper)); ChatCommands.Add(new Command("tell", "whisper", Whisper)); if (ConfigurationManager.DistributationAgent != "terraria-online") { From 7cc56a1b5a12cc402a4aacf0e6ac0eff1876998e Mon Sep 17 00:00:00 2001 From: Deathmax Date: Fri, 1 Jul 2011 21:13:17 +0800 Subject: [PATCH 4/4] Added /reply (/r) - Sends a whisper to the last person who whispered to you /whisper now uses string.Join --- TShockAPI/Commands.cs | 20 ++++++++++++++++---- TShockAPI/TSPlayer.cs | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index ae093d78..388302ff 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -147,6 +147,8 @@ namespace TShockAPI ChatCommands.Add(new Command("whisper", "whisper", Whisper)); ChatCommands.Add(new Command("w", "whisper", Whisper)); ChatCommands.Add(new Command("tell", "whisper", Whisper)); + ChatCommands.Add(new Command("r", "whisper", Reply)); + ChatCommands.Add(new Command("reply", "whisper", Reply)); if (ConfigurationManager.DistributationAgent != "terraria-online") { ChatCommands.Add(new Command("kill", "kill", Kill)); @@ -1328,14 +1330,24 @@ namespace TShockAPI else { var plr = players[0]; - var msg = ""; - for (int i = 2; i < args.Parameters.Count; i++ ) - msg += args.Parameters[i] + " "; - msg = msg.TrimEnd(new char[] { ' ' }); + var msg = string.Join(" ", args.Parameters, 1, args.Parameters.Count - 1); plr.SendMessage("(Whisper From)" + "<" + args.Player.Name + ">" + msg, Color.MediumPurple); args.Player.SendMessage("(Whisper To)" + "<" + plr.Name + ">" + msg, Color.MediumPurple); + plr.LastWhisper = args.Player; } } + + private static void Reply(CommandArgs args) + { + if (args.Player.LastWhisper != null) + { + var msg = string.Join(" ", args.Parameters); + args.Player.LastWhisper.SendMessage("(Whisper From)" + "<" + args.Player.Name + ">" + msg, Color.MediumPurple); + args.Player.SendMessage("(Whisper To)" + "<" + args.Player.LastWhisper.Name + ">" + msg, Color.MediumPurple); + } + else + args.Player.SendMessage("You haven't previously received any whispers. Please use /whisper to whisper to other people.", Color.Red); + } #endregion General Commands #region Cheat Commands diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index c25eca69..a410490f 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -40,6 +40,7 @@ namespace TShockAPI public bool InitSpawn = false; public bool DisplayLogs = true; public Vector2 oldSpawn = Vector2.Zero; + public TSPlayer LastWhisper; public bool RealPlayer {