Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use same TSPlayer.Active check #2939

Open
wants to merge 3 commits into
base: general-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions TShockAPI/Bouncer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@ void Reject(bool shouldResync = true)
return;
}

if (TShock.Players[id] == null)
if (TShock.Players[id] == null || !TShock.Players[id].Active)
{
TShock.Log.ConsoleDebug(GetString(
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: target is null", args.Player.Name,
Expand Down Expand Up @@ -2081,7 +2081,7 @@ internal void OnHealOtherPlayer(object sender, GetDataHandlers.HealOtherPlayerEv
short amount = args.Amount;
byte plr = args.TargetPlayerIndex;

if (amount <= 0 || Main.player[plr] == null || !Main.player[plr].active)
if (amount <= 0 || TShock.Players[plr] == null || !TShock.Players[plr].Active)
{
TShock.Log.ConsoleDebug(GetString("Bouncer / OnHealOtherPlayer rejected null checks"));
args.Handled = true;
Expand Down Expand Up @@ -2589,7 +2589,7 @@ internal void OnPlayerDamage(object sender, GetDataHandlers.PlayerDamageEventArg
byte direction = args.Direction;
PlayerDeathReason reason = args.PlayerDeathReason;

if (id >= Main.maxPlayers || TShock.Players[id] == null)
if (id >= Main.maxPlayers || TShock.Players[id] == null || !TShock.Players[id].Active)
{
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerDamage rejected null check"));
args.Handled = true;
Expand Down
8 changes: 4 additions & 4 deletions TShockAPI/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3070,12 +3070,12 @@ private static void TPHere(CommandArgs args)
args.Player.SendErrorMessage(GetString("You do not have permission to teleport all other players."));
return;
}
for (int i = 0; i < Main.maxPlayers; i++)
foreach (var player in TShock.Players)
{
if (Main.player[i].active && (Main.player[i] != args.TPlayer))
if (player != null && player.Active && player.Index != args.Player.Index)
{
if (TShock.Players[i].Teleport(args.TPlayer.position.X, args.TPlayer.position.Y))
TShock.Players[i].SendSuccessMessage(GetString("You were teleported to {0}.", args.Player.Name));
if (player.Teleport(args.TPlayer.position.X, args.TPlayer.position.Y))
player.SendSuccessMessage(GetString("You were teleported to {0}.", args.Player.Name));
}
}
args.Player.SendSuccessMessage(GetString("Teleported everyone to yourself."));
Expand Down
6 changes: 3 additions & 3 deletions TShockAPI/Rest/RestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private object ServerStatusV2(RestRequestArgs args)
{"serverversion", Main.versionNumber},
{"tshockversion", TShock.VersionNum},
{"port", TShock.Config.Settings.ServerPort},
{"playercount", Main.player.Where(p => null != p && p.active).Count()},
{"playercount", TShock.Utils.GetActivePlayerCount()},
{"maxplayers", TShock.Config.Settings.MaxSlots},
{"world", (TShock.Config.Settings.UseServerName ? TShock.Config.Settings.ServerName : Main.worldName)},
{"uptime", (DateTime.Now - System.Diagnostics.Process.GetCurrentProcess().StartTime).ToString(@"d'.'hh':'mm':'ss")},
Expand Down Expand Up @@ -944,8 +944,8 @@ private object PlayerMute(RestRequestArgs args)
[Token]
private object PlayerList(RestRequestArgs args)
{
var activeplayers = Main.player.Where(p => null != p && p.active).ToList();
return new RestObject() { { "players", string.Join(", ", activeplayers.Select(p => p.name)) } };
var activeplayers = TShock.Players.Where(p => null != p && p.Active).Select(p => p.Name);
return new RestObject() { { "players", string.Join(", ", activeplayers) } };
}

[Description("Fetches detailed user information on all connected users, and can be filtered by specifying a key value pair filter users where the key is a field and the value is a users field value.")]
Expand Down
4 changes: 2 additions & 2 deletions TShockAPI/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void SendLogs(string log, Color color, TSPlayer excludedPlayer = null)
foreach (TSPlayer player in TShock.Players)
{
if (player != null && player != excludedPlayer && player.Active && player.HasPermission(Permissions.logs) &&
player.DisplayLogs && TShock.Config.Settings.DisableSpewLogs == false)
player.DisplayLogs && !TShock.Config.Settings.DisableSpewLogs)
player.SendMessage(log, color);
}
}
Expand All @@ -183,7 +183,7 @@ public void SendLogs(string log, Color color, TSPlayer excludedPlayer = null)
/// <returns>The number of active players on the server.</returns>
public int GetActivePlayerCount()
{
return Main.player.Where(p => null != p && p.active).Count();
return TShock.Players.Count(p => null != p && p.Active);
}

//Random should not be generated in a method
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Use past tense when adding new entries; sign your name off when you add or chang
* Allowed Flower Boots to place Ash Flowers on Ash Grass blocks. (@punchready)
* Removed unnecessary range check that artifically shortened quick stack reach. (@boddyn, #2885, @bcat)
* Improved the exploit protection in tile rect handling. (@punchready)
* Changed the use of `Player.active` to `TSPlayer.Active` for consistency. (@sgkoishi, #2939)

## TShock 5.1.3
* Added support for Terraria 1.4.4.9 via OTAPI 3.1.20. (@SignatureBeef)
Expand Down