From 537e987b416ab7b76db56236698206f23eb28888 Mon Sep 17 00:00:00 2001 From: "@Someone" <45270312+Someone-193@users.noreply.github.com> Date: Sun, 3 Aug 2025 13:41:18 -0400 Subject: [PATCH] the fix --- .../API/Features/CustomRole.cs | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs index 4838224e8..60c8dfdd1 100644 --- a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs +++ b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs @@ -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 typeLookupTable = new(); private static Dictionary stringLookupTable = new(); @@ -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; } } @@ -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)