From ef6dedbd5541582f1d4abfd67ca7e189a25d28ee Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sat, 17 May 2025 22:40:02 -0400 Subject: [PATCH] add errors for incorrect usage of registrations --- MiraAPI/PluginLoading/MiraPluginManager.cs | 42 +++++++++++++++------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index bd2db7b..91767b0 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -53,21 +53,29 @@ public sealed class MiraPluginManager continue; } - foreach (var method in type.GetMethods(BindingFlags.Static | BindingFlags.Public)) + foreach (var method in type.GetMethods()) { var eventAttribute = method.GetCustomAttribute(); - if (eventAttribute != null) + if (eventAttribute == null) { - var parameters = method.GetParameters(); - if (parameters.Length != 1 || !parameters[0].ParameterType.IsSubclassOf(typeof(MiraEvent))) - { - Logger.Error($"Invalid event registration method {method.Name} in {type.Name}"); - continue; - } - - var paramType = parameters[0].ParameterType; - MiraEventManager.RegisterEventHandler(paramType, method, eventAttribute.Priority); + continue; } + + if (!method.IsStatic) + { + Logger.Error($"Event method {method.Name} in {type.Name} must be static."); + continue; + } + + var parameters = method.GetParameters(); + if (parameters.Length != 1 || !parameters[0].ParameterType.IsSubclassOf(typeof(MiraEvent))) + { + Logger.Error($"Invalid event registration method {method.Name} in {type.Name}"); + continue; + } + + var paramType = parameters[0].ParameterType; + MiraEventManager.RegisterEventHandler(paramType, method, eventAttribute.Priority); } if (RegisterModifier(type, info)) @@ -169,11 +177,16 @@ public sealed class MiraPluginManager ModdedOptionsManager.RegisterAttributeOption(type, attribute, property, pluginInfo); } + foreach (var field in type.GetFields().Where(f=>f.FieldType.IsAssignableTo(typeof(IModdedOption)))) + { + Logger.Error($"{field.Name} is a field, not a property. Use properties for options."); + } + return true; } catch (Exception e) { - Logger.Error($"Failed to register options for {type.Name}: {e}"); + Logger.Error($"Failed to register options for {type.Name}: {e.ToString()}"); } return false; } @@ -234,6 +247,11 @@ public sealed class MiraPluginManager PaletteManager.CustomColors.Add(color); } + + foreach (var field in type.GetFields().Where(f=>f.FieldType.IsAssignableTo(typeof(CustomColor)))) + { + Logger.Error($"{field.Name} is a field, not a property. Use properties for colors."); + } } catch (Exception e) {