From 1306043c00d536c3ef197bb885e3280b1c213619 Mon Sep 17 00:00:00 2001 From: Zack Piispanen Date: Thu, 26 Jan 2012 19:41:12 -0500 Subject: [PATCH] Added permission for seeing ids when using /who Also added in the ability to see ids when using /who. Good for quickly adding ids to a region. --- TShockAPI/Commands.cs | 5 ++++- TShockAPI/Permissions.cs | 5 ++++- TShockAPI/Utils.cs | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index ffea76db..ee85a62a 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -2636,7 +2636,10 @@ namespace TShockAPI private static void Playing(CommandArgs args) { - args.Player.SendMessage(string.Format("Current players: {0}.", TShock.Utils.GetPlayers()), 255, 240, 20); + string response = args.Player.Group.HasPermission(Permissions.seeids) + ? TShock.Utils.GetPlayersWithIds() + : TShock.Utils.GetPlayers(); + args.Player.SendMessage(string.Format("Current players: {0}.", response), 255, 240, 20); args.Player.SendMessage(string.Format("TShock: {0} ({1}): ({2}/{3})", TShock.VersionNum, TShock.VersionCodename, TShock.Utils.ActivePlayers(), TShock.Config.MaxSlots)); } diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index 97d6e7e4..fb79bdca 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -158,7 +158,10 @@ namespace TShockAPI [Description("User can start invasions (Goblin/Snow Legion) using items")] public static readonly string startinvasion; - static Permissions() + [Description("User can see the id of players with /who")] + public static readonly string seeids; + + static Permissions() { foreach (var field in typeof (Permissions).GetFields()) { diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 05579b95..d5c723b9 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -69,6 +69,29 @@ namespace TShockAPI return sb.ToString(); } + /// + /// Used for some places where a list of players might be used. + /// + /// String of players and their id seperated by commas. + public string GetPlayersWithIds() + { + var sb = new StringBuilder(); + foreach (TSPlayer player in TShock.Players) + { + if (player != null && player.Active) + { + if (sb.Length != 0) + { + sb.Append(", "); + } + sb.Append(player.Name); + string id = "( " + Convert.ToString(TShock.Users.GetUserID(player.UserAccountName)) + " )"; + sb.Append(id); + } + } + return sb.ToString(); + } + /// /// Finds a player and gets IP as string ///