From 07310df68a12c41ddf46277395f3bc4d52e1cb4b Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 17 Jun 2021 12:57:40 +0100 Subject: [PATCH] Added support for plugin parameters on update methods --- .../eco/internal/config/updating/ConfigHandler.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/eco-api/src/main/java/com/willfp/eco/internal/config/updating/ConfigHandler.java b/eco-api/src/main/java/com/willfp/eco/internal/config/updating/ConfigHandler.java index e49a736a..80dda28c 100644 --- a/eco-api/src/main/java/com/willfp/eco/internal/config/updating/ConfigHandler.java +++ b/eco-api/src/main/java/com/willfp/eco/internal/config/updating/ConfigHandler.java @@ -44,15 +44,18 @@ public class ConfigHandler extends PluginDependent { public void callUpdate() { updatableClasses.forEach(clazz -> Arrays.stream(clazz.getDeclaredMethods()).forEach(method -> { if (method.isAnnotationPresent(ConfigUpdater.class)) { - if (method.getParameterTypes().length != 0) { - throw new InvalidUpdateMethodException("Update method must not have parameters."); - } if (!Modifier.isStatic(method.getModifiers())) { throw new InvalidUpdateMethodException("Update method must be static."); } try { - method.invoke(null); + if (method.getParameterCount() == 0) { + method.invoke(null); + } else if (method.getParameterCount() == 1) { + method.invoke(null, this.getPlugin()); + } else { + throw new InvalidUpdateMethodException("Update method must have 0 parameters or a plugin parameter."); + } } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); throw new InvalidUpdateMethodException("Update method generated an exception."); @@ -69,7 +72,7 @@ public class ConfigHandler extends PluginDependent { public void registerUpdatableClass(@NotNull final Class updatableClass) { boolean isValid = false; for (Method method : updatableClass.getDeclaredMethods()) { - if (Modifier.isStatic(method.getModifiers()) && method.getParameterTypes().length == 0 && method.isAnnotationPresent(ConfigUpdater.class)) { + if (Modifier.isStatic(method.getModifiers()) && (method.getParameterCount() == 0 || method.getParameterCount() == 1) && method.isAnnotationPresent(ConfigUpdater.class)) { isValid = true; break; }