From 1a63ecb560a3f1f53fc478bf650ad4599ab4fcb8 Mon Sep 17 00:00:00 2001 From: Jade Macho Date: Tue, 14 Nov 2023 00:07:11 +0100 Subject: [PATCH] Update to newer Dalamud API --- PatMe2Mqtt/Cmd.cs | 5 +++-- PatMe2Mqtt/PatMe2Mqtt.csproj | 4 ++-- PatMe2Mqtt/PatMe2Mqtt.json | 2 +- PatMe2Mqtt/PatMeProxyApi/PatMe.cs | 16 ++++++++-------- PatMe2Mqtt/Plugin.cs | 8 ++++---- PatMe2Mqtt/Service.cs | 24 ++++++++++++++---------- PatMe2Mqtt/packages.lock.json | 6 +++--- 7 files changed, 35 insertions(+), 30 deletions(-) diff --git a/PatMe2Mqtt/Cmd.cs b/PatMe2Mqtt/Cmd.cs index cd3b9ec..5519880 100644 --- a/PatMe2Mqtt/Cmd.cs +++ b/PatMe2Mqtt/Cmd.cs @@ -1,11 +1,12 @@ using Dalamud.Game.Command; +using Dalamud.Plugin.Services; using System; namespace PatMe2Mqtt { public abstract class Cmd : IDisposable { - private CommandManager? _commandManager; + private ICommandManager? _commandManager; private string? _commandString; public abstract string Name { get; } @@ -13,7 +14,7 @@ namespace PatMe2Mqtt public abstract string HelpMessage { get; } - public void Register(CommandManager commandManager) + public void Register(ICommandManager commandManager) { if (_commandManager is not null) { diff --git a/PatMe2Mqtt/PatMe2Mqtt.csproj b/PatMe2Mqtt/PatMe2Mqtt.csproj index 94d3abc..74359a3 100644 --- a/PatMe2Mqtt/PatMe2Mqtt.csproj +++ b/PatMe2Mqtt/PatMe2Mqtt.csproj @@ -3,7 +3,7 @@ 0x0ade - 0.1.0.0 + 0.1.0.1 Gluing PatMe and FFXIV2MQTT together. @@ -25,7 +25,7 @@ - + $(DalamudLibPath)FFXIVClientStructs.dll false diff --git a/PatMe2Mqtt/PatMe2Mqtt.json b/PatMe2Mqtt/PatMe2Mqtt.json index 889470b..e9e0d8c 100644 --- a/PatMe2Mqtt/PatMe2Mqtt.json +++ b/PatMe2Mqtt/PatMe2Mqtt.json @@ -3,7 +3,7 @@ "InternalName": "patme2mqtt", "Author": "0x0ade", "ApplicableVersion": "any", - "DalamudApiLevel": 8, + "DalamudApiLevel": 9, "Punchline": "Gluing PatMe and FFXIV2MQTT together.", "Description": "Basic plugin that pokes FFXIV2MQTT every time PatMe detects a pat.", "Tags": [ "pat", "emote", "mqtt", "patme", "ffxiv2mqtt" ], diff --git a/PatMe2Mqtt/PatMeProxyApi/PatMe.cs b/PatMe2Mqtt/PatMeProxyApi/PatMe.cs index eb6c6d7..d3b8be7 100644 --- a/PatMe2Mqtt/PatMeProxyApi/PatMe.cs +++ b/PatMe2Mqtt/PatMeProxyApi/PatMe.cs @@ -32,11 +32,11 @@ namespace PatMe2Mqtt.PatMeProxyApi public bool Refresh() { - PluginLog.LogInformation("Refreshing PatMeProxyApi"); + Service.PluginLog.Information("Refreshing PatMeProxyApi"); if (Service.GetPluginInstance?.Invoke("PatMe") is not { } realPatMe) { - PluginLog.LogInformation("PatMe not found"); + Service.PluginLog.Information("PatMe not found"); Unset(); @@ -49,18 +49,18 @@ namespace PatMe2Mqtt.PatMeProxyApi if (_realPatMeServiceType is null) { - PluginLog.LogInformation("PatMe.Service not found"); + Service.PluginLog.Information("PatMe.Service not found"); Unset(); return false; } - PluginLog.LogInformation($"PatMe found: {_realPatMeType.Assembly.FullName}"); + Service.PluginLog.Information($"PatMe found: {_realPatMeType.Assembly.FullName}"); if (_lastPatMe?.Target != realPatMe) { - PluginLog.LogInformation($"Different PatMe, clearing cache"); + Service.PluginLog.Information($"Different PatMe, clearing cache"); ClearCache(); @@ -86,7 +86,7 @@ namespace PatMe2Mqtt.PatMeProxyApi { if (_realPatMeType?.Assembly.GetType(typeName) is not { } type) { - PluginLog.LogInformation($"GetStaticValue failed, type \"{typeName}\" not found"); + Service.PluginLog.Information($"GetStaticValue failed, type \"{typeName}\" not found"); return null; } @@ -103,7 +103,7 @@ namespace PatMe2Mqtt.PatMeProxyApi { if (_realPatMeType?.Assembly.GetType(typeName) is not { } type) { - PluginLog.LogInformation($"GetStaticValue failed, type \"{typeName}\" not found"); + Service.PluginLog.Information($"GetStaticValue failed, type \"{typeName}\" not found"); return null; } @@ -150,7 +150,7 @@ namespace PatMe2Mqtt.PatMeProxyApi { if (_realPatMeType?.Assembly.GetType(typeName) is not { } type) { - PluginLog.LogInformation($"GetStaticValue failed, type \"{typeName}\" not found"); + Service.PluginLog.Information($"GetStaticValue failed, type \"{typeName}\" not found"); return; } diff --git a/PatMe2Mqtt/Plugin.cs b/PatMe2Mqtt/Plugin.cs index e0b95e3..087a0d5 100644 --- a/PatMe2Mqtt/Plugin.cs +++ b/PatMe2Mqtt/Plugin.cs @@ -73,7 +73,7 @@ namespace PatMe2Mqtt } catch (Exception e) { - PluginLog.LogError(e, "PatMe2Mqtt couldn't SyncAll"); + Service.PluginLog.Error(e, "PatMe2Mqtt couldn't SyncAll"); } } @@ -96,7 +96,7 @@ namespace PatMe2Mqtt } catch (Exception e) { - PluginLog.LogError(e, "PatMe2Mqtt couldn't SyncByDescSingular({0})", descSingular); + Service.PluginLog.Error(e, "PatMe2Mqtt couldn't SyncByDescSingular({0})", descSingular); } } @@ -111,11 +111,11 @@ namespace PatMe2Mqtt } catch (Exception e) { - PluginLog.LogWarning(e, "PatMe2Mqtt couldn't Sync(\"{0}\", {1})", topic, value); + Service.PluginLog.Warning(e, "PatMe2Mqtt couldn't Sync(\"{0}\", {1})", topic, value); } } - private void OnLogIn(object? sender, EventArgs e) + private void OnLogIn() { Service.Framework.RunOnTick(SyncAll, delayTicks: 10); } diff --git a/PatMe2Mqtt/Service.cs b/PatMe2Mqtt/Service.cs index e56058d..a2f4a8e 100644 --- a/PatMe2Mqtt/Service.cs +++ b/PatMe2Mqtt/Service.cs @@ -11,6 +11,7 @@ using Dalamud.Plugin; using System.Reflection; using System; using System.Collections; +using Dalamud.Plugin.Services; namespace PatMe2Mqtt { @@ -23,14 +24,14 @@ namespace PatMe2Mqtt { if (typeof(PluginServiceAttribute).Assembly.GetType("Dalamud.Service`1") is not { } serviceContainerContainer) { - PluginLog.LogInformation("PatMe2Mqtt couldn't find the service container types."); + PluginLog.Information("PatMe2Mqtt couldn't find the service container types."); return; } if (typeof(PluginServiceAttribute).Assembly.GetType("Dalamud.Plugin.Internal.PluginManager") is not { } pluginManagerType) { - PluginLog.LogInformation("PatMe2Mqtt couldn't find the plugin manager type."); + PluginLog.Information("PatMe2Mqtt couldn't find the plugin manager type."); return; } @@ -38,7 +39,7 @@ namespace PatMe2Mqtt if (typeof(PluginServiceAttribute).Assembly.GetType("Dalamud.Plugin.Internal.Types.LocalPlugin") is not { } localPluginType || localPluginType.GetField("instance", BindingFlags.NonPublic | BindingFlags.Instance) is not { } localPluginInstanceField) { - PluginLog.LogInformation("PatMe2Mqtt couldn't find the local plugin type or important members."); + PluginLog.Information("PatMe2Mqtt couldn't find the local plugin type or important members."); return; } @@ -47,14 +48,14 @@ namespace PatMe2Mqtt if (serviceContainerContainer.GetMethod("Get")?.Invoke(null, Array.Empty()) is not object manager) { - PluginLog.LogInformation("PatMe2Mqtt couldn't obtain the plugin manager."); + PluginLog.Information("PatMe2Mqtt couldn't obtain the plugin manager."); return; } if (pluginManagerType.GetProperty("InstalledPlugins") is not { } installedPluginsProperty) { - PluginLog.LogInformation("PatMe2Mqtt couldn't obtain the plugin list property."); + PluginLog.Information("PatMe2Mqtt couldn't obtain the plugin list property."); return; } @@ -63,7 +64,7 @@ namespace PatMe2Mqtt { if (installedPluginsProperty?.GetValue(manager) is not IList installedPlugins) { - PluginLog.LogInformation("PatMe2Mqtt couldn't obtain the plugin list."); + PluginLog.Information("PatMe2Mqtt couldn't obtain the plugin list."); return null; } @@ -81,7 +82,7 @@ namespace PatMe2Mqtt } catch (Exception e) { - PluginLog.LogInformation($"PatMe2Mqtt couldn't obtain the plugin manager service: {e}"); + PluginLog.Information($"PatMe2Mqtt couldn't obtain the plugin manager service: {e}"); } } @@ -93,13 +94,16 @@ namespace PatMe2Mqtt public static DalamudPluginInterface PluginInterface { get; private set; } = null!; [PluginService] - public static CommandManager CommandManager { get; private set; } = null!; + public static ICommandManager CommandManager { get; private set; } = null!; [PluginService] - public static Framework Framework { get; private set; } = null!; + public static IFramework Framework { get; private set; } = null!; [PluginService] - public static ClientState ClientState { get; private set; } = null!; + public static IClientState ClientState { get; private set; } = null!; + + [PluginService] + public static IPluginLog PluginLog { get; private set; } = null!; public static Func? GetPluginInstance { get; private set; } } diff --git a/PatMe2Mqtt/packages.lock.json b/PatMe2Mqtt/packages.lock.json index 467f0f2..6cf1c73 100644 --- a/PatMe2Mqtt/packages.lock.json +++ b/PatMe2Mqtt/packages.lock.json @@ -4,9 +4,9 @@ "net7.0-windows7.0": { "DalamudPackager": { "type": "Direct", - "requested": "[2.1.11, )", - "resolved": "2.1.11", - "contentHash": "9qlAWoRRTiL/geAvuwR/g6Bcbrd/bJJgVnB/RurBiyKs6srsP0bvpoo8IK+Eg8EA6jWeM6/YJWs66w4FIAzqPw==" + "requested": "[2.1.12, )", + "resolved": "2.1.12", + "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" } } }