Merge pull request #2939 from sgkoishi/consistency-playeractive-patch

Use same TSPlayer.Active check
This commit is contained in:
Lucas Nicodemus 2025-01-25 23:15:31 +09:00 committed by GitHub
commit 251353c566
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 13 additions and 14 deletions

View file

@ -1878,7 +1878,7 @@ namespace TShockAPI
return; return;
} }
if (TShock.Players[id] == null) if (TShock.Players[id] == null || !TShock.Players[id].Active)
{ {
TShock.Log.ConsoleDebug(GetString( TShock.Log.ConsoleDebug(GetString(
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: target is null", args.Player.Name, "Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: target is null", args.Player.Name,
@ -2081,7 +2081,7 @@ namespace TShockAPI
short amount = args.Amount; short amount = args.Amount;
byte plr = args.TargetPlayerIndex; 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")); TShock.Log.ConsoleDebug(GetString("Bouncer / OnHealOtherPlayer rejected null checks"));
args.Handled = true; args.Handled = true;
@ -2589,7 +2589,7 @@ namespace TShockAPI
byte direction = args.Direction; byte direction = args.Direction;
PlayerDeathReason reason = args.PlayerDeathReason; 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")); TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerDamage rejected null check"));
args.Handled = true; args.Handled = true;

View file

@ -3070,12 +3070,12 @@ namespace TShockAPI
args.Player.SendErrorMessage(GetString("You do not have permission to teleport all other players.")); args.Player.SendErrorMessage(GetString("You do not have permission to teleport all other players."));
return; 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)) if (player.Teleport(args.TPlayer.position.X, args.TPlayer.position.Y))
TShock.Players[i].SendSuccessMessage(GetString("You were teleported to {0}.", args.Player.Name)); player.SendSuccessMessage(GetString("You were teleported to {0}.", args.Player.Name));
} }
} }
args.Player.SendSuccessMessage(GetString("Teleported everyone to yourself.")); args.Player.SendSuccessMessage(GetString("Teleported everyone to yourself."));

View file

@ -402,7 +402,7 @@ namespace TShockAPI
{"serverversion", Main.versionNumber}, {"serverversion", Main.versionNumber},
{"tshockversion", TShock.VersionNum}, {"tshockversion", TShock.VersionNum},
{"port", TShock.Config.Settings.ServerPort}, {"port", TShock.Config.Settings.ServerPort},
{"playercount", Main.player.Where(p => null != p && p.active).Count()}, {"playercount", TShock.Utils.GetActivePlayerCount()},
{"maxplayers", TShock.Config.Settings.MaxSlots}, {"maxplayers", TShock.Config.Settings.MaxSlots},
{"world", (TShock.Config.Settings.UseServerName ? TShock.Config.Settings.ServerName : Main.worldName)}, {"world", (TShock.Config.Settings.UseServerName ? TShock.Config.Settings.ServerName : Main.worldName)},
{"uptime", (DateTime.Now - System.Diagnostics.Process.GetCurrentProcess().StartTime).ToString(@"d'.'hh':'mm':'ss")}, {"uptime", (DateTime.Now - System.Diagnostics.Process.GetCurrentProcess().StartTime).ToString(@"d'.'hh':'mm':'ss")},
@ -944,8 +944,8 @@ namespace TShockAPI
[Token] [Token]
private object PlayerList(RestRequestArgs args) private object PlayerList(RestRequestArgs args)
{ {
var activeplayers = Main.player.Where(p => null != p && p.active).ToList(); var activeplayers = TShock.Players.Where(p => null != p && p.Active).Select(p => p.Name);
return new RestObject() { { "players", string.Join(", ", activeplayers.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.")] [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.")]

View file

@ -172,7 +172,7 @@ namespace TShockAPI
foreach (TSPlayer player in TShock.Players) foreach (TSPlayer player in TShock.Players)
{ {
if (player != null && player != excludedPlayer && player.Active && player.HasPermission(Permissions.logs) && 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); player.SendMessage(log, color);
} }
} }
@ -183,7 +183,7 @@ namespace TShockAPI
/// <returns>The number of active players on the server.</returns> /// <returns>The number of active players on the server.</returns>
public int GetActivePlayerCount() 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 //Random should not be generated in a method

View file

@ -79,7 +79,7 @@ Use past tense when adding new entries; sign your name off when you add or chang
## Upcoming changes ## Upcoming changes
* Fixed `/dump-reference-data` mutate the command names. (#2943, @sgkoishi) * Fixed `/dump-reference-data` mutate the command names. (#2943, @sgkoishi)
* You know the drill * Changed the use of `Player.active` to `TSPlayer.Active` for consistency. (@sgkoishi, #2939)
* Fix typo in config for IP bans. (@redchess64) * Fix typo in config for IP bans. (@redchess64)
## TShock 5.2.1 ## TShock 5.2.1
@ -132,7 +132,6 @@ Use past tense when adding new entries; sign your name off when you add or chang
* Relaxed custom death message restrictions to allow Inferno potions in PvP. (@drunderscore) * Relaxed custom death message restrictions to allow Inferno potions in PvP. (@drunderscore)
* Allowed Flower Boots to place Ash Flowers on Ash Grass blocks. (@punchready) * 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) * Removed unnecessary range check that artifically shortened quick stack reach. (@boddyn, #2885, @bcat)
* Re-wrote tile rect handling from scratch, fixing a certain exploitable flaw in the old code and significantly reducing the potential exploit surface, potentially even down to zero. (@punchready)
## TShock 5.1.3 ## TShock 5.1.3
* Added support for Terraria 1.4.4.9 via OTAPI 3.1.20. (@SignatureBeef) * Added support for Terraria 1.4.4.9 via OTAPI 3.1.20. (@SignatureBeef)