diff --git a/src/RollTheDice+DiceNoExplosives.cs b/src/RollTheDice+DiceNoExplosives.cs index 6139b91..d506462 100644 --- a/src/RollTheDice+DiceNoExplosives.cs +++ b/src/RollTheDice+DiceNoExplosives.cs @@ -51,11 +51,7 @@ private void DiceNoExplosivesUnload() private void DiceNoExplosivesOnEntitySpawned(CEntityInstance entity) { // remove listener if no players to save resources - if (_playersWithoutExplosives.Count == 0) - { - RemoveListener(DiceNoExplosivesOnEntitySpawned); - return; - } + if (_playersWithoutExplosives.Count == 0) return; // handle smoke grenades if (entity.DesignerName == "smokegrenade_projectile") DiceNoExplosivesHandleSmokeGrenade(entity.Handle); // handle HE grenades diff --git a/src/RollTheDice+DicePlayerAsChicken.cs b/src/RollTheDice+DicePlayerAsChicken.cs index edff6bf..7808ebf 100644 --- a/src/RollTheDice+DicePlayerAsChicken.cs +++ b/src/RollTheDice+DicePlayerAsChicken.cs @@ -44,14 +44,14 @@ private Dictionary DicePlayerAsChicken(CCSPlayerController playe private void DicePlayerAsChickenUnload() { + // remove listeners + RemoveListener(EventDicePlayerAsChickenOnTick); + RemoveListener(EventDicePlayerAsChickenCheckTransmit); DicePlayerAsChickenReset(); } private void DicePlayerAsChickenReset() { - // remove listeners - RemoveListener(EventDicePlayerAsChickenOnTick); - RemoveListener(EventDicePlayerAsChickenCheckTransmit); // iterate through all players foreach (CCSPlayerController player in _playersAsChicken.Keys) { @@ -65,11 +65,7 @@ private void DicePlayerAsChickenReset() private void EventDicePlayerAsChickenOnTick() { // remove listener if no players to save resources - if (_playersAsChicken.Count() == 0) - { - RemoveListener(EventDicePlayerAsChickenOnTick); - return; - } + if (_playersAsChicken.Count() == 0) return; // worker Dictionary> _playersAsChickenCopy = new(_playersAsChicken); foreach (var (player, playerData) in _playersAsChickenCopy) @@ -109,11 +105,7 @@ private void EventDicePlayerAsChickenOnTick() private void EventDicePlayerAsChickenCheckTransmit(CCheckTransmitInfoList infoList) { // remove listener if no players to save resources - if (_playersAsChicken.Count() == 0) - { - RemoveListener(EventDicePlayerAsChickenCheckTransmit); - return; - } + if (_playersAsChicken.Count() == 0) return; // worker foreach ((CCheckTransmitInfo info, CCSPlayerController? player) in infoList) { diff --git a/src/RollTheDice+DicePlayerCloak.cs b/src/RollTheDice+DicePlayerCloak.cs index b8f636b..136f771 100644 --- a/src/RollTheDice+DicePlayerCloak.cs +++ b/src/RollTheDice+DicePlayerCloak.cs @@ -33,13 +33,13 @@ private Dictionary DicePlayerCloak(CCSPlayerController player, C private void DicePlayerCloakUnload() { + // remove listeners + RemoveListener(EventDicePlayerCloakOnTick); DicePlayerCloakReset(); } private void DicePlayerCloakReset() { - // remove listeners - RemoveListener(EventDicePlayerCloakOnTick); // iterate through all players foreach (var (player, visibility) in _playersWithCloak) { @@ -56,12 +56,7 @@ private void DicePlayerCloakReset() private void EventDicePlayerCloakOnTick() { - // remove listener if no players to save resources - if (_playersWithCloak.Count() == 0) - { - RemoveListener(EventDicePlayerCloakOnTick); - return; - } + if (_playersWithCloak.Count() == 0) return; // worker Dictionary _playersWithCloakCopy = new(_playersWithCloak); foreach (var (player, visibility) in _playersWithCloakCopy) diff --git a/src/RollTheDice+DicePlayerDisguiseAsPlant.cs b/src/RollTheDice+DicePlayerDisguiseAsPlant.cs index 2aca2aa..7739ffb 100644 --- a/src/RollTheDice+DicePlayerDisguiseAsPlant.cs +++ b/src/RollTheDice+DicePlayerDisguiseAsPlant.cs @@ -56,12 +56,12 @@ private void DicePlayerDisguiseAsPlantLoad() private void DicePlayerDisguiseAsPlantUnload() { + RemoveListener(EventDicePlayerDisguiseAsPlantOnTick); DicePlayerDisguiseAsPlantReset(); } private void DicePlayerDisguiseAsPlantReset() { - RemoveListener(EventDicePlayerDisguiseAsPlantOnTick); foreach (CCSPlayerController player in _playersDisguisedAsPlants.Keys) { if (player == null || player.Pawn == null || player.Pawn.Value == null) continue; @@ -73,12 +73,7 @@ private void DicePlayerDisguiseAsPlantReset() private void EventDicePlayerDisguiseAsPlantOnTick() { - // remove listener if no players to save resources - if (_playersDisguisedAsPlants.Count == 0) - { - RemoveListener(EventDicePlayerDisguiseAsPlantOnTick); - return; - } + if (_playersDisguisedAsPlants.Count == 0) return; // worker Dictionary> _playersDisguisedAsPlantsCopy = new(_playersDisguisedAsPlants); foreach (var (player, playerData) in _playersDisguisedAsPlantsCopy) diff --git a/src/RollTheDice+DicePlayerMakeFakeGunSoundss.cs b/src/RollTheDice+DicePlayerMakeFakeGunSoundss.cs index a8d0083..58a95d8 100644 --- a/src/RollTheDice+DicePlayerMakeFakeGunSoundss.cs +++ b/src/RollTheDice+DicePlayerMakeFakeGunSoundss.cs @@ -36,23 +36,18 @@ private Dictionary DicePlayerMakeFakeGunSounds(CCSPlayerControll private void DicePlayerMakeFakeGunSoundsUnload() { + RemoveListener(EventDicePlayerMakeFakeGunSoundsOnTick); DicePlayerMakeFakeGunSoundsReset(); } private void DicePlayerMakeFakeGunSoundsReset() { - RemoveListener(EventDicePlayerMakeFakeGunSoundsOnTick); _playersWithFakeGunSounds.Clear(); } private void EventDicePlayerMakeFakeGunSoundsOnTick() { - // remove listener if no players to save resources - if (_playersWithFakeGunSounds.Count() == 0) - { - DicePlayerMakeFakeGunSoundsReset(); - return; - } + if (_playersWithFakeGunSounds.Count() == 0) return; // worker Dictionary _playersWithFakeGunSoundsCopy = new(_playersWithFakeGunSounds); foreach (var (player, last_sound) in _playersWithFakeGunSoundsCopy) diff --git a/src/RollTheDice+DicePlayerMakeHostageSounds.cs b/src/RollTheDice+DicePlayerMakeHostageSounds.cs index 8283d7d..e0a914f 100644 --- a/src/RollTheDice+DicePlayerMakeHostageSounds.cs +++ b/src/RollTheDice+DicePlayerMakeHostageSounds.cs @@ -29,23 +29,18 @@ private Dictionary DicePlayerMakeHostageSounds(CCSPlayerControll private void DicePlayerMakeHostageSoundsUnload() { + RemoveListener(EventDicePlayerMakeHostageSoundsOnTick); DicePlayerMakeHostageSoundsReset(); } private void DicePlayerMakeHostageSoundsReset() { - RemoveListener(EventDicePlayerMakeHostageSoundsOnTick); _playersWithHostageSounds.Clear(); } private void EventDicePlayerMakeHostageSoundsOnTick() { - // remove listener if no players to save resources - if (_playersWithHostageSounds.Count() == 0) - { - DicePlayerMakeHostageSoundsReset(); - return; - } + if (_playersWithHostageSounds.Count() == 0) return; // worker Dictionary _playersWithHostageSoundsCopy = new(_playersWithHostageSounds); foreach (var (player, playerStatus) in _playersWithHostageSoundsCopy) diff --git a/src/RollTheDice+DicePlayerRespawn.cs b/src/RollTheDice+DicePlayerRespawn.cs index 7c47133..e779485 100644 --- a/src/RollTheDice+DicePlayerRespawn.cs +++ b/src/RollTheDice+DicePlayerRespawn.cs @@ -30,23 +30,18 @@ private void DicePlayerRespawnLoad() private void DicePlayerRespawnUnload() { + RemoveListener(EventDicePlayerRespawnOnTick); DicePlayerRespawnReset(); } private void DicePlayerRespawnReset() { - RemoveListener(EventDicePlayerRespawnOnTick); _playersWithRespawnAbility.Clear(); } private void EventDicePlayerRespawnOnTick() { - // remove listener if no players to save resources - if (_playersWithRespawnAbility.Count() == 0) - { - DicePlayerRespawnReset(); - return; - } + if (_playersWithRespawnAbility.Count() == 0) return; // worker Dictionary> _playersWithRespawnAbilityCopy = new(_playersWithRespawnAbility); foreach (var (player, playerData) in _playersWithRespawnAbilityCopy)