Fix /dbq clear

This commit is contained in:
Liza 2024-10-05 21:03:04 +02:00
parent 3e5717542c
commit 61b6b2115a
Signed by: liza
GPG Key ID: 7199F8D727D55F67
3 changed files with 40 additions and 7 deletions

View File

@ -1,14 +1,17 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Reflection;
using Dalamud.Game.Command; using Dalamud.Game.Command;
using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Ipc; using Dalamud.Plugin.Ipc;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game;
using LLib;
namespace KitchenSink.Commands; namespace KitchenSink.Commands;
@ -28,12 +31,15 @@ internal sealed class DropboxQueue : IDisposable
private readonly IChatGui _chatGui; private readonly IChatGui _chatGui;
private readonly DropboxApi _dropboxApi; private readonly DropboxApi _dropboxApi;
public DropboxQueue(IDalamudPluginInterface pluginInterface, ICommandManager commandManager, IChatGui chatGui, public DropboxQueue(IDalamudPluginInterface pluginInterface,
DalamudReflector reflector,
ICommandManager commandManager,
IChatGui chatGui,
IPluginLog pluginLog) IPluginLog pluginLog)
{ {
_commandManager = commandManager; _commandManager = commandManager;
_chatGui = chatGui; _chatGui = chatGui;
_dropboxApi = new DropboxApi(pluginInterface, pluginLog); _dropboxApi = new DropboxApi(pluginInterface, reflector, pluginLog);
_commandManager.AddHandler("/dbq", new CommandInfo(Queue) _commandManager.AddHandler("/dbq", new CommandInfo(Queue)
{ {
@ -64,7 +70,7 @@ internal sealed class DropboxQueue : IDisposable
BuildRequest(parts.Length == 2 ? parts[1] : string.Empty); BuildRequest(parts.Length == 2 ? parts[1] : string.Empty);
break; break;
case "clear": case "clear":
//_dropboxApi.ClearQueue(); _dropboxApi.ClearQueue();
break; break;
default: default:
AddToQueue(arguments); AddToQueue(arguments);
@ -233,13 +239,15 @@ internal sealed class DropboxQueue : IDisposable
private sealed class DropboxApi private sealed class DropboxApi
{ {
private readonly DalamudReflector _reflector;
private readonly IPluginLog _pluginLog; private readonly IPluginLog _pluginLog;
private readonly ICallGateSubscriber<object> _beginTradingQueue; private readonly ICallGateSubscriber<object> _beginTradingQueue;
private readonly ICallGateSubscriber<uint,bool,int> _getItemQuantity; private readonly ICallGateSubscriber<uint,bool,int> _getItemQuantity;
private readonly ICallGateSubscriber<uint,bool,int, object> _setItemQuantity; private readonly ICallGateSubscriber<uint,bool,int, object> _setItemQuantity;
public DropboxApi(IDalamudPluginInterface pluginInterface, IPluginLog pluginLog) public DropboxApi(IDalamudPluginInterface pluginInterface, DalamudReflector reflector, IPluginLog pluginLog)
{ {
_reflector = reflector;
_pluginLog = pluginLog; _pluginLog = pluginLog;
_beginTradingQueue = pluginInterface.GetIpcSubscriber<object>("Dropbox.BeginTradingQueue"); _beginTradingQueue = pluginInterface.GetIpcSubscriber<object>("Dropbox.BeginTradingQueue");
@ -258,5 +266,27 @@ internal sealed class DropboxQueue : IDisposable
int currentQuantity = _getItemQuantity.InvokeFunc(itemId, hq); int currentQuantity = _getItemQuantity.InvokeFunc(itemId, hq);
_setItemQuantity.InvokeAction(itemId, hq, quantity + currentQuantity); _setItemQuantity.InvokeAction(itemId, hq, quantity + currentQuantity);
} }
public void ClearQueue()
{
if (TryGetItemQuantities(out _, out IDictionary? itemQuantities))
itemQuantities.Clear();
}
private bool TryGetItemQuantities([NotNullWhen(true)] out IDalamudPlugin? dropboxPlugin,
[NotNullWhen(true)] out IDictionary? itemQuantities)
{
if (!_reflector.TryGetDalamudPlugin("Dropbox", out dropboxPlugin))
{
itemQuantities = null;
return false;
}
var itemQueueUiType = dropboxPlugin.GetType().Assembly.GetType("Dropbox.ItemQueueUI")!;
itemQuantities =
(IDictionary?)itemQueueUiType.GetField("ItemQuantities", BindingFlags.Public | BindingFlags.Static)!
.GetValue(null);
return itemQuantities != null;
}
} }
} }

View File

@ -1,6 +1,6 @@
<Project Sdk="Dalamud.NET.Sdk/9.0.2"> <Project Sdk="Dalamud.NET.Sdk/9.0.2">
<PropertyGroup> <PropertyGroup>
<Version>1.0</Version> <Version>1.1</Version>
<OutputPath>dist</OutputPath> <OutputPath>dist</OutputPath>
</PropertyGroup> </PropertyGroup>

View File

@ -4,6 +4,7 @@ using Dalamud.Plugin;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using ECommons; using ECommons;
using KitchenSink.Commands; using KitchenSink.Commands;
using LLib;
namespace KitchenSink; namespace KitchenSink;
@ -17,13 +18,15 @@ internal sealed class KitchenSinkPlugin : IDalamudPlugin
public KitchenSinkPlugin(IDalamudPluginInterface pluginInterface, ICommandManager commandManager, public KitchenSinkPlugin(IDalamudPluginInterface pluginInterface, ICommandManager commandManager,
IClientState clientState, IChatGui chatGui, INotificationManager notificationManager, IDtrBar dtrBar, IClientState clientState, IChatGui chatGui, INotificationManager notificationManager, IDtrBar dtrBar,
ICondition condition, IPluginLog pluginLog) ICondition condition, IFramework framework, IPluginLog pluginLog)
{ {
DalamudReflector reflector = new DalamudReflector(pluginInterface, framework, pluginLog);
ECommonsMain.Init(pluginInterface, this); ECommonsMain.Init(pluginInterface, this);
_autoRetainerApi = new AutoRetainerApi(); _autoRetainerApi = new AutoRetainerApi();
_characterSwitch = new CharacterSwitch(_autoRetainerApi, commandManager, clientState, chatGui, _characterSwitch = new CharacterSwitch(_autoRetainerApi, commandManager, clientState, chatGui,
notificationManager, dtrBar, condition, pluginLog); notificationManager, dtrBar, condition, pluginLog);
_dropboxQueue = new DropboxQueue(pluginInterface, commandManager, chatGui, pluginLog); _dropboxQueue = new DropboxQueue(pluginInterface, reflector, commandManager, chatGui, pluginLog);
} }
public void Dispose() public void Dispose()