2021-06-23 12:06:08 +01:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.Player;
|
|
|
|
|
|
|
|
|
|
namespace QSB.DeathSync.Events
|
|
|
|
|
{
|
2021-07-12 22:02:50 +01:00
|
|
|
|
internal class PlayerRespawnEvent : QSBEvent<PlayerMessage>
|
2021-06-23 12:06:08 +01:00
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.PlayerRespawn;
|
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
=> GlobalMessenger<uint>.AddListener(EventNames.QSBPlayerRespawn, Handler);
|
|
|
|
|
|
|
|
|
|
public override void CloseListener()
|
|
|
|
|
=> GlobalMessenger<uint>.RemoveListener(EventNames.QSBPlayerRespawn, Handler);
|
|
|
|
|
|
|
|
|
|
private void Handler(uint playerId) => SendEvent(CreateMessage(playerId));
|
|
|
|
|
|
|
|
|
|
private PlayerMessage CreateMessage(uint playerId) => new PlayerMessage
|
|
|
|
|
{
|
|
|
|
|
AboutId = playerId
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-04 22:34:38 +01:00
|
|
|
|
public override void OnReceiveLocal(bool server, PlayerMessage message)
|
2021-06-23 12:06:08 +01:00
|
|
|
|
=> OnReceiveRemote(server, message);
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote(bool server, PlayerMessage message)
|
|
|
|
|
{
|
|
|
|
|
if (message.AboutId == LocalPlayerId)
|
|
|
|
|
{
|
|
|
|
|
RespawnManager.Instance.Respawn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RespawnManager.Instance.OnPlayerRespawn(QSBPlayerManager.GetPlayer(message.AboutId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|