Skip to content

Commit 0fde095

Browse files
authored
fix: Add Player to TrackedPlayers before setting role (#606)
the fix
1 parent 0ec6164 commit 0fde095

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public abstract class CustomRole
3939
{
4040
private const float AddRoleDelay = 0.25f;
4141

42+
// used in AddRole and InternalChangingRole
43+
private static bool skipChangingCheck;
44+
4245
private static Dictionary<Type, CustomRole?> typeLookupTable = new();
4346

4447
private static Dictionary<string, CustomRole?> stringLookupTable = new();
@@ -515,19 +518,27 @@ public virtual void AddRole(Player player)
515518

516519
if (Role != RoleTypeId.None)
517520
{
518-
if (KeepPositionOnSpawn)
521+
try
519522
{
520-
if (KeepInventoryOnSpawn)
521-
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.None);
523+
skipChangingCheck = true;
524+
if (KeepPositionOnSpawn)
525+
{
526+
if (KeepInventoryOnSpawn)
527+
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.None);
528+
else
529+
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.AssignInventory);
530+
}
522531
else
523-
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.AssignInventory);
532+
{
533+
if (KeepInventoryOnSpawn && player.IsAlive)
534+
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.UseSpawnpoint);
535+
else
536+
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.All);
537+
}
524538
}
525-
else
539+
finally
526540
{
527-
if (KeepInventoryOnSpawn && player.IsAlive)
528-
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.UseSpawnpoint);
529-
else
530-
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.All);
541+
skipChangingCheck = false;
531542
}
532543
}
533544

@@ -952,8 +963,10 @@ private void OnInternalChangingNickname(ChangingNicknameEventArgs ev)
952963

953964
private void OnInternalChangingRole(ChangingRoleEventArgs ev)
954965
{
955-
if (ev.IsAllowed && ev.Reason != SpawnReason.Destroyed && Check(ev.Player) && ((ev.NewRole == RoleTypeId.Spectator && !KeepRoleOnDeath) || (ev.NewRole != RoleTypeId.Spectator && !KeepRoleOnChangingRole)))
966+
if (!skipChangingCheck && ev.IsAllowed && ev.Reason != SpawnReason.Destroyed && Check(ev.Player) && ((ev.NewRole == RoleTypeId.Spectator && !KeepRoleOnDeath) || (ev.NewRole != RoleTypeId.Spectator && !KeepRoleOnChangingRole)))
956967
RemoveRole(ev.Player);
968+
else
969+
skipChangingCheck = false;
957970
}
958971

959972
private void OnSpawningRagdoll(SpawningRagdollEventArgs ev)

0 commit comments

Comments
 (0)