Skip to content

fix: Add Player to TrackedPlayers before setting role #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public abstract class CustomRole
{
private const float AddRoleDelay = 0.25f;

// used in AddRole and InternalChangingRole
private static bool skipChangingCheck;

private static Dictionary<Type, CustomRole?> typeLookupTable = new();

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

if (Role != RoleTypeId.None)
{
if (KeepPositionOnSpawn)
try
{
if (KeepInventoryOnSpawn)
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.None);
skipChangingCheck = true;
if (KeepPositionOnSpawn)
{
if (KeepInventoryOnSpawn)
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.None);
else
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.AssignInventory);
}
else
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.AssignInventory);
{
if (KeepInventoryOnSpawn && player.IsAlive)
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.UseSpawnpoint);
else
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.All);
}
}
else
finally
{
if (KeepInventoryOnSpawn && player.IsAlive)
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.UseSpawnpoint);
else
player.Role.Set(Role, SpawnReason.ForceClass, RoleSpawnFlags.All);
skipChangingCheck = false;
}
}

Expand Down Expand Up @@ -952,8 +963,10 @@ private void OnInternalChangingNickname(ChangingNicknameEventArgs ev)

private void OnInternalChangingRole(ChangingRoleEventArgs ev)
{
if (ev.IsAllowed && ev.Reason != SpawnReason.Destroyed && Check(ev.Player) && ((ev.NewRole == RoleTypeId.Spectator && !KeepRoleOnDeath) || (ev.NewRole != RoleTypeId.Spectator && !KeepRoleOnChangingRole)))
if (!skipChangingCheck && ev.IsAllowed && ev.Reason != SpawnReason.Destroyed && Check(ev.Player) && ((ev.NewRole == RoleTypeId.Spectator && !KeepRoleOnDeath) || (ev.NewRole != RoleTypeId.Spectator && !KeepRoleOnChangingRole)))
RemoveRole(ev.Player);
else
skipChangingCheck = false;
}

private void OnSpawningRagdoll(SpawningRagdollEventArgs ev)
Expand Down
Loading