Skip to content

Commit 1374e04

Browse files
Allow external plugins to set IsHomeSpawn for custom bed spawns
1 parent 65869d5 commit 1374e04

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

RespawnProtection/Components/RespawnProtectionComponent.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using RestoreMonarchy.RespawnProtection.Models;
1+
using RestoreMonarchy.RespawnProtection.Models;
22
using Rocket.Unturned.Player;
33
using SDG.Unturned;
44
using Steamworks;
@@ -17,7 +17,7 @@ public class RespawnProtectionComponent : MonoBehaviour
1717

1818
public Player Player { get; private set; }
1919
public bool IsProtected { get; private set; }
20-
public bool IsHomeSpawn { get; internal set; }
20+
public bool IsHomeSpawn { get; set; }
2121
private CSteamID SteamID => Player.channel.owner.playerID.steamID;
2222

2323
public List<LastAttackMessage> LastAttackMessages { get; private set; } = new();
@@ -76,10 +76,14 @@ private void OnLifeUpdated(bool isDead)
7676
if (isDead)
7777
{
7878
DisableProtection();
79+
IsHomeSpawn = false;
7980
}
8081
else
8182
{
82-
if (!configuration.EnableHomeSpawnProtection && IsHomeSpawn)
83+
bool wasHomeSpawn = IsHomeSpawn;
84+
IsHomeSpawn = false;
85+
86+
if (!configuration.EnableHomeSpawnProtection && wasHomeSpawn)
8387
{
8488
return;
8589
}
@@ -222,4 +226,4 @@ private void OnEquipRequested(PlayerEquipment equipment, ItemJar jar, ItemAsset
222226
}
223227
}
224228
}
225-
}
229+
}

RespawnProtection/RespawnProtection.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<TargetFramework>net48</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
<RootNamespace>RestoreMonarchy.RespawnProtection</RootNamespace>
7-
<Version>1.3.0</Version>
7+
<Version>1.3.1</Version>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<PackageReference Include="RestoreMonarchy.RocketRedist" Version="3.*" ExcludeAssets="runtime" />
1212
</ItemGroup>
1313

14-
</Project>
14+
</Project>

RespawnProtection/RespawnProtectionPlugin.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected override void Unload()
8080
};
8181
#endif
8282

83-
private void OnPlayerConnected(UnturnedPlayer player)
83+
private void OnPlayerConnected(UnturnedPlayer player)
8484
{
8585
RespawnProtectionComponent component = player.Player.gameObject.AddComponent<RespawnProtectionComponent>();
8686
if (Configuration.Instance.EnableJoinSpawnProtection)
@@ -95,11 +95,12 @@ private void OnPlayerConnected(UnturnedPlayer player)
9595
{
9696
SendMessageToPlayer(player, "SpawnProtectionEnabled", duration);
9797
}, Configuration.Instance.ProtectionEnabledMessageDelay);
98-
99-
} else
98+
99+
}
100+
else
100101
{
101102
SendMessageToPlayer(player, "SpawnProtectionEnabled", duration);
102-
}
103+
}
103104
}
104105
}
105106
}
@@ -167,7 +168,11 @@ private void OnSelectRespawnPoint(PlayerLife sender, bool wantsToSpawnAtHome, re
167168
RespawnProtectionComponent component = sender.gameObject.GetComponent<RespawnProtectionComponent>();
168169
if (component != null)
169170
{
170-
component.IsHomeSpawn = wantsToSpawnAtHome;
171+
// Only set IsHomeSpawn from here if it's not already set to true by another plugin (e.g. DeathMenu)
172+
if (!component.IsHomeSpawn)
173+
{
174+
component.IsHomeSpawn = wantsToSpawnAtHome;
175+
}
171176
}
172177
}
173178

@@ -193,4 +198,4 @@ internal void SendMessageToPlayer(IRocketPlayer player, string translationKey, p
193198
}
194199
}
195200
}
196-
}
201+
}

0 commit comments

Comments
 (0)