Skip to content

Commit 7c0f07f

Browse files
Fix rare null reference error and add hidden ProtectionEnabledMessageDelay option
1 parent e0711a6 commit 7c0f07f

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

RespawnProtection/Components/RespawnProtectionComponent.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ private IEnumerator ProtectionTimer()
108108
DisableProtection();
109109
if (configuration.SendProtectionDisabledExpiredMessage)
110110
{
111-
pluginInstance.SendMessageToPlayer(UnturnedPlayer.FromCSteamID(SteamID), "SpawnProtectionDisabledExpired");
111+
UnturnedPlayer unturnedPlayer = UnturnedPlayer.FromCSteamID(SteamID);
112+
pluginInstance.SendMessageToPlayer(unturnedPlayer, "SpawnProtectionDisabledExpired");
112113
}
113114
}
114115

RespawnProtection/RespawnProtection.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net48</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
<RootNamespace>RestoreMonarchy.RespawnProtection</RootNamespace>
7-
<Version>1.2.0</Version>
7+
<Version>1.2.1</Version>
88
</PropertyGroup>
99

1010
<ItemGroup>

RespawnProtection/RespawnProtectionConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class RespawnProtectionConfiguration : IRocketPluginConfiguration
2020
public float EffectTriggerRate { get; set; }
2121
public float AttackMessageRate { get; set; }
2222
public bool SendProtectionEnabledMessage { get; set; } = true;
23+
public float ProtectionEnabledMessageDelay { get; set; } = 0f;
24+
public bool ShouldSerializeSpawnProtectionEnabledMessageDelay() => ProtectionEnabledMessageDelay > 0;
2325
public bool SendProtectionDisabledExpiredMessage { get; set; } = true;
2426
public bool SendProtectionDisabledOtherMessage { get; set; } = true;
2527

RespawnProtection/RespawnProtectionPlugin.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Rocket.API.Collections;
55
using Rocket.Core.Logging;
66
using Rocket.Core.Plugins;
7+
using Rocket.Core.Utils;
78
using Rocket.Unturned;
89
using Rocket.Unturned.Chat;
910
using Rocket.Unturned.Player;
@@ -68,7 +69,17 @@ private void OnPlayerConnected(UnturnedPlayer player)
6869
if (Configuration.Instance.SendProtectionEnabledMessage)
6970
{
7071
string duration = Configuration.Instance.ProtectionDuration.ToString("N0");
71-
SendMessageToPlayer(player, "SpawnProtectionEnabled", duration);
72+
if (Configuration.Instance.ProtectionEnabledMessageDelay > 0)
73+
{
74+
TaskDispatcher.QueueOnMainThread(() =>
75+
{
76+
SendMessageToPlayer(player, "SpawnProtectionEnabled", duration);
77+
}, Configuration.Instance.ProtectionEnabledMessageDelay);
78+
79+
} else
80+
{
81+
SendMessageToPlayer(player, "SpawnProtectionEnabled", duration);
82+
}
7283
}
7384
}
7485
}
@@ -151,7 +162,10 @@ internal void SendMessageToPlayer(IRocketPlayer player, string translationKey, p
151162
}
152163

153164
UnturnedPlayer unturnedPlayer = (UnturnedPlayer)player;
154-
ChatManager.serverSendMessage(msg, MessageColor, null, unturnedPlayer.SteamPlayer(), EChatMode.SAY, Configuration.Instance.MessageIconUrl, true);
165+
if (unturnedPlayer != null)
166+
{
167+
ChatManager.serverSendMessage(msg, MessageColor, null, unturnedPlayer.SteamPlayer(), EChatMode.SAY, Configuration.Instance.MessageIconUrl, true);
168+
}
155169
}
156170
}
157171
}

0 commit comments

Comments
 (0)