From df4da817b64c76139b16318b0fd647a84e66e20c Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 31 Dec 2017 01:30:13 -0700 Subject: [PATCH] Rename Utils.ActivePlayers to something better. Issues related to ICollections being null led to reverting migrating this to TSPlayer until a better solution is uncovered. --- TShockAPI/Commands.cs | 2 +- TShockAPI/GetDataHandlers.cs | 2 +- TShockAPI/StatTracker.cs | 2 +- TShockAPI/TShock.cs | 8 ++++---- TShockAPI/Utils.cs | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 4f9bf7d9..36dabc6b 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -4819,7 +4819,7 @@ namespace TShockAPI return; } - args.Player.SendSuccessMessage("Online Players ({0}/{1})", TShock.Utils.ActivePlayers(), TShock.Config.MaxSlots); + args.Player.SendSuccessMessage("Online Players ({0}/{1})", TShock.Utils.GetActivePlayerCount(), TShock.Config.MaxSlots); var players = new List(); diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 3524f733..f4cd0a9e 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1892,7 +1892,7 @@ namespace TShockAPI if (OnGetSection(args.Player, args.Data, args.Data.ReadInt32(), args.Data.ReadInt32())) return true; - if (TShock.Utils.ActivePlayers() + 1 > TShock.Config.MaxSlots && + if (TShock.Utils.GetActivePlayerCount() + 1 > TShock.Config.MaxSlots && !args.Player.HasPermission(Permissions.reservedslot)) { args.Player.Kick(TShock.Config.ServerFullReason, true, true); diff --git a/TShockAPI/StatTracker.cs b/TShockAPI/StatTracker.cs index 1151d170..807c530c 100644 --- a/TShockAPI/StatTracker.cs +++ b/TShockAPI/StatTracker.cs @@ -144,7 +144,7 @@ namespace TShockAPI return new JsonData() { port = Terraria.Netplay.ListenPort, - currentPlayers = TShock.Utils.ActivePlayers(), + currentPlayers = TShock.Utils.GetActivePlayerCount(), maxPlayers = TShock.Config.MaxSlots, systemRam = GetTotalSystemRam(ServerApi.RunningMono), version = TShock.VersionNum.ToString(), diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 56bc45a8..5a795972 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1241,7 +1241,7 @@ namespace TShockAPI var player = new TSPlayer(args.Who); - if (Utils.ActivePlayers() + 1 > Config.MaxSlots + Config.ReservedSlots) + if (Utils.GetActivePlayerCount() + 1 > Config.MaxSlots + Config.ReservedSlots) { player.Kick(Config.ServerFullNoReservedReason, true, true, null, false); args.Handled = true; @@ -1400,7 +1400,7 @@ namespace TShockAPI } // The last player will leave after this hook is executed. - if (Utils.ActivePlayers() == 1) + if (Utils.GetActivePlayerCount() == 1) { if (Config.SaveWorldOnLastPlayerExit) SaveManager.Instance.SaveWorld(); @@ -1621,7 +1621,7 @@ namespace TShockAPI if (Config.EnableGeoIP && TShock.Geo != null) { Log.Info("{0} ({1}) from '{2}' group from '{3}' joined. ({4}/{5})", player.Name, player.IP, - player.Group.Name, player.Country, TShock.Utils.ActivePlayers(), + player.Group.Name, player.Country, TShock.Utils.GetActivePlayerCount(), TShock.Config.MaxSlots); if (!player.SilentJoinInProgress) Utils.Broadcast(string.Format("{0} ({1}) has joined.", player.Name, player.Country), Color.Yellow); @@ -1629,7 +1629,7 @@ namespace TShockAPI else { Log.Info("{0} ({1}) from '{2}' group joined. ({3}/{4})", player.Name, player.IP, - player.Group.Name, TShock.Utils.ActivePlayers(), TShock.Config.MaxSlots); + player.Group.Name, TShock.Utils.GetActivePlayerCount(), TShock.Config.MaxSlots); if (!player.SilentJoinInProgress) Utils.Broadcast(player.Name + " has joined.", Color.Yellow); } diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index f3c35591..09e7d542 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -153,7 +153,7 @@ namespace TShockAPI /// Gets the number of active players on the server. /// /// The number of active players on the server. - public int ActivePlayers() + public int GetActivePlayerCount() { return Main.player.Where(p => null != p && p.active).Count(); } @@ -1117,7 +1117,7 @@ namespace TShockAPI } else { - invasionSize = 100 + (TShock.Config.InvasionMultiplier * ActivePlayers()); + invasionSize = 100 + (TShock.Config.InvasionMultiplier * GetActivePlayerCount()); } // Order matters @@ -1151,12 +1151,12 @@ namespace TShockAPI } /// Updates the console title with some pertinent information. - /// If the server is empty; determines if we should use Utils.ActivePlayers() for player count or 0. + /// If the server is empty; determines if we should use Utils.GetActivePlayerCount() for player count or 0. internal void SetConsoleTitle(bool empty) { Console.Title = string.Format("{0}{1}/{2} on {3} @ {4}:{5} (TShock for Terraria v{6})", !string.IsNullOrWhiteSpace(TShock.Config.ServerName) ? TShock.Config.ServerName + " - " : "", - empty ? 0 : ActivePlayers(), + empty ? 0 : GetActivePlayerCount(), TShock.Config.MaxSlots, Main.worldName, Netplay.ServerIP.ToString(), Netplay.ListenPort, TShock.VersionNum); }