delay honorific changes to avoid serverspam
This commit is contained in:
@@ -17,6 +17,7 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
|
|||||||
private readonly CharacterData _playerData = new();
|
private readonly CharacterData _playerData = new();
|
||||||
private readonly Dictionary<ObjectKind, GameObjectHandler> _playerRelatedObjects = new();
|
private readonly Dictionary<ObjectKind, GameObjectHandler> _playerRelatedObjects = new();
|
||||||
private Task? _cacheCreationTask;
|
private Task? _cacheCreationTask;
|
||||||
|
private CancellationTokenSource _honorificCts = new();
|
||||||
private CancellationTokenSource _palettePlusCts = new();
|
private CancellationTokenSource _palettePlusCts = new();
|
||||||
|
|
||||||
public CacheCreationService(ILogger<CacheCreationService> logger, MareMediator mediator, Func<ObjectKind, Func<IntPtr>, bool, GameObjectHandler> gameObjectHandlerFactory,
|
public CacheCreationService(ILogger<CacheCreationService> logger, MareMediator mediator, Func<ObjectKind, Func<IntPtr>, bool, GameObjectHandler> gameObjectHandlerFactory,
|
||||||
@@ -64,7 +65,7 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
|
|||||||
Mediator.Subscribe<HonorificMessage>(this, async (_) =>
|
Mediator.Subscribe<HonorificMessage>(this, async (_) =>
|
||||||
{
|
{
|
||||||
Logger.LogDebug("Received Honorific change, updating player");
|
Logger.LogDebug("Received Honorific change, updating player");
|
||||||
await AddPlayerCacheToCreate().ConfigureAwait(false);
|
HonorificChanged();
|
||||||
});
|
});
|
||||||
Mediator.Subscribe<PenumbraModSettingChangedMessage>(this, async (msg) =>
|
Mediator.Subscribe<PenumbraModSettingChangedMessage>(this, async (msg) =>
|
||||||
{
|
{
|
||||||
@@ -97,6 +98,20 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
|
|||||||
_cacheCreateLock.Release();
|
_cacheCreateLock.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HonorificChanged()
|
||||||
|
{
|
||||||
|
_honorificCts?.Cancel();
|
||||||
|
_honorificCts?.Dispose();
|
||||||
|
_honorificCts = new();
|
||||||
|
var token = _honorificCts.Token;
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(3), token).ConfigureAwait(false);
|
||||||
|
await AddPlayerCacheToCreate().ConfigureAwait(false);
|
||||||
|
}, token);
|
||||||
|
}
|
||||||
|
|
||||||
private void PalettePlusChanged()
|
private void PalettePlusChanged()
|
||||||
{
|
{
|
||||||
_palettePlusCts?.Cancel();
|
_palettePlusCts?.Cancel();
|
||||||
|
|||||||
Reference in New Issue
Block a user