Skip to content

Commit

Permalink
fixed a possible nre if the config was fucked up
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikihero committed Oct 2, 2024
1 parent fd9b542 commit bd34cd0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Common Utilities/EventHandlers/PlayerHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public void OnChangingRole(ChangingRoleEventArgs ev)

public void OnSpawned(SpawnedEventArgs ev)
{
if (ev.Player == null)
if (ev.Player is null)
{
Log.Warn($"{nameof(OnSpawned)}: Triggering player is null.");
return;
}

RoleTypeId newRole = ev.Player.Role.Type;
if (config.HealthValues != null && config.HealthValues.TryGetValue(newRole, out int health))
if (config.HealthValues is not null && config.HealthValues.TryGetValue(newRole, out int health))
{
ev.Player.MaxHealth = health;
ev.Player.Health = health;
Expand All @@ -84,7 +84,7 @@ public void OnSpawned(SpawnedEventArgs ev)
ev.Player.CustomInfo = $"({ev.Player.Health}/{ev.Player.MaxHealth}) {(!string.IsNullOrEmpty(ev.Player.CustomInfo) ? ev.Player.CustomInfo.Substring(ev.Player.CustomInfo.LastIndexOf(')') + 1) : string.Empty)}";
}

if (config.AfkIgnoredRoles.Contains(newRole) && Plugin.AfkDict.TryGetValue(ev.Player, out Tuple<int, Vector3> value))
if (config.AfkIgnoredRoles is not null && config.AfkIgnoredRoles.Contains(newRole) && Plugin.AfkDict.TryGetValue(ev.Player, out Tuple<int, Vector3> value))
{
Plugin.AfkDict[ev.Player] =
new Tuple<int, Vector3>(newRole is RoleTypeId.Spectator ? value.Item1 : 0, ev.Player.Position);
Expand All @@ -93,21 +93,21 @@ public void OnSpawned(SpawnedEventArgs ev)

public void OnPlayerDied(DiedEventArgs ev)
{
if (ev.Attacker != null && config.HealthOnKill.ContainsKey(ev.Attacker.Role))
if (ev.Attacker is not null && config.HealthOnKill is not null && config.HealthOnKill.ContainsKey(ev.Attacker.Role))
{
ev.Attacker.Heal(config.HealthOnKill[ev.Attacker.Role]);
}
}

public void OnPlayerHurting(HurtingEventArgs ev)
{
if (config.RoleDamageDealtMultipliers != null && ev.Attacker != null && config.RoleDamageDealtMultipliers.TryGetValue(ev.Attacker.Role, out var damageMultiplier))
if (config.RoleDamageDealtMultipliers is not null && ev.Attacker is not null && config.RoleDamageDealtMultipliers.TryGetValue(ev.Attacker.Role, out var damageMultiplier))
ev.Amount *= damageMultiplier;

if (config.RoleDamageReceivedMultipliers != null && config.RoleDamageReceivedMultipliers.TryGetValue(ev.Player.Role, out damageMultiplier))
if (config.RoleDamageReceivedMultipliers is not null && config.RoleDamageReceivedMultipliers.TryGetValue(ev.Player.Role, out damageMultiplier))
ev.Amount *= damageMultiplier;

if (config.DamageMultipliers != null && config.DamageMultipliers.TryGetValue(ev.DamageHandler.Type, out damageMultiplier))
if (config.DamageMultipliers is not null && config.DamageMultipliers.TryGetValue(ev.DamageHandler.Type, out damageMultiplier))
ev.Amount *= damageMultiplier;

if (config.PlayerHealthInfo)
Expand Down

0 comments on commit bd34cd0

Please sign in to comment.