Skip to content

Commit

Permalink
Changes Asked
Browse files Browse the repository at this point in the history
  • Loading branch information
NotZer0Two committed Nov 30, 2024
1 parent 446287d commit 1f0c040
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions EXILED/Exiled.API/Features/Npc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ namespace Exiled.API.Features
/// </summary>
public class Npc : Player
{
/// <summary>
/// Gets a <see cref="Dictionary{TKey, TValue}"/> containing all <see cref="Player"/>'s on the server.
/// </summary>
public static Dictionary<GameObject, Player> Dictionary { get; } = new(new ReferenceHub.GameObjectComparer());

/// <inheritdoc cref="Player" />
public Npc(ReferenceHub referenceHub)
: base(referenceHub)
Expand All @@ -48,7 +53,7 @@ public Npc(GameObject gameObject)
/// <summary>
/// Gets a list of Npcs.
/// </summary>
public static new List<Npc> List => Player.List.OfType<Npc>().ToList();
public static IReadOnlyCollection<Player> List => Dictionary.Values;

/// <summary>
/// Gets or sets the player's position.
Expand All @@ -75,7 +80,10 @@ public Player? FollowedPlayer
set
{
if (!GameObject.TryGetComponent(out PlayerFollower follower))
{
GameObject.AddComponent<PlayerFollower>()._hubToFollow = value?.ReferenceHub;
return;
}

follower._hubToFollow = value?.ReferenceHub;
}
Expand All @@ -97,11 +105,14 @@ public float? MaxDistance

set
{
if (!GameObject.TryGetComponent(out PlayerFollower follower))
if(!value.HasValue)
return;

if(!value.HasValue)
if (!GameObject.TryGetComponent(out PlayerFollower follower))
{
GameObject.AddComponent<PlayerFollower>()._maxDistance = value.Value;
return;
}

follower._maxDistance = value.Value;
}
Expand All @@ -123,11 +134,14 @@ public float? MinDistance

set
{
if (!GameObject.TryGetComponent(out PlayerFollower follower))
if(!value.HasValue)
return;

if(!value.HasValue)
if (!GameObject.TryGetComponent(out PlayerFollower follower))
{
GameObject.AddComponent<PlayerFollower>()._minDistance = value.Value;
return;
}

follower._minDistance = value.Value;
}
Expand All @@ -149,11 +163,14 @@ public float? Speed

set
{
if (!GameObject.TryGetComponent(out PlayerFollower follower))
if(!value.HasValue)
return;

if(!value.HasValue)
if (!GameObject.TryGetComponent(out PlayerFollower follower))
{
GameObject.AddComponent<PlayerFollower>()._speed = value.Value;
return;
}

follower._speed = value.Value;
}
Expand Down

0 comments on commit 1f0c040

Please sign in to comment.