Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheR00st3r committed Nov 4, 2023
1 parent 3fe0543 commit 6ed0ebc
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion PugSharp/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace PugSharp;
public class Player : IPlayer
{
private static readonly ILogger<Player> _Logger = LogManager.CreateLogger<Player>();
private readonly CCSPlayerController _PlayerController;
private uint _EntityIndex;
private CCSPlayerController _PlayerController;

public Player(CCSPlayerController playerController)
{
Expand All @@ -20,6 +21,7 @@ public Player(CCSPlayerController playerController)
_Logger.LogError("PlayerController is invalid!");
}

_EntityIndex = playerController.EntityIndex!.Value.Value;
_PlayerController = playerController;
if (_PlayerController.ActionTrackingServices != null)
{
Expand All @@ -29,17 +31,32 @@ public Player(CCSPlayerController playerController)

private T DefaultIfInvalid<T>(Func<T> loadValue) where T : struct
{
if (_PlayerController == null || !_PlayerController.IsValid)
{
_PlayerController = Utilities.GetPlayerFromIndex((int)_EntityIndex);
}

return _PlayerController != null && _PlayerController.IsValid ? loadValue() : default;
}

private T DefaultIfInvalid<T>(Func<T> loadValue, T defaultValue)
{
if (_PlayerController == null || !_PlayerController.IsValid)
{
_PlayerController = Utilities.GetPlayerFromIndex((int)_EntityIndex);
}

return _PlayerController != null && _PlayerController.IsValid ? loadValue() : defaultValue;
}


private T? NullIfInvalid<T>(Func<T?> loadValue)
{
if (_PlayerController == null || !_PlayerController.IsValid)
{
_PlayerController = Utilities.GetPlayerFromIndex((int)_EntityIndex);
}

return _PlayerController != null && _PlayerController.IsValid ? loadValue() : default;
}

Expand Down

0 comments on commit 6ed0ebc

Please sign in to comment.