Fix issue where non-existent retainers could cause plugin to not work properly

This commit is contained in:
Liza 2024-01-20 02:34:27 +01:00
parent 37e9f29d41
commit e78cd642cd
Signed by: liza
GPG Key ID: 7199F8D727D55F67
3 changed files with 18 additions and 3 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<Version>3.1</Version> <Version>3.2</Version>
<LangVersion>11.0</LangVersion> <LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

View File

@ -44,9 +44,13 @@ partial class AutoRetainerControlPlugin
save = true; save = true;
} }
// remove retainers without name
save |= character.Retainers.RemoveAll(x => string.IsNullOrEmpty(x.Name)) > 0;
// migrate legacy retainers // migrate legacy retainers
foreach (var legacyRetainer in character.Retainers.Where(x => x.RetainerContentId == 0)) foreach (var legacyRetainer in character.Retainers.Where(x => x.RetainerContentId == 0))
{ {
_pluginLog.Information($"Migrating retainer '{legacyRetainer.Name}' (char: {character})");
var retainerData = var retainerData =
offlineCharacterData.RetainerData.SingleOrDefault(x => legacyRetainer.Name == x.Name); offlineCharacterData.RetainerData.SingleOrDefault(x => legacyRetainer.Name == x.Name);
if (retainerData != null) if (retainerData != null)
@ -71,7 +75,7 @@ partial class AutoRetainerControlPlugin
} }
List<ulong> unknownRetainerIds = offlineCharacterData.RetainerData.Select(x => x.RetainerID).Where(x => x != 0).ToList(); List<ulong> unknownRetainerIds = offlineCharacterData.RetainerData.Select(x => x.RetainerID).Where(x => x != 0).ToList();
foreach (var retainerData in offlineCharacterData.RetainerData) foreach (var retainerData in offlineCharacterData.RetainerData.Where(x => !string.IsNullOrEmpty(x.Name)))
{ {
unknownRetainerIds.Remove(retainerData.RetainerID); unknownRetainerIds.Remove(retainerData.RetainerID);

View File

@ -74,7 +74,18 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin
}); });
if (_autoRetainerApi.Ready) if (_autoRetainerApi.Ready)
Sync(); {
try
{
Sync();
}
catch (Exception e)
{
_pluginLog.Error(e, "Unable to sync characters");
_chatGui.PrintError(
"Unable to synchronize characters with AutoRetainer, plugin might not work properly.");
}
}
} }
private void SendRetainerToVenture(string retainerName) private void SendRetainerToVenture(string retainerName)