From aa3816a21d97ecd2b7cc1ae34d4c203129239f35 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 29 Dec 2020 14:00:39 +0000 Subject: [PATCH] Reworked Updatable system --- build.gradle | 1 + .../willfp/ecoenchants/EcoEnchantsPlugin.java | 22 -------- .../TabCompleterEnchantinfo.java | 9 ++-- .../config/EcoEnchantsConfigs.java | 7 ++- .../ecoenchants/display/EnchantDisplay.java | 11 ++-- .../ecoenchants/display/EnchantmentCache.java | 9 ++-- .../ecoenchants/enchantments/EcoEnchants.java | 7 ++- .../enchantments/meta/EnchantmentRarity.java | 7 ++- .../enchantments/meta/EnchantmentTarget.java | 7 ++- .../enchantments/meta/EnchantmentType.java | 7 ++- eco-util/build.gradle | 3 +- .../willfp/eco/util/config/ConfigHandler.java | 52 +++++++------------ .../com/willfp/eco/util/config/Configs.java | 7 ++- .../config/annotations/ConfigUpdater.java | 11 ---- .../util/config/annotations/Updatable.java | 19 +++++++ .../eco/util/drops/internal/DropManager.java | 7 ++- .../willfp/eco/util/interfaces/Updatable.java | 4 -- .../eco/util/plugin/AbstractEcoPlugin.java | 22 -------- 18 files changed, 72 insertions(+), 140 deletions(-) delete mode 100644 eco-util/src/main/java/com/willfp/eco/util/config/annotations/ConfigUpdater.java create mode 100644 eco-util/src/main/java/com/willfp/eco/util/config/annotations/Updatable.java delete mode 100644 eco-util/src/main/java/com/willfp/eco/util/interfaces/Updatable.java diff --git a/build.gradle b/build.gradle index bf219d78..72ab6fd9 100644 --- a/build.gradle +++ b/build.gradle @@ -87,6 +87,7 @@ clean.doLast { shadowJar { relocate('org.bstats.bukkit', 'com.willfp.eco.util.shaded.bstats') relocate('org.apache.maven', 'com.willfp.eco.util.shaded.maven') + relocate('org.reflections', 'com.willfp.eco.util.shaded.reflections') archiveFileName = findProperty("plugin-name") + " v" + findProperty("version") + ".jar" } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java index 0583f123..2195ab50 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java @@ -6,25 +6,17 @@ import com.willfp.eco.util.command.AbstractCommand; import com.willfp.eco.util.drops.telekinesis.TelekinesisTests; import com.willfp.eco.util.integrations.IntegrationLoader; import com.willfp.eco.util.interfaces.EcoRunnable; -import com.willfp.eco.util.interfaces.Updatable; import com.willfp.eco.util.packets.AbstractPacketAdapter; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.command.commands.CommandEcodebug; import com.willfp.ecoenchants.command.commands.CommandEcoreload; import com.willfp.ecoenchants.command.commands.CommandEnchantinfo; -import com.willfp.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo; -import com.willfp.ecoenchants.config.EcoEnchantsConfigs; -import com.willfp.ecoenchants.display.EnchantDisplay; -import com.willfp.ecoenchants.display.EnchantmentCache; import com.willfp.ecoenchants.display.packets.PacketChat; import com.willfp.ecoenchants.display.packets.PacketOpenWindowMerchant; import com.willfp.ecoenchants.display.packets.PacketSetCreativeSlot; import com.willfp.ecoenchants.display.packets.PacketSetSlot; import com.willfp.ecoenchants.display.packets.PacketWindowItems; import com.willfp.ecoenchants.enchantments.EcoEnchants; -import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; -import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; -import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.support.merging.anvil.AnvilListeners; import com.willfp.ecoenchants.enchantments.support.merging.grindstone.GrindstoneListeners; import com.willfp.ecoenchants.enchantments.support.obtaining.EnchantingListeners; @@ -202,18 +194,4 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin { new VillagerListeners() ); } - - @Override - public List> getUpdatableClasses() { - return Arrays.asList( - EcoEnchantsConfigs.class, - EnchantmentCache.class, - EnchantmentRarity.class, - EnchantmentTarget.class, - EcoEnchants.class, - EnchantDisplay.class, - TabCompleterEnchantinfo.class, - EnchantmentType.class - ); - } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/tabcompleters/TabCompleterEnchantinfo.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/tabcompleters/TabCompleterEnchantinfo.java index 08d4b8f0..293e3263 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/tabcompleters/TabCompleterEnchantinfo.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/tabcompleters/TabCompleterEnchantinfo.java @@ -3,8 +3,7 @@ package com.willfp.ecoenchants.command.tabcompleters; import com.willfp.eco.util.StringUtils; import com.willfp.eco.util.command.AbstractCommand; import com.willfp.eco.util.command.AbstractTabCompleter; -import com.willfp.eco.util.config.annotations.ConfigUpdater; -import com.willfp.eco.util.interfaces.Updatable; +import com.willfp.eco.util.config.annotations.Updatable; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import org.bukkit.Bukkit; @@ -18,7 +17,8 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -public class TabCompleterEnchantinfo extends AbstractTabCompleter implements Updatable { +@Updatable +public class TabCompleterEnchantinfo extends AbstractTabCompleter { /** * The cached enchantment names. */ @@ -34,8 +34,7 @@ public class TabCompleterEnchantinfo extends AbstractTabCompleter implements Upd /** * Called on /ecoreload. */ - @ConfigUpdater - public static void reload() { + public static void update() { ENCHANT_NAMES.clear(); ENCHANT_NAMES.addAll(EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).collect(Collectors.toList())); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EcoEnchantsConfigs.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EcoEnchantsConfigs.java index 19eb1cde..481dffd8 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EcoEnchantsConfigs.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EcoEnchantsConfigs.java @@ -1,7 +1,6 @@ package com.willfp.ecoenchants.config; -import com.willfp.eco.util.config.annotations.ConfigUpdater; -import com.willfp.eco.util.interfaces.Updatable; +import com.willfp.eco.util.config.annotations.Updatable; import com.willfp.ecoenchants.config.configs.EnchantmentConfig; import com.willfp.ecoenchants.config.configs.Rarity; import com.willfp.ecoenchants.config.configs.Target; @@ -12,8 +11,9 @@ import org.jetbrains.annotations.NotNull; import java.util.HashSet; import java.util.Set; +@Updatable(methodName = "updateConfigs") @UtilityClass -public class EcoEnchantsConfigs implements Updatable { +public class EcoEnchantsConfigs { /** * target.yml. */ @@ -33,7 +33,6 @@ public class EcoEnchantsConfigs implements Updatable { /** * Update all configs. */ - @ConfigUpdater public void updateConfigs() { TARGET.update(); RARITY.update(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index c03afa57..1b06c006 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -2,8 +2,7 @@ package com.willfp.ecoenchants.display; import com.google.common.collect.Lists; import com.willfp.eco.util.NumberUtils; -import com.willfp.eco.util.config.annotations.ConfigUpdater; -import com.willfp.eco.util.interfaces.Updatable; +import com.willfp.eco.util.config.annotations.Updatable; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.display.options.DisplayOptions; import com.willfp.ecoenchants.enchantments.EcoEnchant; @@ -24,12 +23,9 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; -/** - * All methods and fields pertaining to showing players the enchantments on their items. - */ -@SuppressWarnings("DeprecatedIsStillUsed") +@Updatable @UtilityClass -public class EnchantDisplay implements Updatable { +public class EnchantDisplay { /** * Instance of EcoEnchants. */ @@ -62,7 +58,6 @@ public class EnchantDisplay implements Updatable { /** * Update config values. */ - @ConfigUpdater public static void update() { OPTIONS.update(); EnchantmentCache.update(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java index e109fec7..089ca13b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java @@ -2,8 +2,7 @@ package com.willfp.ecoenchants.display; import com.google.common.collect.ImmutableSet; import com.willfp.eco.util.config.Configs; -import com.willfp.eco.util.config.annotations.ConfigUpdater; -import com.willfp.eco.util.interfaces.Updatable; +import com.willfp.eco.util.config.annotations.Updatable; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; @@ -22,9 +21,10 @@ import java.util.List; import java.util.Optional; import java.util.Set; -@UtilityClass @SuppressWarnings("deprecation") -public class EnchantmentCache implements Updatable { +@Updatable +@UtilityClass +public class EnchantmentCache { /** * The physical cache. */ @@ -64,7 +64,6 @@ public class EnchantmentCache implements Updatable { /** * Update the cache. */ - @ConfigUpdater public static void update() { CACHE.clear(); Arrays.asList(Enchantment.values()).parallelStream().forEach(enchantment -> { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java index 9d7bb175..ec487a13 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -4,8 +4,7 @@ package com.willfp.ecoenchants.enchantments; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableList; -import com.willfp.eco.util.config.annotations.ConfigUpdater; -import com.willfp.eco.util.interfaces.Updatable; +import com.willfp.eco.util.config.annotations.Updatable; import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.AshArtifact; import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.CloudsArtifact; import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.CrimsonArtifact; @@ -239,9 +238,10 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; +@Updatable @UtilityClass @SuppressWarnings({"unused", "checkstyle:JavadocVariable"}) -public class EcoEnchants implements Updatable { +public class EcoEnchants { public static final String CONFIG_LOCATION = "config."; public static final String OBTAINING_LOCATION = "obtaining."; public static final String GENERAL_LOCATION = "general-config."; @@ -550,7 +550,6 @@ public class EcoEnchants implements Updatable { /** * Update all {@link EcoEnchant}s. */ - @ConfigUpdater public static void update() { for (EcoEnchant ecoEnchant : new HashSet<>(values())) { ecoEnchant.update(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java index 723df32a..7c72c1ef 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java @@ -2,11 +2,10 @@ package com.willfp.ecoenchants.enchantments.meta; import com.willfp.eco.util.NumberUtils; import com.willfp.eco.util.StringUtils; -import com.willfp.eco.util.config.annotations.ConfigUpdater; +import com.willfp.eco.util.config.annotations.Updatable; import com.willfp.eco.util.integrations.placeholder.PlaceholderEntry; import com.willfp.eco.util.integrations.placeholder.PlaceholderManager; import com.willfp.eco.util.interfaces.Registerable; -import com.willfp.eco.util.interfaces.Updatable; import com.willfp.ecoenchants.config.EcoEnchantsConfigs; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -16,7 +15,8 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; -public class EnchantmentRarity implements Registerable, Updatable { +@Updatable +public class EnchantmentRarity implements Registerable { /** * All registered rarities. */ @@ -134,7 +134,6 @@ public class EnchantmentRarity implements Registerable, Updatable { /** * Update all rarities. */ - @ConfigUpdater public static void update() { Set raritiesNames = EcoEnchantsConfigs.RARITY.getRarities(); raritiesNames.forEach(rarity -> { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentTarget.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentTarget.java index 166a1aa5..3478096c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentTarget.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentTarget.java @@ -1,9 +1,8 @@ package com.willfp.ecoenchants.enchantments.meta; import com.google.common.collect.ImmutableSet; -import com.willfp.eco.util.config.annotations.ConfigUpdater; +import com.willfp.eco.util.config.annotations.Updatable; import com.willfp.eco.util.interfaces.Registerable; -import com.willfp.eco.util.interfaces.Updatable; import com.willfp.ecoenchants.config.EcoEnchantsConfigs; import lombok.Getter; import org.bukkit.Material; @@ -14,7 +13,8 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; -public class EnchantmentTarget implements Registerable, Updatable { +@Updatable +public class EnchantmentTarget implements Registerable { /** * All registered targets. */ @@ -77,7 +77,6 @@ public class EnchantmentTarget implements Registerable, Updatable { /** * Update all targets. */ - @ConfigUpdater public static void update() { Set targetNames = EcoEnchantsConfigs.TARGET.getTargets(); ALL.materials.clear(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java index 3a609f9a..aa85369e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java @@ -2,8 +2,7 @@ package com.willfp.ecoenchants.enchantments.meta; import com.google.common.collect.ImmutableList; import com.willfp.eco.util.config.Configs; -import com.willfp.eco.util.config.annotations.ConfigUpdater; -import com.willfp.eco.util.interfaces.Updatable; +import com.willfp.eco.util.config.annotations.Updatable; import com.willfp.eco.util.lambda.ObjectCallable; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; @@ -15,7 +14,8 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; -public class EnchantmentType implements Updatable { +@Updatable +public class EnchantmentType { /** * All registered types. */ @@ -204,7 +204,6 @@ public class EnchantmentType implements Updatable { /** * Update callables of all types. */ - @ConfigUpdater public static void update() { REGISTERED.forEach(EnchantmentType::refresh); } diff --git a/eco-util/build.gradle b/eco-util/build.gradle index 09514688..9a316d9e 100644 --- a/eco-util/build.gradle +++ b/eco-util/build.gradle @@ -8,6 +8,7 @@ repositories { dependencies { implementation 'org.apache.maven:maven-artifact:3.0.3' implementation 'org.bstats:bstats-bukkit:1.7' + implementation 'org.reflections:reflections:0.9.12' compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT' compileOnly 'me.clip:placeholderapi:2.10.9' compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT' @@ -19,5 +20,5 @@ dependencies { compileOnly 'com.github.angeschossen:LandsAPI:4.7.3' compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT' compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd' - compileOnly fileTree(dir: '/../lib', include: ['*.jar']) + compileOnly fileTree(dir: '../lib', include: ['*.jar']) } \ No newline at end of file diff --git a/eco-util/src/main/java/com/willfp/eco/util/config/ConfigHandler.java b/eco-util/src/main/java/com/willfp/eco/util/config/ConfigHandler.java index b2a3f37a..fe59ee27 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/config/ConfigHandler.java +++ b/eco-util/src/main/java/com/willfp/eco/util/config/ConfigHandler.java @@ -1,26 +1,18 @@ package com.willfp.eco.util.config; -import com.willfp.eco.util.config.annotations.ConfigUpdater; +import com.willfp.eco.util.config.annotations.Updatable; import com.willfp.eco.util.config.annotations.InvalidUpdatableClassException; import com.willfp.eco.util.config.annotations.InvalidUpdateMethodException; import com.willfp.eco.util.injection.PluginDependent; -import com.willfp.eco.util.interfaces.Updatable; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import org.jetbrains.annotations.NotNull; +import org.reflections.Reflections; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; public class ConfigHandler extends PluginDependent { - /** - * A set of all classes that can be updated. - */ - private final Set> updatableClasses = new HashSet<>(); - /** * Creates a new config handler and links it to an {@link AbstractEcoPlugin}. * @@ -34,43 +26,35 @@ public class ConfigHandler extends PluginDependent { * Invoke all update methods. */ 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."); + for (Class clazz : new Reflections("com.willfp").getTypesAnnotatedWith(Updatable.class)) { + boolean valid = false; + + for (Method method : clazz.getDeclaredMethods()) { + if (!method.isAnnotationPresent(Updatable.class)) { + continue; } + if (!Modifier.isStatic(method.getModifiers())) { - throw new InvalidUpdateMethodException("Update method must be static."); + continue; + } + + if (method.getParameterTypes().length != 0) { + continue; } try { method.invoke(null); + valid = true; + break; } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); throw new InvalidUpdateMethodException("Update method generated an exception."); } } - })); - } - /** - * Register an updatable class. - * - * @param updatableClass The class with an update method. - */ - 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)) { - isValid = true; - break; + if (!valid) { + throw new InvalidUpdatableClassException("No valid update method found! (Must be static, have no parameters)"); } } - - if (!isValid) { - throw new InvalidUpdatableClassException("Registered updatable class " + updatableClass + " must have an annotated static method with no modifiers."); - } - - updatableClasses.add(updatableClass); } } diff --git a/eco-util/src/main/java/com/willfp/eco/util/config/Configs.java b/eco-util/src/main/java/com/willfp/eco/util/config/Configs.java index 6ed19530..26cea7ac 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/config/Configs.java +++ b/eco-util/src/main/java/com/willfp/eco/util/config/Configs.java @@ -1,13 +1,13 @@ package com.willfp.eco.util.config; -import com.willfp.eco.util.config.annotations.ConfigUpdater; +import com.willfp.eco.util.config.annotations.Updatable; import com.willfp.eco.util.config.configs.Config; import com.willfp.eco.util.config.configs.Lang; -import com.willfp.eco.util.interfaces.Updatable; import lombok.experimental.UtilityClass; +@Updatable @UtilityClass -public final class Configs implements Updatable { +public final class Configs { /** * The {@link BaseConfig} implementation for lang.yml. */ @@ -23,7 +23,6 @@ public final class Configs implements Updatable { * * @see BaseConfig */ - @ConfigUpdater public void update() { LANG.update(); CONFIG.update(); diff --git a/eco-util/src/main/java/com/willfp/eco/util/config/annotations/ConfigUpdater.java b/eco-util/src/main/java/com/willfp/eco/util/config/annotations/ConfigUpdater.java deleted file mode 100644 index 40d64862..00000000 --- a/eco-util/src/main/java/com/willfp/eco/util/config/annotations/ConfigUpdater.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.willfp.eco.util.config.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface ConfigUpdater { -} diff --git a/eco-util/src/main/java/com/willfp/eco/util/config/annotations/Updatable.java b/eco-util/src/main/java/com/willfp/eco/util/config/annotations/Updatable.java new file mode 100644 index 00000000..926c228b --- /dev/null +++ b/eco-util/src/main/java/com/willfp/eco/util/config/annotations/Updatable.java @@ -0,0 +1,19 @@ +package com.willfp.eco.util.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Updatable { + /** + * The static, no-parameter method to be called on config update. + *

+ * Default is update. + * + * @return The method name. + */ + String methodName() default "update"; +} diff --git a/eco-util/src/main/java/com/willfp/eco/util/drops/internal/DropManager.java b/eco-util/src/main/java/com/willfp/eco/util/drops/internal/DropManager.java index 94d0b5b8..1104fd8d 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/drops/internal/DropManager.java +++ b/eco-util/src/main/java/com/willfp/eco/util/drops/internal/DropManager.java @@ -1,13 +1,13 @@ package com.willfp.eco.util.drops.internal; import com.willfp.eco.util.config.Configs; -import com.willfp.eco.util.config.annotations.ConfigUpdater; -import com.willfp.eco.util.interfaces.Updatable; +import com.willfp.eco.util.config.annotations.Updatable; import lombok.Getter; import lombok.experimental.UtilityClass; +@Updatable @UtilityClass -public final class DropManager implements Updatable { +public final class DropManager { /** * The currently used type, or implementation, of {@link AbstractDropQueue}. *

@@ -21,7 +21,6 @@ public final class DropManager implements Updatable { * * @see DropQueueType */ - @ConfigUpdater public void update() { type = Configs.CONFIG.getBool("drops.collate") ? DropQueueType.COLLATED : DropQueueType.STANDARD; } diff --git a/eco-util/src/main/java/com/willfp/eco/util/interfaces/Updatable.java b/eco-util/src/main/java/com/willfp/eco/util/interfaces/Updatable.java deleted file mode 100644 index 5f97e64e..00000000 --- a/eco-util/src/main/java/com/willfp/eco/util/interfaces/Updatable.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.willfp.eco.util.interfaces; - -public interface Updatable { -} diff --git a/eco-util/src/main/java/com/willfp/eco/util/plugin/AbstractEcoPlugin.java b/eco-util/src/main/java/com/willfp/eco/util/plugin/AbstractEcoPlugin.java index 31bc0493..c5147ca6 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/plugin/AbstractEcoPlugin.java +++ b/eco-util/src/main/java/com/willfp/eco/util/plugin/AbstractEcoPlugin.java @@ -12,8 +12,6 @@ import com.willfp.eco.util.bukkit.scheduling.RunnableFactory; import com.willfp.eco.util.bukkit.scheduling.Scheduler; import com.willfp.eco.util.command.AbstractCommand; import com.willfp.eco.util.config.ConfigHandler; -import com.willfp.eco.util.config.Configs; -import com.willfp.eco.util.drops.internal.DropManager; import com.willfp.eco.util.drops.internal.FastCollatedDropQueue; import com.willfp.eco.util.drops.telekinesis.EcoTelekinesisTests; import com.willfp.eco.util.drops.telekinesis.TelekinesisTests; @@ -39,7 +37,6 @@ import com.willfp.eco.util.integrations.antigrief.plugins.AntigriefTowny; import com.willfp.eco.util.integrations.antigrief.plugins.AntigriefWorldGuard; import com.willfp.eco.util.integrations.placeholder.PlaceholderManager; import com.willfp.eco.util.integrations.placeholder.plugins.PlaceholderIntegrationPAPI; -import com.willfp.eco.util.interfaces.Updatable; import com.willfp.eco.util.optional.Prerequisite; import com.willfp.eco.util.packets.AbstractPacketAdapter; import com.willfp.eco.util.updater.UpdateChecker; @@ -89,11 +86,6 @@ public abstract class AbstractEcoPlugin extends JavaPlugin { */ private final List integrations = new ArrayList<>(); - /** - * Set of external plugin integrations. - */ - private final List> updatableClasses = new ArrayList<>(); - /** * The internal plugin logger. */ @@ -240,19 +232,12 @@ public abstract class AbstractEcoPlugin extends JavaPlugin { } }); - - updatableClasses.add(Configs.class); - updatableClasses.add(DropManager.class); - updatableClasses.addAll(this.getUpdatableClasses()); - this.getListeners().forEach(listener -> this.getEventManager().registerListener(listener)); this.getCommands().forEach(AbstractCommand::register); this.getScheduler().runLater(this::afterLoad, 1); - this.updatableClasses.forEach(clazz -> this.getConfigHandler().registerUpdatableClass(clazz)); - this.enable(); } @@ -401,11 +386,4 @@ public abstract class AbstractEcoPlugin extends JavaPlugin { * @return A list of all listeners. */ public abstract List getListeners(); - - /** - * All updatable classes. - * - * @return A list of all updatable classes. - */ - public abstract List> getUpdatableClasses(); }