Ignore errors when building DTR bar entry if AR isn't installed
This commit is contained in:
parent
e573b792d8
commit
fa4f8c2b2c
@ -8,6 +8,7 @@ using Dalamud.Game.Command;
|
||||
using Dalamud.Game.Gui.Dtr;
|
||||
using Dalamud.Game.Text;
|
||||
using Dalamud.Interface.ImGuiNotification;
|
||||
using Dalamud.Plugin.Ipc.Exceptions;
|
||||
using Dalamud.Plugin.Services;
|
||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||
|
||||
@ -75,6 +76,8 @@ internal sealed class CharacterSwitch : IDisposable
|
||||
}
|
||||
|
||||
private Target? FindCharacter(int direction, bool showError = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
_pluginLog.Verbose($"Switching characters ({direction})");
|
||||
|
||||
@ -105,6 +108,12 @@ internal sealed class CharacterSwitch : IDisposable
|
||||
|
||||
return new Target(target.Name, target.World);
|
||||
}
|
||||
catch (IpcError)
|
||||
{
|
||||
_chatGui.PrintError("Could not switch character, AutoRetainer API isn't available.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void NextCharacter(string command, string arguments) => SwitchCharacter(FindCharacter(1));
|
||||
|
||||
@ -118,6 +127,8 @@ internal sealed class CharacterSwitch : IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string[] args = arguments.Split(' ', 2);
|
||||
if (args.Length < 2 || !int.TryParse(args[1], CultureInfo.InvariantCulture, out int index))
|
||||
index = 1;
|
||||
@ -127,7 +138,8 @@ internal sealed class CharacterSwitch : IDisposable
|
||||
.Where(x => !x.ExcludeRetainer || !x.ExcludeWorkshop)
|
||||
.Select(x => new { x.Name, x.World })
|
||||
.ToList();
|
||||
var target = targets.Where(x => x.World.StartsWith(args[0], StringComparison.OrdinalIgnoreCase)).Skip(index - 1)
|
||||
var target = targets.Where(x => x.World.StartsWith(args[0], StringComparison.OrdinalIgnoreCase))
|
||||
.Skip(index - 1)
|
||||
.FirstOrDefault() ??
|
||||
targets.FirstOrDefault(x => x.Name.Contains(arguments, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
@ -139,6 +151,11 @@ internal sealed class CharacterSwitch : IDisposable
|
||||
|
||||
SwitchCharacter(new Target(target.Name, target.World));
|
||||
}
|
||||
catch (IpcError)
|
||||
{
|
||||
_chatGui.PrintError("Could not switch character, AutoRetainer API isn't available.");
|
||||
}
|
||||
}
|
||||
|
||||
private void SwitchCharacter(Target? target)
|
||||
{
|
||||
@ -173,6 +190,11 @@ internal sealed class CharacterSwitch : IDisposable
|
||||
}
|
||||
|
||||
private void UpdateDtrBar()
|
||||
{
|
||||
if (_dtrBarEntry.UserHidden)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
string? currentWorld = _clientState.LocalPlayer?.CurrentWorld.GameData?.Name?.ToString();
|
||||
string? homeWorld = _clientState.LocalPlayer?.HomeWorld.GameData?.Name?.ToString();
|
||||
@ -201,6 +223,14 @@ internal sealed class CharacterSwitch : IDisposable
|
||||
_dtrBarEntry.Text = $"{homeWorld} {seIconChar.ToIconString()}";
|
||||
_dtrBarEntry.Tooltip = $"Return to {homeWorld}";
|
||||
}
|
||||
|
||||
if (!_dtrBarEntry.Shown)
|
||||
_dtrBarEntry.Shown = true;
|
||||
}
|
||||
catch (IpcError)
|
||||
{
|
||||
_dtrBarEntry.Shown = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
Loading…
Reference in New Issue
Block a user