diff --git a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
index 0e0d8042b0..db5e599cd3 100644
--- a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
+++ b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
@@ -37,14 +37,6 @@ namespace Exiled.CustomRoles.API.Features
///
public abstract class CustomRole
{
- ///
- /// Gets or sets the number of players that naturally spawned with this custom role.
- ///
- [YamlIgnore]
- #pragma warning disable SA1401 // Fields should be private
- public int SpawnedPlayers = 0;
- #pragma warning restore SA1401 // Fields should be private
-
private const float AddRoleDelay = 0.25f;
private static Dictionary typeLookupTable = new();
@@ -184,6 +176,12 @@ public abstract class CustomRole
///
public virtual string AbilityUsage { get; set; } = "Enter \".special\" in the console to use your ability. If you have multiple abilities, you can use this command to cycle through them, or specify the one to use with \".special ROLENAME AbilityNum\"";
+ ///
+ /// Gets or sets the number of players that naturally spawned with this custom role.
+ ///
+ [YamlIgnore]
+ public int SpawnedPlayers { get; set; }
+
///
/// Gets a by ID.
///
diff --git a/EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs b/EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs
index 5c0aa7356e..1a10e38dcf 100644
--- a/EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs
+++ b/EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs
@@ -22,8 +22,7 @@ namespace Exiled.CustomRoles.Events
///
public class PlayerHandlers
{
- private readonly CustomRoles plugin;
- private readonly HashSet validSpawnReasons = new()
+ private static readonly HashSet ValidSpawnReasons = new()
{
SpawnReason.RoundStart,
SpawnReason.Respawn,
@@ -33,6 +32,8 @@ public class PlayerHandlers
SpawnReason.ItemUsage,
};
+ private readonly CustomRoles plugin;
+
///
/// Initializes a new instance of the class.
///
@@ -64,7 +65,7 @@ internal void OnSpawningRagdoll(SpawningRagdollEventArgs ev)
///
internal void OnSpawned(SpawnedEventArgs ev)
{
- if (!validSpawnReasons.Contains(ev.Reason) || ev.Player.HasAnyCustomRole())
+ if (!ValidSpawnReasons.Contains(ev.Reason) || ev.Player.HasAnyCustomRole())
{
return;
}
@@ -108,7 +109,7 @@ internal void OnSpawned(SpawnedEventArgs ev)
break;
}
- int newSpawnCount = Interlocked.Increment(ref candidateRole.SpawnedPlayers);
+ int newSpawnCount = candidateRole.SpawnedPlayers++;
if (newSpawnCount <= candidateRole.SpawnProperties.Limit)
{
candidateRole.AddRole(ev.Player);
@@ -116,7 +117,7 @@ internal void OnSpawned(SpawnedEventArgs ev)
}
else
{
- Interlocked.Decrement(ref candidateRole.SpawnedPlayers);
+ candidateRole.SpawnedPlayers--;
randomRoll -= candidateRole.SpawnChance;
}
}