From 17cfdc3a16b45607804abb62dbc5946d2fe9f560 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 31 Dec 2017 01:13:03 -0700 Subject: [PATCH] Add TSPlayer.ActivePlayers --- CHANGELOG.md | 2 +- TShockAPI/TSPlayer.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9a0ab61..a9dd9d55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,7 +68,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Removed _all obsolete methods in TShock marked obsolete prior to this version (all of them)_ (@hakusaro). * Removed broken noclip detection and attempted prevention. TShock wasn't doing a good job at stopping noclip. It's always worse to claim that you do something that you can't/don't do, so removing this is better than keeping broken detection in. (@hakusaro) * Replaced `Utils.FindPlayer` with `TSPlayer.FindByNameOrID` to more appropriately be object orientated. (@hakusaro) -* Removed `Utils.ActivePlayers()` -- use `TShock.Players.Length` instead. (@hakusaro) +* Removed `Utils.ActivePlayers()` -- use `TSPlayer.ActivePlayers.Count` instead. (@hakusaro) * Moved `Utils.Kick()` to `TSPlayer` since its first argument was a `TSPlayer` object. (@hakusaro) * Removed `Utils.ForceKick()`. (@hakusaro) * Removed `Utils.GetPlayerIP()`. (@hakusaro) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index c71141e7..2b51ddd0 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -74,6 +74,18 @@ namespace TShockAPI /// public static readonly TSPlayer All = new TSPlayer("All"); + /// + /// Gets the number of active players on the server. + /// + /// The number of active players on the server. + public static ICollection ActivePlayers + { + get + { + return TShock.Players.Where(p => null != p && p.TPlayer.active) as ICollection; + } + } + /// /// Finds a TSPlayer based on name or ID ///