Update to newer Dalamud API

This commit is contained in:
Jade Macho 2023-11-14 00:07:11 +01:00
parent 9200d0048f
commit 1a63ecb560
Signed by: 0x0ade
GPG Key ID: 21C91DB3ADE0B6D5
7 changed files with 35 additions and 30 deletions

View File

@ -1,11 +1,12 @@
using Dalamud.Game.Command; using Dalamud.Game.Command;
using Dalamud.Plugin.Services;
using System; using System;
namespace PatMe2Mqtt namespace PatMe2Mqtt
{ {
public abstract class Cmd : IDisposable public abstract class Cmd : IDisposable
{ {
private CommandManager? _commandManager; private ICommandManager? _commandManager;
private string? _commandString; private string? _commandString;
public abstract string Name { get; } public abstract string Name { get; }
@ -13,7 +14,7 @@ namespace PatMe2Mqtt
public abstract string HelpMessage { get; } public abstract string HelpMessage { get; }
public void Register(CommandManager commandManager) public void Register(ICommandManager commandManager)
{ {
if (_commandManager is not null) if (_commandManager is not null)
{ {

View File

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Authors>0x0ade</Authors> <Authors>0x0ade</Authors>
<Company></Company> <Company></Company>
<Version>0.1.0.0</Version> <Version>0.1.0.1</Version>
<Description>Gluing PatMe and FFXIV2MQTT together.</Description> <Description>Gluing PatMe and FFXIV2MQTT together.</Description>
<Copyright></Copyright> <Copyright></Copyright>
<PackageProjectUrl></PackageProjectUrl> <PackageProjectUrl></PackageProjectUrl>
@ -25,7 +25,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.11" /> <PackageReference Include="DalamudPackager" Version="2.1.12" />
<Reference Include="FFXIVClientStructs"> <Reference Include="FFXIVClientStructs">
<HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath> <HintPath>$(DalamudLibPath)FFXIVClientStructs.dll</HintPath>
<Private>false</Private> <Private>false</Private>

View File

@ -3,7 +3,7 @@
"InternalName": "patme2mqtt", "InternalName": "patme2mqtt",
"Author": "0x0ade", "Author": "0x0ade",
"ApplicableVersion": "any", "ApplicableVersion": "any",
"DalamudApiLevel": 8, "DalamudApiLevel": 9,
"Punchline": "Gluing PatMe and FFXIV2MQTT together.", "Punchline": "Gluing PatMe and FFXIV2MQTT together.",
"Description": "Basic plugin that pokes FFXIV2MQTT every time PatMe detects a pat.", "Description": "Basic plugin that pokes FFXIV2MQTT every time PatMe detects a pat.",
"Tags": [ "pat", "emote", "mqtt", "patme", "ffxiv2mqtt" ], "Tags": [ "pat", "emote", "mqtt", "patme", "ffxiv2mqtt" ],

View File

@ -32,11 +32,11 @@ namespace PatMe2Mqtt.PatMeProxyApi
public bool Refresh() public bool Refresh()
{ {
PluginLog.LogInformation("Refreshing PatMeProxyApi"); Service.PluginLog.Information("Refreshing PatMeProxyApi");
if (Service.GetPluginInstance?.Invoke("PatMe") is not { } realPatMe) if (Service.GetPluginInstance?.Invoke("PatMe") is not { } realPatMe)
{ {
PluginLog.LogInformation("PatMe not found"); Service.PluginLog.Information("PatMe not found");
Unset(); Unset();
@ -49,18 +49,18 @@ namespace PatMe2Mqtt.PatMeProxyApi
if (_realPatMeServiceType is null) if (_realPatMeServiceType is null)
{ {
PluginLog.LogInformation("PatMe.Service not found"); Service.PluginLog.Information("PatMe.Service not found");
Unset(); Unset();
return false; return false;
} }
PluginLog.LogInformation($"PatMe found: {_realPatMeType.Assembly.FullName}"); Service.PluginLog.Information($"PatMe found: {_realPatMeType.Assembly.FullName}");
if (_lastPatMe?.Target != realPatMe) if (_lastPatMe?.Target != realPatMe)
{ {
PluginLog.LogInformation($"Different PatMe, clearing cache"); Service.PluginLog.Information($"Different PatMe, clearing cache");
ClearCache(); ClearCache();
@ -86,7 +86,7 @@ namespace PatMe2Mqtt.PatMeProxyApi
{ {
if (_realPatMeType?.Assembly.GetType(typeName) is not { } type) 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; return null;
} }
@ -103,7 +103,7 @@ namespace PatMe2Mqtt.PatMeProxyApi
{ {
if (_realPatMeType?.Assembly.GetType(typeName) is not { } type) 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; return null;
} }
@ -150,7 +150,7 @@ namespace PatMe2Mqtt.PatMeProxyApi
{ {
if (_realPatMeType?.Assembly.GetType(typeName) is not { } type) 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; return;
} }

View File

@ -73,7 +73,7 @@ namespace PatMe2Mqtt
} }
catch (Exception e) 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) 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) 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); Service.Framework.RunOnTick(SyncAll, delayTicks: 10);
} }

View File

@ -11,6 +11,7 @@ using Dalamud.Plugin;
using System.Reflection; using System.Reflection;
using System; using System;
using System.Collections; using System.Collections;
using Dalamud.Plugin.Services;
namespace PatMe2Mqtt namespace PatMe2Mqtt
{ {
@ -23,14 +24,14 @@ namespace PatMe2Mqtt
{ {
if (typeof(PluginServiceAttribute).Assembly.GetType("Dalamud.Service`1") is not { } serviceContainerContainer) 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; return;
} }
if (typeof(PluginServiceAttribute).Assembly.GetType("Dalamud.Plugin.Internal.PluginManager") is not { } pluginManagerType) 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; return;
} }
@ -38,7 +39,7 @@ namespace PatMe2Mqtt
if (typeof(PluginServiceAttribute).Assembly.GetType("Dalamud.Plugin.Internal.Types.LocalPlugin") is not { } localPluginType || if (typeof(PluginServiceAttribute).Assembly.GetType("Dalamud.Plugin.Internal.Types.LocalPlugin") is not { } localPluginType ||
localPluginType.GetField("instance", BindingFlags.NonPublic | BindingFlags.Instance) is not { } localPluginInstanceField) 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; return;
} }
@ -47,14 +48,14 @@ namespace PatMe2Mqtt
if (serviceContainerContainer.GetMethod("Get")?.Invoke(null, Array.Empty<object>()) is not object manager) if (serviceContainerContainer.GetMethod("Get")?.Invoke(null, Array.Empty<object>()) is not object manager)
{ {
PluginLog.LogInformation("PatMe2Mqtt couldn't obtain the plugin manager."); PluginLog.Information("PatMe2Mqtt couldn't obtain the plugin manager.");
return; return;
} }
if (pluginManagerType.GetProperty("InstalledPlugins") is not { } installedPluginsProperty) 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; return;
} }
@ -63,7 +64,7 @@ namespace PatMe2Mqtt
{ {
if (installedPluginsProperty?.GetValue(manager) is not IList installedPlugins) 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; return null;
} }
@ -81,7 +82,7 @@ namespace PatMe2Mqtt
} }
catch (Exception e) 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!; public static DalamudPluginInterface PluginInterface { get; private set; } = null!;
[PluginService] [PluginService]
public static CommandManager CommandManager { get; private set; } = null!; public static ICommandManager CommandManager { get; private set; } = null!;
[PluginService] [PluginService]
public static Framework Framework { get; private set; } = null!; public static IFramework Framework { get; private set; } = null!;
[PluginService] [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<string, object?>? GetPluginInstance { get; private set; } public static Func<string, object?>? GetPluginInstance { get; private set; }
} }

View File

@ -4,9 +4,9 @@
"net7.0-windows7.0": { "net7.0-windows7.0": {
"DalamudPackager": { "DalamudPackager": {
"type": "Direct", "type": "Direct",
"requested": "[2.1.11, )", "requested": "[2.1.12, )",
"resolved": "2.1.11", "resolved": "2.1.12",
"contentHash": "9qlAWoRRTiL/geAvuwR/g6Bcbrd/bJJgVnB/RurBiyKs6srsP0bvpoo8IK+Eg8EA6jWeM6/YJWs66w4FIAzqPw==" "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
} }
} }
} }