mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-16 04:31:22 +01:00
Implemented new config updater system
This commit is contained in:
parent
7367f8feef
commit
f0fae2ccbd
@ -6,6 +6,7 @@ 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;
|
||||
@ -118,16 +119,7 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin {
|
||||
* Code executed on /ecoreload.
|
||||
*/
|
||||
@Override
|
||||
public void reload() {
|
||||
EcoEnchantsConfigs.updateConfigs();
|
||||
EnchantmentCache.update();
|
||||
EnchantmentRarity.update();
|
||||
EnchantmentTarget.update();
|
||||
EcoEnchants.update();
|
||||
EnchantDisplay.update();
|
||||
TabCompleterEnchantinfo.reload();
|
||||
EnchantmentType.update();
|
||||
|
||||
public void onReload() {
|
||||
EcoEnchants.values().forEach((ecoEnchant -> {
|
||||
HandlerList.unregisterAll(ecoEnchant);
|
||||
|
||||
@ -209,4 +201,18 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin {
|
||||
new VillagerListeners()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<? extends Updatable>> getUpdatableClasses() {
|
||||
return Arrays.asList(
|
||||
EcoEnchantsConfigs.class,
|
||||
EnchantmentCache.class,
|
||||
EnchantmentRarity.class,
|
||||
EnchantmentTarget.class,
|
||||
EcoEnchants.class,
|
||||
EnchantDisplay.class,
|
||||
TabCompleterEnchantinfo.class,
|
||||
EnchantmentType.class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +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.ConfigUpdater;
|
||||
import com.willfp.eco.util.interfaces.Updatable;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -16,13 +18,14 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TabCompleterEnchantinfo extends AbstractTabCompleter {
|
||||
public class TabCompleterEnchantinfo extends AbstractTabCompleter implements Updatable {
|
||||
private static final List<String> enchantsNames = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).collect(Collectors.toList());
|
||||
|
||||
public TabCompleterEnchantinfo() {
|
||||
super((AbstractCommand) Objects.requireNonNull(Bukkit.getPluginCommand("enchantinfo")).getExecutor());
|
||||
}
|
||||
|
||||
@ConfigUpdater
|
||||
public static void reload() {
|
||||
enchantsNames.clear();
|
||||
enchantsNames.addAll(EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).collect(Collectors.toList()));
|
||||
@ -32,7 +35,7 @@ public class TabCompleterEnchantinfo extends AbstractTabCompleter {
|
||||
public List<String> onTab(@NotNull CommandSender sender, @NotNull List<String> args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
if (args.size() == 0) {
|
||||
if (args.isEmpty()) {
|
||||
// Currently, this case is not ever reached
|
||||
return enchantsNames;
|
||||
}
|
||||
|
@ -1,79 +1,62 @@
|
||||
package com.willfp.ecoenchants.config;
|
||||
|
||||
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;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class EcoEnchantsConfigs {
|
||||
private static final Target TARGET = new Target();
|
||||
private static final Rarity RARITY = new Rarity();
|
||||
private static final Set<EnchantmentConfig> enchantmentConfigs = new HashSet<>();
|
||||
@UtilityClass
|
||||
public class EcoEnchantsConfigs implements Updatable {
|
||||
/**
|
||||
* target.yml.
|
||||
*/
|
||||
public final Target TARGET = new Target();
|
||||
|
||||
/**
|
||||
* Update all configs
|
||||
* Called on /ecoreload
|
||||
* rarity.yml.
|
||||
*/
|
||||
public static void updateConfigs() {
|
||||
public final Rarity RARITY = new Rarity();
|
||||
|
||||
/**
|
||||
* All enchantment-specific configs.
|
||||
*/
|
||||
@Getter
|
||||
private final Set<EnchantmentConfig> enchantmentConfigs = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Update all configs.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public void updateConfigs() {
|
||||
TARGET.update();
|
||||
RARITY.update();
|
||||
updateEnchantmentConfigs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update enchantment configs
|
||||
*/
|
||||
public static void updateEnchantmentConfigs() {
|
||||
enchantmentConfigs.forEach((EnchantmentYamlConfig::update));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all enchantment configs
|
||||
* Get EnchantmentConfig matching permission name.
|
||||
*
|
||||
* @return Set of all enchantment configs
|
||||
*/
|
||||
public static Set<EnchantmentConfig> getEnchantmentConfigs() {
|
||||
return enchantmentConfigs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get EnchantmentConfig matching permission name
|
||||
*
|
||||
* @param permissionName The permission name to match
|
||||
*
|
||||
* @return The matching {@link EnchantmentConfig}
|
||||
* @param permissionName The permission name to match.
|
||||
* @return The matching {@link EnchantmentConfig}.
|
||||
*/
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||
public static EnchantmentConfig getEnchantmentConfig(String permissionName) {
|
||||
public EnchantmentConfig getEnchantmentConfig(@NotNull final String permissionName) {
|
||||
return enchantmentConfigs.stream().filter(config -> config.getName().equalsIgnoreCase(permissionName)).findFirst().get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new enchantment config yml
|
||||
* Adds new enchantment config yml.
|
||||
*
|
||||
* @param config The config to add
|
||||
* @param config The config to add.
|
||||
*/
|
||||
public static void addEnchantmentConfig(EnchantmentConfig config) {
|
||||
public void addEnchantmentConfig(@NotNull final EnchantmentConfig config) {
|
||||
enchantmentConfigs.add(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get target.yml
|
||||
*
|
||||
* @return target.yml
|
||||
*/
|
||||
public static Target getTarget() {
|
||||
return TARGET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rarity.yml
|
||||
*
|
||||
* @return rarity.yml
|
||||
*/
|
||||
public static Rarity getRarity() {
|
||||
return RARITY;
|
||||
}
|
||||
}
|
@ -2,6 +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.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;
|
||||
@ -24,7 +26,7 @@ import java.util.List;
|
||||
* All methods and fields pertaining to showing players the enchantments on their items.
|
||||
*/
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
public class EnchantDisplay {
|
||||
public class EnchantDisplay implements Updatable {
|
||||
private static final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
|
||||
|
||||
/**
|
||||
@ -58,6 +60,7 @@ public class EnchantDisplay {
|
||||
/**
|
||||
* Update config values
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
OPTIONS.update();
|
||||
EnchantmentCache.update();
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.willfp.ecoenchants.display;
|
||||
|
||||
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.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
@ -15,8 +17,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class EnchantmentCache {
|
||||
public class EnchantmentCache implements Updatable {
|
||||
private static final Set<CacheEntry> CACHE = new HashSet<>();
|
||||
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||
@ -29,6 +30,7 @@ public class EnchantmentCache {
|
||||
return new HashSet<>(CACHE);
|
||||
}
|
||||
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
CACHE.clear();
|
||||
Arrays.asList(Enchantment.values()).parallelStream().forEach(enchantment -> {
|
||||
|
@ -4,6 +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.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;
|
||||
@ -239,7 +241,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
* Contains general methods for EcoEnchants
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
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.";
|
||||
@ -555,6 +557,7 @@ public class EcoEnchants {
|
||||
* Update all {@link EcoEnchant}s
|
||||
* Called on /ecoreload
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
for (EcoEnchant ecoEnchant : new HashSet<>(values())) {
|
||||
ecoEnchant.update();
|
||||
|
@ -2,9 +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.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 java.util.HashSet;
|
||||
@ -14,7 +16,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Class for storing all enchantment rarities
|
||||
*/
|
||||
public class EnchantmentRarity implements Registerable {
|
||||
public class EnchantmentRarity implements Registerable, Updatable {
|
||||
private static final Set<EnchantmentRarity> rarities = new HashSet<>();
|
||||
|
||||
private final String name;
|
||||
@ -151,17 +153,17 @@ public class EnchantmentRarity implements Registerable {
|
||||
* Update all rarities
|
||||
* Called on /ecoreload
|
||||
*/
|
||||
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
Set<String> raritiesNames = EcoEnchantsConfigs.getRarity().getRarities();
|
||||
Set<String> raritiesNames = EcoEnchantsConfigs.RARITY.getRarities();
|
||||
raritiesNames.forEach((rarity) -> {
|
||||
double probability = EcoEnchantsConfigs.getRarity().getDouble("rarities." + rarity + ".table-probability");
|
||||
int minimumLevel = EcoEnchantsConfigs.getRarity().getInt("rarities." + rarity + ".minimum-level");
|
||||
double villagerProbability = EcoEnchantsConfigs.getRarity().getDouble("rarities." + rarity + ".villager-probability");
|
||||
double lootProbability = EcoEnchantsConfigs.getRarity().getDouble("rarities." + rarity + ".loot-probability");
|
||||
double probability = EcoEnchantsConfigs.RARITY.getDouble("rarities." + rarity + ".table-probability");
|
||||
int minimumLevel = EcoEnchantsConfigs.RARITY.getInt("rarities." + rarity + ".minimum-level");
|
||||
double villagerProbability = EcoEnchantsConfigs.RARITY.getDouble("rarities." + rarity + ".villager-probability");
|
||||
double lootProbability = EcoEnchantsConfigs.RARITY.getDouble("rarities." + rarity + ".loot-probability");
|
||||
String customColor = null;
|
||||
if (EcoEnchantsConfigs.getRarity().getBool("rarities." + rarity + ".custom-color.enabled")) {
|
||||
customColor = StringUtils.translate(EcoEnchantsConfigs.getRarity().getString("rarities." + rarity + ".custom-color.color"));
|
||||
if (EcoEnchantsConfigs.RARITY.getBool("rarities." + rarity + ".custom-color.enabled")) {
|
||||
customColor = StringUtils.translate(EcoEnchantsConfigs.RARITY.getString("rarities." + rarity + ".custom-color.color"));
|
||||
}
|
||||
|
||||
new EnchantmentRarity(rarity, probability, minimumLevel, villagerProbability, lootProbability, customColor).register();
|
||||
|
@ -1,7 +1,9 @@
|
||||
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.interfaces.Registerable;
|
||||
import com.willfp.eco.util.interfaces.Updatable;
|
||||
import com.willfp.ecoenchants.config.EcoEnchantsConfigs;
|
||||
import org.bukkit.Material;
|
||||
|
||||
@ -13,7 +15,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Class for storing all enchantment rarities
|
||||
*/
|
||||
public class EnchantmentTarget implements Registerable {
|
||||
public class EnchantmentTarget implements Registerable, Updatable {
|
||||
private static final Set<EnchantmentTarget> targets = new HashSet<>();
|
||||
public static final EnchantmentTarget ALL = new EnchantmentTarget("all", new HashSet<>());
|
||||
|
||||
@ -79,11 +81,12 @@ public class EnchantmentTarget implements Registerable {
|
||||
* Update all targets
|
||||
* Called on /ecoreload
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
Set<String> targetNames = EcoEnchantsConfigs.getTarget().getTargets();
|
||||
Set<String> targetNames = EcoEnchantsConfigs.TARGET.getTargets();
|
||||
ALL.materials.clear();
|
||||
targetNames.forEach((name) -> {
|
||||
Set<Material> materials = EcoEnchantsConfigs.getTarget().getTargetMaterials(name);
|
||||
Set<Material> materials = EcoEnchantsConfigs.TARGET.getTargetMaterials(name);
|
||||
new EnchantmentTarget(name, materials).register();
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.willfp.ecoenchants.enchantments.meta;
|
||||
|
||||
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.lambda.ObjectCallable;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
@ -9,7 +11,7 @@ import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EnchantmentType {
|
||||
public class EnchantmentType implements Updatable {
|
||||
private static final List<EnchantmentType> values = new ArrayList<>();
|
||||
|
||||
public static final EnchantmentType NORMAL = new EnchantmentType("normal", false, () -> Configs.LANG.getString("not-curse-color"));
|
||||
@ -115,6 +117,7 @@ public class EnchantmentType {
|
||||
return requiredToExtend;
|
||||
}
|
||||
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
values.forEach(EnchantmentType::refresh);
|
||||
}
|
||||
|
@ -0,0 +1,75 @@
|
||||
package com.willfp.eco.util.config;
|
||||
|
||||
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 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<Class<? extends Updatable>> updatableClasses = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Creates a new config handler and links it to an {@link AbstractEcoPlugin}.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public ConfigHandler(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.");
|
||||
}
|
||||
if (!Modifier.isStatic(method.getModifiers())) {
|
||||
throw new InvalidUpdateMethodException("Update method must be static.");
|
||||
}
|
||||
|
||||
try {
|
||||
method.invoke(null);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
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<? extends Updatable> 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);
|
||||
}
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
package com.willfp.eco.util.config;
|
||||
|
||||
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;
|
||||
|
||||
@UtilityClass
|
||||
public final class Configs {
|
||||
public final class Configs implements Updatable {
|
||||
/**
|
||||
* The {@link BaseConfig} implementation for lang.yml.
|
||||
*/
|
||||
@ -21,6 +23,7 @@ public final class Configs {
|
||||
*
|
||||
* @see BaseConfig
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public void update() {
|
||||
LANG.update();
|
||||
CONFIG.update();
|
||||
|
@ -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 {
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.willfp.eco.util.config.annotations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InvalidUpdatableClassException extends RuntimeException {
|
||||
/**
|
||||
* Called when an updatable class is registered into an {@link com.willfp.eco.util.config.ConfigHandler}.
|
||||
*
|
||||
* @param message The error message.
|
||||
*/
|
||||
public InvalidUpdatableClassException(@NotNull final String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.eco.util.config.annotations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InvalidUpdateMethodException extends RuntimeException {
|
||||
/**
|
||||
* Throws a new invalid update method exception.
|
||||
* <p>
|
||||
* Causes include:
|
||||
* Update method with parameters.
|
||||
* Update method is not static.
|
||||
*
|
||||
* @param message The error message to show.
|
||||
*/
|
||||
public InvalidUpdateMethodException(@NotNull final String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -1,31 +1,28 @@
|
||||
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 lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
public final class DropManager {
|
||||
@UtilityClass
|
||||
public final class DropManager implements Updatable {
|
||||
/**
|
||||
* The currently used type, or implementation, of {@link AbstractDropQueue}.
|
||||
* <p>
|
||||
* Standard by default, used if drops.collate key is not present in config.
|
||||
*/
|
||||
@Getter
|
||||
private static DropQueueType type = DropQueueType.STANDARD;
|
||||
private DropQueueType type = DropQueueType.STANDARD;
|
||||
|
||||
/**
|
||||
* Update the type of drop queue that should be used.
|
||||
*
|
||||
* @see DropQueueType
|
||||
*/
|
||||
public static void update() {
|
||||
@ConfigUpdater
|
||||
public void update() {
|
||||
type = Configs.CONFIG.getBool("drops.collate") ? DropQueueType.COLLATED : DropQueueType.STANDARD;
|
||||
}
|
||||
|
||||
static {
|
||||
update();
|
||||
}
|
||||
|
||||
private DropManager() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
package com.willfp.eco.util.interfaces;
|
||||
|
||||
public interface Updatable {
|
||||
}
|
@ -11,6 +11,7 @@ import com.willfp.eco.util.bukkit.scheduling.EcoScheduler;
|
||||
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;
|
||||
@ -38,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;
|
||||
@ -87,6 +89,11 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
*/
|
||||
private final List<IntegrationLoader> integrations = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Set of external plugin integrations.
|
||||
*/
|
||||
private final List<Class<? extends Updatable>> updatableClasses = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The internal plugin logger.
|
||||
*/
|
||||
@ -131,6 +138,12 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private final ExtensionLoader extensionLoader;
|
||||
|
||||
/**
|
||||
* The handler class for updatable classes.
|
||||
*/
|
||||
@Getter
|
||||
private final ConfigHandler configHandler;
|
||||
|
||||
/**
|
||||
* If the server is running an outdated version of the plugin.
|
||||
*/
|
||||
@ -158,6 +171,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
this.metadataValueFactory = new MetadataValueFactory(this);
|
||||
this.runnableFactory = new RunnableFactory(this);
|
||||
this.extensionLoader = new EcoExtensionLoader(this);
|
||||
this.configHandler = new ConfigHandler(this);
|
||||
|
||||
if (!Bukkit.getServicesManager().isProvidedFor(TelekinesisTests.class)) {
|
||||
Bukkit.getServicesManager().register(TelekinesisTests.class, new EcoTelekinesisTests(), this, ServicePriority.Normal);
|
||||
@ -232,6 +246,8 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
|
||||
this.getScheduler().runLater(this::afterLoad, 1);
|
||||
|
||||
this.getUpdatableClasses().forEach(clazz -> this.getConfigHandler().registerUpdatableClass(clazz));
|
||||
|
||||
this.enable();
|
||||
}
|
||||
|
||||
@ -265,7 +281,9 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
*/
|
||||
public final void afterLoad() {
|
||||
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
|
||||
if (abstractPacketAdapter.isPostLoad()) abstractPacketAdapter.register();
|
||||
if (abstractPacketAdapter.isPostLoad()) {
|
||||
abstractPacketAdapter.register();
|
||||
}
|
||||
});
|
||||
|
||||
if (!Prerequisite.HasPaper.isMet()) {
|
||||
@ -291,9 +309,8 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
/**
|
||||
* Default code to be executed on plugin reload.
|
||||
*/
|
||||
public final void onReload() {
|
||||
Configs.update();
|
||||
DropManager.update();
|
||||
public final void reload() {
|
||||
this.getConfigHandler().callUpdate();
|
||||
this.getScheduler().cancelAll();
|
||||
new FastCollatedDropQueue.CollatedRunnable(this);
|
||||
|
||||
@ -325,6 +342,17 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
return integrations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default updatable classes that exist within internal libraries.
|
||||
*
|
||||
* @return The default updatable classes.
|
||||
*/
|
||||
public final List<Class<? extends Updatable>> getDefaultUpdatableClasses() {
|
||||
updatableClasses.add(Configs.class);
|
||||
updatableClasses.add(DropManager.class);
|
||||
return updatableClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on enable.
|
||||
*/
|
||||
@ -343,7 +371,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
/**
|
||||
* The plugin-specific code to be executed on reload.
|
||||
*/
|
||||
public abstract void reload();
|
||||
public abstract void onReload();
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed after the server is up.
|
||||
@ -379,4 +407,11 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
* @return A list of all listeners.
|
||||
*/
|
||||
public abstract List<Listener> getListeners();
|
||||
|
||||
/**
|
||||
* All updatable classes.
|
||||
*
|
||||
* @return A list of all updatable classes.
|
||||
*/
|
||||
public abstract List<Class<? extends Updatable>> getUpdatableClasses();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user