Updated extensions to use new constructor

This commit is contained in:
Auxilor
2020-12-12 11:43:14 +00:00
parent 7ab1a35686
commit ae3ffd2954
22 changed files with 60 additions and 56 deletions

View File

@@ -1,6 +1,5 @@
package com.willfp.ecoenchants.enchantments;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
@@ -9,6 +8,7 @@ import com.willfp.ecoenchants.enchantments.util.Watcher;
import com.willfp.ecoenchants.util.StringUtils;
import com.willfp.ecoenchants.util.interfaces.ObjectCallable;
import com.willfp.ecoenchants.util.interfaces.Registerable;
import com.willfp.ecoenchants.util.internal.Logger;
import com.willfp.ecoenchants.util.optional.Prerequisite;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
@@ -25,14 +25,7 @@ import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
@SuppressWarnings({"unchecked", "deprecation"})
@@ -59,31 +52,18 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
/**
* Create a new EcoEnchant that exists within the base plugin
* Create a new EcoEnchant
*
* @param key The key name of the enchantment
* @param type The type of the enchantment
* @param prerequisites Optional {@link Prerequisite}s that must be met
*/
@ApiStatus.Internal
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Prerequisite... prerequisites) {
this(key, type, EcoEnchantsPlugin.class, prerequisites);
}
/**
* Create a new EcoEnchant that exists within an extension or external plugin
*
* @param key The key name of the enchantment
* @param type The type of the enchantment
* @param plugin The Main class of the {@link org.bukkit.plugin.Plugin} or {@link com.willfp.ecoenchants.extensions.Extension} that the enchantment was created by
* @param prerequisites Optional {@link Prerequisite}s that must be met
*/
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Class<?> plugin, Prerequisite... prerequisites) {
super(NamespacedKey.minecraft(key));
this.type = type;
this.permissionName = key.replaceAll("_", "");
ConfigManager.addEnchantmentConfig(new EnchantmentConfig(this.permissionName, plugin, this.type));
ConfigManager.addEnchantmentConfig(new EnchantmentConfig(this.permissionName, this.getClass(), this.type));
this.config = ConfigManager.getEnchantmentConfig(this.permissionName);
if (Bukkit.getPluginManager().getPermission("ecoenchants.fromtable." + permissionName) == null) {
@@ -103,6 +83,25 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
EcoEnchants.addNewEcoEnchant(this);
}
/**
* Create a new EcoEnchant that exists within an extension or external plugin
*
* @param key The key name of the enchantment
* @param type The type of the enchantment
* @param plugin Unused value
* @param prerequisites Optional {@link Prerequisite}s that must be met
*
* @deprecated Specifying the source class is no longer needed
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.8.0")
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Class<?> plugin, Prerequisite... prerequisites) {
this(key, type, prerequisites);
Logger.warn("Enchantment " + key + " (Generated by " + plugin.getName() + ") is using a legacy constructor!");
Logger.warn("Update your extensions - support for legacy enchantments will be removed in subsequent versions.");
}
/**
* Update the enchantment based off config values
* This can be overriden but may lead to unexpected behavior
@@ -257,6 +256,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
* If enchantment conflicts with any enchantment in set
*
* @param enchantments The set to test against
*
* @return If there are any conflicts
*/
public boolean conflictsWithAny(Set<? extends Enchantment> enchantments) {
@@ -344,6 +344,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
* Only here for compatibility with {@link Enchantment}
*
* @return Returns {@link EnchantmentTarget#ALL}. Do not use.
*
* @deprecated {@link EnchantmentTarget} is not supported due to its lack of flexibility. Use {@link EcoEnchant#getTarget()} instead.
*/
@Override
@@ -354,6 +355,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
/**
* @return false
*
* @deprecated Treasure enchantments do not exist. Use {@link EcoEnchant#getType()} instead.
*/
@Override
@@ -364,6 +366,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
/**
* @return Returns if enchantment is cursed.
*
* @deprecated Use {@link EcoEnchant#getType()} instead.
*/
@Override
@@ -376,6 +379,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
* Get if enchantment conflicts with specified enchantment
*
* @param enchantment The enchantment to test against
*
* @return If conflicts
*/
@Override
@@ -387,6 +391,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
* If enchantment can be applied to item
*
* @param itemStack The {@link ItemStack} to test against
*
* @return If can be applied
*/
@Override

View File

@@ -35,11 +35,7 @@ public abstract class Artifact extends EcoEnchant {
private Particle.DustOptions extra;
protected Artifact(String key, Prerequisite... prerequisites) {
this(key, EcoEnchantsPlugin.class, prerequisites);
}
protected Artifact(String key, Class<?> plugin, Prerequisite... prerequisites) {
super(key, EnchantmentType.ARTIFACT, plugin, prerequisites);
super(key, EnchantmentType.ARTIFACT, prerequisites);
if(!Prerequisite.areMet(prerequisites)) {
HandlerList.unregisterAll(this); // Prevent events firing
@@ -50,6 +46,12 @@ public abstract class Artifact extends EcoEnchant {
this.extra = this.getDustOptions();
}
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.8.0")
protected Artifact(String key, Class<?> plugin, Prerequisite... prerequisites) {
this(key, prerequisites);
}
public abstract Particle getParticle();
public Particle.DustOptions getDustOptions() {

View File

@@ -37,11 +37,13 @@ public abstract class Spell extends EcoEnchant {
);
protected Spell(String key, Prerequisite... prerequisites) {
this(key, EcoEnchantsPlugin.class, prerequisites);
super(key, EnchantmentType.SPELL, prerequisites);
}
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.8.0")
protected Spell(String key, Class<?> plugin, Prerequisite... prerequisites) {
super(key, EnchantmentType.SPELL, plugin, prerequisites);
this(key, prerequisites);
}
public int getCooldownTime() {