Disabled the pair request on already paired users

This commit is contained in:
CakeAndBanana
2025-10-01 02:47:11 +02:00
parent dea4ef4832
commit e91d163763
3 changed files with 17 additions and 9 deletions

View File

@@ -147,7 +147,7 @@ public sealed class Plugin : IDalamudPlugin
collection.AddSingleton<RedrawManager>();
collection.AddSingleton<BroadcastService>();
collection.AddSingleton(addonLifecycle);
collection.AddSingleton(p => new ContextMenu(contextMenu, pluginInterface, gameData, p.GetRequiredService<ILogger<ContextMenu>>(), p.GetRequiredService<DalamudUtilService>(), p.GetRequiredService<ApiController>(), objectTable, p.GetRequiredService<LightlessConfigService>()));
collection.AddSingleton(p => new ContextMenu(contextMenu, pluginInterface, gameData, p.GetRequiredService<ILogger<ContextMenu>>(), p.GetRequiredService<DalamudUtilService>(), p.GetRequiredService<ApiController>(), objectTable, p.GetRequiredService<LightlessConfigService>(), p.GetRequiredService<PairManager>()));
collection.AddSingleton((s) => new IpcCallerPenumbra(s.GetRequiredService<ILogger<IpcCallerPenumbra>>(), pluginInterface,
s.GetRequiredService<DalamudUtilService>(), s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<RedrawManager>()));
collection.AddSingleton((s) => new IpcCallerGlamourer(s.GetRequiredService<ILogger<IpcCallerGlamourer>>(), pluginInterface,

View File

@@ -40,7 +40,6 @@ public class NameplateService : DisposableMediatorSubscriberBase
private void OnNamePlateUpdate(INamePlateUpdateContext context, IReadOnlyList<INamePlateUpdateHandler> handlers)
{
if (!_configService.Current.IsNameplateColorsEnabled || (_configService.Current.IsNameplateColorsEnabled && _clientState.IsPvPExcludingDen))
return;
@@ -78,7 +77,6 @@ public class NameplateService : DisposableMediatorSubscriberBase
public void RequestRedraw()
{
_namePlateGui.RequestRedraw();
}

View File

@@ -3,13 +3,13 @@ using Dalamud.Game.Gui.ContextMenu;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using LightlessSync.LightlessConfiguration;
using LightlessSync.PlayerData.Pairs;
using LightlessSync.Services;
using LightlessSync.Utils;
using LightlessSync.WebAPI;
using Lumina.Excel.Sheets;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Linq;
namespace LightlessSync.UI;
@@ -21,16 +21,17 @@ internal class ContextMenu : IHostedService
private readonly ILogger<ContextMenu> _logger;
private readonly DalamudUtilService _dalamudUtil;
private readonly LightlessConfigService _configService;
private readonly PairManager _pairManager;
private readonly ApiController _apiController;
private readonly IObjectTable _objectTable;
private static readonly string[] ValidAddons = new[]
{
private static readonly string[] _validAddons =
[
null,
"PartyMemberList", "FriendList", "FreeCompany", "LinkShell", "CrossWorldLinkshell",
"_PartyList", "ChatLog", "LookingForGroup", "BlackList", "ContentMemberList",
"SocialList", "ContactList", "BeginnerChatList", "MuteList"
};
];
public ContextMenu(
IContextMenu contextMenu,
@@ -40,7 +41,8 @@ internal class ContextMenu : IHostedService
DalamudUtilService dalamudUtil,
ApiController apiController,
IObjectTable objectTable,
LightlessConfigService configService)
LightlessConfigService configService,
PairManager pairManager)
{
_contextMenu = contextMenu;
_pluginInterface = pluginInterface;
@@ -50,6 +52,7 @@ internal class ContextMenu : IHostedService
_apiController = apiController;
_objectTable = objectTable;
_configService = configService;
_pairManager = pairManager;
}
public Task StartAsync(CancellationToken cancellationToken)
@@ -81,7 +84,7 @@ internal class ContextMenu : IHostedService
if (!_pluginInterface.UiBuilder.ShouldModifyUi)
return;
if (!ValidAddons.Contains(args.AddonName, StringComparer.Ordinal))
if (!_validAddons.Contains(args.AddonName, StringComparer.Ordinal))
return;
if (args.Target is not MenuTargetDefault target)
@@ -94,6 +97,9 @@ internal class ContextMenu : IHostedService
if (targetData == null || targetData.Address == IntPtr.Zero)
return;
if (VisibleUserIds.Any(u => u == target.TargetObjectId))
return;
var world = GetWorld(target.TargetHomeWorld.RowId);
if (!IsWorldValid(world))
return;
@@ -138,6 +144,10 @@ internal class ContextMenu : IHostedService
_logger.LogError(ex, "Error sending pair request.");
}
}
private HashSet<ulong> VisibleUserIds => _pairManager.GetOnlineUserPairs()
.Where(u => u.IsVisible && u.PlayerCharacterId != uint.MaxValue)
.Select(u => (ulong)u.PlayerCharacterId)
.ToHashSet();
private IPlayerCharacter? GetPlayerFromObjectTable(MenuTargetDefault target)
{