error check and more verbose error log

This commit is contained in:
XtraCube committed 2024-08-23 22:48:53 -04:00
1 parent d9fb89d86b
commit dcf6221671
1 file changed
+8 -1
+8 -1
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Reactor.Utilities;
namespace MiraAPI.Hud;
@@ -12,10 +13,16 @@ public static class CustomButtonManager
{
if (!typeof(CustomActionButton).IsAssignableFrom(buttonType))
{
Logger<MiraApiPlugin>.Error($"{buttonType?.Name} does not inherit from CustomActionButton.");
return;
}
var button = (CustomActionButton)Activator.CreateInstance(buttonType);
if (Activator.CreateInstance(buttonType) is not CustomActionButton button)
{
Logger<MiraApiPlugin>.Error($"Failed to create button from {buttonType.Name}");
return;
}
CustomButtons.Add(button);
typeof(CustomButtonSingleton<>).MakeGenericType(buttonType)
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!