quantum-space-buddies/QSB/GeyserSync/GeyserEvent.cs

34 lines
951 B
C#
Raw Normal View History

2020-08-13 13:32:58 +00:00
using QSB.Events;
using QSB.Messaging;
using QSB.WorldSync;
namespace QSB.GeyserSync
{
public class GeyserEvent : QSBEvent<GeyserMessage>
{
public override MessageType Type => MessageType.Geyser;
public override void SetupListener()
{
2020-08-13 17:25:12 +00:00
GlobalMessenger<string, bool>.AddListener(EventNames.QSBGeyserState, (name, state) => SendEvent(CreateMessage(name, state)));
2020-08-13 13:32:58 +00:00
}
2020-08-13 17:25:12 +00:00
private GeyserMessage CreateMessage(string name, bool state) => new GeyserMessage
2020-08-13 13:32:58 +00:00
{
SenderId = PlayerRegistry.LocalPlayer.NetId,
UniqueName = name,
2020-08-13 13:32:58 +00:00
State = state
};
public override void OnReceiveRemote(GeyserMessage message)
{
2020-08-13 16:44:27 +00:00
if (!IsInUniverse)
2020-08-13 13:32:58 +00:00
{
return;
}
var geyser = WorldRegistry.GetObject<QSBGeyser>(message.UniqueName);
2020-08-13 17:25:12 +00:00
geyser.SetState(message.State);
2020-08-13 13:32:58 +00:00
}
}
}