From 39c725cd6535ba74a215c6d93dabf0718b7a9878 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 29 Dec 2020 14:14:55 +0000 Subject: [PATCH] Revert "Reworked Updatable system" This reverts commit aa3816a2 --- 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 | 54 ++++++++++++------- .../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, 141 insertions(+), 73 deletions(-) create mode 100644 eco-util/src/main/java/com/willfp/eco/util/config/annotations/ConfigUpdater.java delete mode 100644 eco-util/src/main/java/com/willfp/eco/util/config/annotations/Updatable.java create mode 100644 eco-util/src/main/java/com/willfp/eco/util/interfaces/Updatable.java diff --git a/build.gradle b/build.gradle index 72ab6fd9..bf219d78 100644 --- a/build.gradle +++ b/build.gradle @@ -87,7 +87,6 @@ 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 2195ab50..0583f123 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,17 +6,25 @@ 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; @@ -194,4 +202,18 @@ 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 293e3263..08d4b8f0 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,7 +3,8 @@ 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.Updatable; +import com.willfp.eco.util.config.annotations.ConfigUpdater; +import com.willfp.eco.util.interfaces.Updatable; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import org.bukkit.Bukkit; @@ -17,8 +18,7 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -@Updatable -public class TabCompleterEnchantinfo extends AbstractTabCompleter { +public class TabCompleterEnchantinfo extends AbstractTabCompleter implements Updatable { /** * The cached enchantment names. */ @@ -34,7 +34,8 @@ public class TabCompleterEnchantinfo extends AbstractTabCompleter { /** * Called on /ecoreload. */ - public static void update() { + @ConfigUpdater + public static void reload() { 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 481dffd8..19eb1cde 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,6 +1,7 @@ package com.willfp.ecoenchants.config; -import com.willfp.eco.util.config.annotations.Updatable; +import com.willfp.eco.util.config.annotations.ConfigUpdater; +import com.willfp.eco.util.interfaces.Updatable; import com.willfp.ecoenchants.config.configs.EnchantmentConfig; import com.willfp.ecoenchants.config.configs.Rarity; import com.willfp.ecoenchants.config.configs.Target; @@ -11,9 +12,8 @@ import org.jetbrains.annotations.NotNull; import java.util.HashSet; import java.util.Set; -@Updatable(methodName = "updateConfigs") @UtilityClass -public class EcoEnchantsConfigs { +public class EcoEnchantsConfigs implements Updatable { /** * target.yml. */ @@ -33,6 +33,7 @@ public class EcoEnchantsConfigs { /** * 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 1b06c006..c03afa57 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,7 +2,8 @@ package com.willfp.ecoenchants.display; import com.google.common.collect.Lists; import com.willfp.eco.util.NumberUtils; -import com.willfp.eco.util.config.annotations.Updatable; +import com.willfp.eco.util.config.annotations.ConfigUpdater; +import com.willfp.eco.util.interfaces.Updatable; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.ecoenchants.display.options.DisplayOptions; import com.willfp.ecoenchants.enchantments.EcoEnchant; @@ -23,9 +24,12 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; -@Updatable +/** + * All methods and fields pertaining to showing players the enchantments on their items. + */ +@SuppressWarnings("DeprecatedIsStillUsed") @UtilityClass -public class EnchantDisplay { +public class EnchantDisplay implements Updatable { /** * Instance of EcoEnchants. */ @@ -58,6 +62,7 @@ public class EnchantDisplay { /** * 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 089ca13b..e109fec7 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,7 +2,8 @@ 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.Updatable; +import com.willfp.eco.util.config.annotations.ConfigUpdater; +import com.willfp.eco.util.interfaces.Updatable; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; @@ -21,10 +22,9 @@ import java.util.List; import java.util.Optional; import java.util.Set; -@SuppressWarnings("deprecation") -@Updatable @UtilityClass -public class EnchantmentCache { +@SuppressWarnings("deprecation") +public class EnchantmentCache implements Updatable { /** * The physical cache. */ @@ -64,6 +64,7 @@ public class EnchantmentCache { /** * 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 ec487a13..9d7bb175 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,7 +4,8 @@ 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.Updatable; +import com.willfp.eco.util.config.annotations.ConfigUpdater; +import com.willfp.eco.util.interfaces.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; @@ -238,10 +239,9 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; -@Updatable @UtilityClass @SuppressWarnings({"unused", "checkstyle:JavadocVariable"}) -public class EcoEnchants { +public class EcoEnchants implements Updatable { public static final String CONFIG_LOCATION = "config."; public static final String OBTAINING_LOCATION = "obtaining."; public static final String GENERAL_LOCATION = "general-config."; @@ -550,6 +550,7 @@ public class EcoEnchants { /** * 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 7c72c1ef..723df32a 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,10 +2,11 @@ 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.Updatable; +import com.willfp.eco.util.config.annotations.ConfigUpdater; 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; @@ -15,8 +16,7 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; -@Updatable -public class EnchantmentRarity implements Registerable { +public class EnchantmentRarity implements Registerable, Updatable { /** * All registered rarities. */ @@ -134,6 +134,7 @@ public class EnchantmentRarity implements Registerable { /** * 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 3478096c..166a1aa5 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,8 +1,9 @@ package com.willfp.ecoenchants.enchantments.meta; import com.google.common.collect.ImmutableSet; -import com.willfp.eco.util.config.annotations.Updatable; +import com.willfp.eco.util.config.annotations.ConfigUpdater; 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; @@ -13,8 +14,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; -@Updatable -public class EnchantmentTarget implements Registerable { +public class EnchantmentTarget implements Registerable, Updatable { /** * All registered targets. */ @@ -77,6 +77,7 @@ public class EnchantmentTarget implements Registerable { /** * 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 aa85369e..3a609f9a 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,7 +2,8 @@ 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.Updatable; +import com.willfp.eco.util.config.annotations.ConfigUpdater; +import com.willfp.eco.util.interfaces.Updatable; import com.willfp.eco.util.lambda.ObjectCallable; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; @@ -14,8 +15,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; -@Updatable -public class EnchantmentType { +public class EnchantmentType implements Updatable { /** * All registered types. */ @@ -204,6 +204,7 @@ public class EnchantmentType { /** * 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 9a316d9e..09514688 100644 --- a/eco-util/build.gradle +++ b/eco-util/build.gradle @@ -8,7 +8,6 @@ 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' @@ -20,5 +19,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 fe59ee27..b2a3f37a 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,18 +1,26 @@ package com.willfp.eco.util.config; -import com.willfp.eco.util.config.annotations.Updatable; +import com.willfp.eco.util.config.annotations.ConfigUpdater; 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}. * @@ -26,35 +34,43 @@ public class ConfigHandler extends PluginDependent { * Invoke all update methods. */ public void callUpdate() { - 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())) { - continue; - } - + updatableClasses.forEach(clazz -> Arrays.stream(clazz.getDeclaredMethods()).forEach(method -> { + if (method.isAnnotationPresent(ConfigUpdater.class)) { if (method.getParameterTypes().length != 0) { - continue; + 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); - valid = true; - break; } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); throw new InvalidUpdateMethodException("Update method generated an exception."); } } + })); + } - if (!valid) { - throw new InvalidUpdatableClassException("No valid update method found! (Must be static, have no parameters)"); + /** + * 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 (!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 26cea7ac..6ed19530 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.Updatable; +import com.willfp.eco.util.config.annotations.ConfigUpdater; 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 { +public final class Configs implements Updatable { /** * The {@link BaseConfig} implementation for lang.yml. */ @@ -23,6 +23,7 @@ public final class Configs { * * @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 new file mode 100644 index 00000000..40d64862 --- /dev/null +++ b/eco-util/src/main/java/com/willfp/eco/util/config/annotations/ConfigUpdater.java @@ -0,0 +1,11 @@ +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 deleted file mode 100644 index 926c228b..00000000 --- a/eco-util/src/main/java/com/willfp/eco/util/config/annotations/Updatable.java +++ /dev/null @@ -1,19 +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.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 1104fd8d..94d0b5b8 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.Updatable; +import com.willfp.eco.util.config.annotations.ConfigUpdater; +import com.willfp.eco.util.interfaces.Updatable; import lombok.Getter; import lombok.experimental.UtilityClass; -@Updatable @UtilityClass -public final class DropManager { +public final class DropManager implements Updatable { /** * The currently used type, or implementation, of {@link AbstractDropQueue}. *

@@ -21,6 +21,7 @@ public final class DropManager { * * @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 new file mode 100644 index 00000000..5f97e64e --- /dev/null +++ b/eco-util/src/main/java/com/willfp/eco/util/interfaces/Updatable.java @@ -0,0 +1,4 @@ +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 c5147ca6..31bc0493 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,6 +12,8 @@ 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; @@ -37,6 +39,7 @@ 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; @@ -86,6 +89,11 @@ 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. */ @@ -232,12 +240,19 @@ 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(); } @@ -386,4 +401,11 @@ 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(); }