using OWML.Common; using QSB.EventsCore; using QSB.SectorSync; using QSB.Utility; using QSB.WorldSync; using QSB.WorldSync.Events; namespace QSB.Player.Events { public class PlayerSectorEvent : QSBEvent { public override EventType Type => EventType.PlayerSectorChange; public override void SetupListener() { GlobalMessenger.AddListener(EventNames.QSBSectorChange, Handler); } public override void CloseListener() { GlobalMessenger.RemoveListener(EventNames.QSBSectorChange, Handler); } private void Handler(uint netId, QSBSector sector) => SendEvent(CreateMessage(netId, sector)); private WorldObjectMessage CreateMessage(uint netId, QSBSector sector) => new WorldObjectMessage { AboutId = netId, ObjectId = sector.ObjectId }; public override void OnReceiveRemote(WorldObjectMessage message) { if (!QSBSceneManager.IsInUniverse) { return; } var sector = WorldRegistry.GetObject(message.ObjectId); if (sector == null) { DebugLog.ToConsole($"Sector with order id {message.ObjectId} not found!", MessageType.Warning); return; } var transformSync = QSBPlayerManager.GetSyncObject(message.AboutId); QSB.Helper.Events.Unity.RunWhen(() => transformSync?.SyncedTransform != null, () => transformSync?.SetReferenceSector(sector)); } } }