Sync when calling SetCustomData directly not just from API

This commit is contained in:
Nick 2023-08-02 17:04:07 -04:00
parent faa557591a
commit fcef4d749d
4 changed files with 13 additions and 7 deletions

View File

@ -8,7 +8,5 @@ public class AddonCustomDataSyncMessage : QSBMessage<(uint playerId, string key,
{
public AddonCustomDataSyncMessage(uint playerId, string key, object data) : base((playerId, key, data.ToBytes())) { }
public override void OnReceiveLocal() => OnReceiveRemote();
public override void OnReceiveRemote() => QSBPlayerManager.GetPlayer(Data.playerId).SetCustomData(Data.key, Data.data.ToObject());
}

View File

@ -1,6 +1,4 @@
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using QSB.Messaging;
using QSB.Messaging;
using QSB.Utility;
namespace QSB.API.Messages;

View File

@ -27,7 +27,7 @@ public class QSBAPI : IQSBAPI
public UnityEvent<uint> OnPlayerLeave() => QSBAPIEvents.OnPlayerLeaveEvent;
public void SetCustomData<T>(uint playerId, string key, T data)
=> new AddonCustomDataSyncMessage(playerId, key, data).Send();
=> QSBPlayerManager.GetPlayer(playerId).SetCustomData<T>(key, data);
public T GetCustomData<T>(uint playerId, string key)
=> QSBPlayerManager.GetPlayer(playerId).GetCustomData<T>(key);

View File

@ -1,10 +1,12 @@
using OWML.Common;
using QSB.Animation.Player;
using QSB.API.Messages;
using QSB.Audio;
using QSB.ClientServerStateSync;
using QSB.HUD;
using QSB.Messaging;
using QSB.ModelShip;
using QSB.Patches;
using QSB.Player.Messages;
using QSB.Player.TransformSync;
using QSB.QuantumSync.WorldObjects;
@ -182,7 +184,15 @@ public partial class PlayerInfo
private Dictionary<string, object> _customData = new();
public void SetCustomData<T>(string key, T data)
=> _customData[key] = data;
{
_customData[key] = data;
if (!QSBPatch.Remote)
{
new AddonCustomDataSyncMessage(PlayerId, key, data).Send();
}
}
public T GetCustomData<T>(string key)
{