Skip to content

Commit

Permalink
Fix rare null reference error and add hidden ProtectionEnabledMessage…
Browse files Browse the repository at this point in the history
…Delay option
  • Loading branch information
RestoreMonarchy committed Nov 2, 2024
1 parent e0711a6 commit 7c0f07f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion RespawnProtection/Components/RespawnProtectionComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ private IEnumerator ProtectionTimer()
DisableProtection();
if (configuration.SendProtectionDisabledExpiredMessage)
{
pluginInstance.SendMessageToPlayer(UnturnedPlayer.FromCSteamID(SteamID), "SpawnProtectionDisabledExpired");
UnturnedPlayer unturnedPlayer = UnturnedPlayer.FromCSteamID(SteamID);
pluginInstance.SendMessageToPlayer(unturnedPlayer, "SpawnProtectionDisabledExpired");
}
}

Expand Down
2 changes: 1 addition & 1 deletion RespawnProtection/RespawnProtection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net48</TargetFramework>
<LangVersion>latest</LangVersion>
<RootNamespace>RestoreMonarchy.RespawnProtection</RootNamespace>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions RespawnProtection/RespawnProtectionConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class RespawnProtectionConfiguration : IRocketPluginConfiguration
public float EffectTriggerRate { get; set; }
public float AttackMessageRate { get; set; }
public bool SendProtectionEnabledMessage { get; set; } = true;
public float ProtectionEnabledMessageDelay { get; set; } = 0f;
public bool ShouldSerializeSpawnProtectionEnabledMessageDelay() => ProtectionEnabledMessageDelay > 0;
public bool SendProtectionDisabledExpiredMessage { get; set; } = true;
public bool SendProtectionDisabledOtherMessage { get; set; } = true;

Expand Down
18 changes: 16 additions & 2 deletions RespawnProtection/RespawnProtectionPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Rocket.API.Collections;
using Rocket.Core.Logging;
using Rocket.Core.Plugins;
using Rocket.Core.Utils;
using Rocket.Unturned;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
Expand Down Expand Up @@ -68,7 +69,17 @@ private void OnPlayerConnected(UnturnedPlayer player)
if (Configuration.Instance.SendProtectionEnabledMessage)
{
string duration = Configuration.Instance.ProtectionDuration.ToString("N0");
SendMessageToPlayer(player, "SpawnProtectionEnabled", duration);
if (Configuration.Instance.ProtectionEnabledMessageDelay > 0)
{
TaskDispatcher.QueueOnMainThread(() =>
{
SendMessageToPlayer(player, "SpawnProtectionEnabled", duration);
}, Configuration.Instance.ProtectionEnabledMessageDelay);

} else
{
SendMessageToPlayer(player, "SpawnProtectionEnabled", duration);
}
}
}
}
Expand Down Expand Up @@ -151,7 +162,10 @@ internal void SendMessageToPlayer(IRocketPlayer player, string translationKey, p
}

UnturnedPlayer unturnedPlayer = (UnturnedPlayer)player;
ChatManager.serverSendMessage(msg, MessageColor, null, unturnedPlayer.SteamPlayer(), EChatMode.SAY, Configuration.Instance.MessageIconUrl, true);
if (unturnedPlayer != null)
{
ChatManager.serverSendMessage(msg, MessageColor, null, unturnedPlayer.SteamPlayer(), EChatMode.SAY, Configuration.Instance.MessageIconUrl, true);
}
}
}
}

0 comments on commit 7c0f07f

Please sign in to comment.