using QSB.Events; using QSB.GeyserSync.WorldObjects; using QSB.WorldSync; using QSB.WorldSync.Events; namespace QSB.GeyserSync.Events { public class GeyserEvent : QSBEvent { public override EventType Type => EventType.Geyser; public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBGeyserState, Handler); public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBGeyserState, Handler); private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state)); private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage { AboutId = LocalPlayerId, ObjectId = id, State = state }; public override void OnReceiveRemote(bool server, BoolWorldObjectMessage message) { if (!QSBCore.HasWokenUp) { return; } var geyser = QSBWorldSync.GetWorldFromId(message.ObjectId); geyser?.SetState(message.State); } } }