@@ -33,19 +33,46 @@ void Start()
3333 {
3434 Player . life . onLifeUpdated += OnLifeUpdated ;
3535 Player . equipment . onEquipRequested += OnEquipRequested ;
36+ Player . onPlayerTeleported += OnPlayerTeleported ;
3637 }
3738
3839 void OnDestroy ( )
3940 {
4041 Player . life . onLifeUpdated -= OnLifeUpdated ;
4142 Player . equipment . onEquipRequested -= OnEquipRequested ;
43+ Player . onPlayerTeleported -= OnPlayerTeleported ;
44+ StopAllCoroutines ( ) ;
45+ }
46+
47+ private void OnPlayerTeleported ( Player player , Vector3 point )
48+ {
49+ if ( ! configuration . EnableArenaSpawnProtection )
50+ {
51+ return ;
52+ }
53+ if ( ! LevelManager . isArenaMode || LevelManager . arenaState != EArenaState . SPAWN )
54+ {
55+ return ;
56+ }
57+
58+ EnableProtection ( ) ;
59+ if ( configuration . SendProtectionEnabledMessage )
60+ {
61+ string duration = configuration . ProtectionDuration . ToString ( "N0" ) ;
62+ pluginInstance . SendMessageToPlayer ( UnturnedPlayer . FromPlayer ( Player ) , "SpawnProtectionEnabled" , duration ) ;
63+ }
4264 }
4365
4466 public Coroutine ProtectionCoroutine { get ; private set ; }
4567 public Coroutine EffectCoroutine { get ; private set ; }
4668
4769 private void OnLifeUpdated ( bool isDead )
4870 {
71+ if ( LevelManager . isArenaMode )
72+ {
73+ return ;
74+ }
75+
4976 if ( isDead )
5077 {
5178 DisableProtection ( ) ;
@@ -61,7 +88,7 @@ private void OnLifeUpdated(bool isDead)
6188 if ( configuration . SendProtectionEnabledMessage )
6289 {
6390 string duration = configuration . ProtectionDuration . ToString ( "N0" ) ;
64- pluginInstance . SendMessageToPlayer ( UnturnedPlayer . FromCSteamID ( SteamID ) , "SpawnProtectionEnabled" , duration ) ;
91+ pluginInstance . SendMessageToPlayer ( UnturnedPlayer . FromPlayer ( Player ) , "SpawnProtectionEnabled" , duration ) ;
6592 }
6693 }
6794 }
@@ -105,12 +132,13 @@ private IEnumerator ProtectionTimer()
105132 {
106133 yield return new WaitForSeconds ( configuration . ProtectionDuration ) ;
107134
108- DisableProtection ( ) ;
109- if ( configuration . SendProtectionDisabledExpiredMessage )
135+ if ( configuration . SendProtectionDisabledExpiredMessage && Player != null )
110136 {
111- UnturnedPlayer unturnedPlayer = UnturnedPlayer . FromCSteamID ( SteamID ) ;
137+ UnturnedPlayer unturnedPlayer = UnturnedPlayer . FromPlayer ( Player ) ;
112138 pluginInstance . SendMessageToPlayer ( unturnedPlayer , "SpawnProtectionDisabledExpired" ) ;
113139 }
140+
141+ DisableProtection ( ) ;
114142 }
115143
116144 private IEnumerator EffectTimer ( )
@@ -139,16 +167,23 @@ private IEnumerator EffectTimer()
139167 }
140168 }
141169
170+ private float lastCheckTime = 0f ;
142171 void FixedUpdate ( )
143172 {
144173 if ( IsProtected && configuration . DisableOnMove )
145174 {
146- if ( Vector3 . Distance ( respawnPosition , Player . transform . position ) > configuration . MaxMoveDistance )
175+ // check every 0.25 seconds
176+ if ( Time . time - lastCheckTime >= 0.25f )
147177 {
148- DisableProtection ( ) ;
149- if ( configuration . SendProtectionDisabledOtherMessage )
178+ lastCheckTime = Time . time ;
179+
180+ if ( Vector3 . Distance ( respawnPosition , Player . transform . position ) > configuration . MaxMoveDistance )
150181 {
151- pluginInstance . SendMessageToPlayer ( UnturnedPlayer . FromCSteamID ( SteamID ) , "SpawnProtectionDisabledOnMove" ) ;
182+ DisableProtection ( ) ;
183+ if ( configuration . SendProtectionDisabledOtherMessage )
184+ {
185+ pluginInstance . SendMessageToPlayer ( UnturnedPlayer . FromPlayer ( Player ) , "SpawnProtectionDisabledOnMove" ) ;
186+ }
152187 }
153188 }
154189 }
@@ -163,7 +198,7 @@ private void OnEquipRequested(PlayerEquipment equipment, ItemJar jar, ItemAsset
163198 DisableProtection ( ) ;
164199 if ( configuration . SendProtectionDisabledOtherMessage )
165200 {
166- pluginInstance . SendMessageToPlayer ( UnturnedPlayer . FromCSteamID ( SteamID ) , "SpawnProtectionDisabledOnEquipGun" ) ;
201+ pluginInstance . SendMessageToPlayer ( UnturnedPlayer . FromPlayer ( Player ) , "SpawnProtectionDisabledOnEquipGun" ) ;
167202 }
168203 }
169204
@@ -172,7 +207,7 @@ private void OnEquipRequested(PlayerEquipment equipment, ItemJar jar, ItemAsset
172207 DisableProtection ( ) ;
173208 if ( configuration . SendProtectionDisabledOtherMessage )
174209 {
175- pluginInstance . SendMessageToPlayer ( UnturnedPlayer . FromCSteamID ( SteamID ) , "SpawnProtectionDisabledOnEquipMelee" ) ;
210+ pluginInstance . SendMessageToPlayer ( UnturnedPlayer . FromPlayer ( Player ) , "SpawnProtectionDisabledOnEquipMelee" ) ;
176211 }
177212 }
178213
@@ -181,7 +216,7 @@ private void OnEquipRequested(PlayerEquipment equipment, ItemJar jar, ItemAsset
181216 DisableProtection ( ) ;
182217 if ( configuration . SendProtectionDisabledOtherMessage )
183218 {
184- pluginInstance . SendMessageToPlayer ( UnturnedPlayer . FromCSteamID ( SteamID ) , "SpawnProtectionDisabledOnEquipThrowable" ) ;
219+ pluginInstance . SendMessageToPlayer ( UnturnedPlayer . FromPlayer ( Player ) , "SpawnProtectionDisabledOnEquipThrowable" ) ;
185220 }
186221 }
187222 }
0 commit comments