Updated all extensions and kept legacy registration - will be removed in next version

This commit is contained in:
Auxilor 2020-12-11 19:02:51 +00:00
parent 6117ad924f
commit 05bd8f31be
25 changed files with 146 additions and 34 deletions

View File

@ -13,7 +13,7 @@ import org.bukkit.potion.PotionEffect;
public class Alchemy extends EcoEnchant {
public Alchemy() {
super("alchemy", EnchantmentType.NORMAL, AlchemyMain.class);
super("alchemy", EnchantmentType.NORMAL, AlchemyMain.getInstance());
}
private static final FixedMetadataValue TRUE = new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true);

View File

@ -1,3 +1,3 @@
name: Alchemy
main: com.willfp.ecoenchants.alchemy.AlchemyMain
version: 1.0.1
version: 1.1.0

View File

@ -12,7 +12,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
public abstract class BiomesEnchantment extends EcoEnchant {
protected BiomesEnchantment(String key, EnchantmentType type, Prerequisite... prerequisites) {
super(key, type, BiomesMain.class, prerequisites);
super(key, type, BiomesMain.getInstance(), prerequisites);
}
public abstract boolean isValid(Biome biome);

View File

@ -1,3 +1,3 @@
name: Biomes
main: com.willfp.ecoenchants.biomes.BiomesMain
version: 1.0.1
version: 1.1.0

View File

@ -13,7 +13,7 @@ import org.bukkit.potion.PotionEffectType;
public abstract class EffectsEnchantment extends EcoEnchant {
protected EffectsEnchantment(String key, EnchantmentType type, Prerequisite... prerequisites) {
super(key, type, EffectsMain.class, prerequisites);
super(key, type, EffectsMain.getInstance(), prerequisites);
}
public abstract PotionEffectType getPotionEffect();

View File

@ -1,3 +1,3 @@
name: Effects
main: com.willfp.ecoenchants.effects.EffectsMain
version: 1.0.2
version: 1.1.0

View File

@ -18,7 +18,7 @@ import org.bukkit.inventory.ItemStack;
public class Endershot extends EcoEnchant {
public Endershot() {
super("endershot", EnchantmentType.NORMAL, EndershotMain.class);
super("endershot", EnchantmentType.NORMAL, EndershotMain.getInstance());
}
@EventHandler(priority = EventPriority.LOW)

View File

@ -1,3 +1,3 @@
name: Endershot
main: com.willfp.ecoenchants.endershot.EndershotMain
version: 1.0.1
version: 1.1.0

View File

@ -14,7 +14,7 @@ import org.bukkit.metadata.FixedMetadataValue;
public class Firewand extends Spell {
public Firewand() {
super("firewand", FirewandMain.class);
super("firewand", FirewandMain.getInstance());
}
@Override

View File

@ -1,3 +1,3 @@
name: Firewand
main: com.willfp.ecoenchants.firewand.FirewandMain
version: 1.0.4
version: 1.1.0

View File

@ -7,7 +7,7 @@ import com.willfp.ecoenchants.util.optional.Prerequisite;
public abstract class MMOEnchantment extends EcoEnchant implements MMOEnchant {
protected MMOEnchantment(String key, EnchantmentType type, Prerequisite... prerequisites) {
super(key, type, MMOMain.class, MMOPrerequisites.append(prerequisites, MMOPrerequisites.HAS_MMOCORE));
super(key, type, MMOMain.getInstance(), MMOPrerequisites.append(prerequisites, MMOPrerequisites.HAS_MMOCORE));
MMOEnchant.REGISTRY.add(this);
}

View File

@ -8,7 +8,7 @@ import com.willfp.ecoenchants.util.optional.Prerequisite;
public abstract class MMOSpell extends Spell implements MMOEnchant {
protected MMOSpell(String key, Prerequisite... prerequisites) {
super(key, MMOMain.class, MMOPrerequisites.append(prerequisites, MMOPrerequisites.HAS_MMOCORE));
super(key, MMOMain.getInstance(), MMOPrerequisites.append(prerequisites, MMOPrerequisites.HAS_MMOCORE));
MMOEnchant.REGISTRY.add(this);
}

View File

@ -1,3 +1,3 @@
name: MMO
main: com.willfp.ecoenchants.mmo.MMOMain
version: 1.0.0
version: 1.1.0

View File

@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class Precision extends EcoEnchant {
public Precision() {
super(
"precision", EnchantmentType.SPECIAL, PrecisionMain.class
"precision", EnchantmentType.SPECIAL, PrecisionMain.getInstance()
);
}

View File

@ -1,3 +1,3 @@
name: Precision
main: com.willfp.ecoenchants.precision.PrecisionMain
version: 1.0.4
version: 1.1.0

View File

@ -1,3 +1,3 @@
name: Sprint Artifacts
main: com.willfp.ecoenchants.sprintartifacts.SprintArtifactsMain
version: 1.0.1
version: 1.1.0

View File

@ -11,7 +11,12 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.*;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Mob;
import org.bukkit.entity.Player;
import org.bukkit.entity.Trident;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -23,7 +28,7 @@ public abstract class SummoningEnchantment extends EcoEnchant {
private final SummoningType summoningType;
protected SummoningEnchantment(String key, EnchantmentType type, SummoningType summoningType, Prerequisite... prerequisites) {
super(key, type, SummoningMain.class, prerequisites);
super(key, type, SummoningMain.getInstance(), prerequisites);
this.summoningType = summoningType;
}

View File

@ -1,3 +1,3 @@
name: Summoning
main: com.willfp.ecoenchants.summoning.SummoningMain
version: 1.0.3
version: 1.1.0

View File

@ -3,6 +3,7 @@ package com.willfp.ecoenchants.config;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.util.EnchantmentRegisterer;
import com.willfp.ecoenchants.util.internal.Logger;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
@ -27,6 +28,9 @@ public abstract class EnchantmentYamlConfig {
private final EnchantmentRegisterer registerer;
private final EcoEnchant.EnchantmentType type;
private final boolean legacy;
private Class<?> legacyRegisterer;
/**
* Create new config yml
*
@ -38,6 +42,30 @@ public abstract class EnchantmentYamlConfig {
this.name = name;
this.registerer = registerer;
this.type = type;
legacy = false;
File basedir = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), "enchants/");
if (!basedir.exists()) basedir.mkdirs();
File dir = new File(basedir, type.getName() + "/");
if (!dir.exists()) {
dir.mkdirs();
}
this.directory = dir;
init();
}
@Deprecated
public EnchantmentYamlConfig(String name, Class<?> registerer, EcoEnchant.EnchantmentType type) {
this.name = name;
this.legacyRegisterer = registerer;
this.registerer = null;
this.type = type;
legacy = true;
Logger.warn("Config " + name + " was created in legacy mode!");
Logger.warn("Update your extensions");
File basedir = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), "enchants/");
if (!basedir.exists()) basedir.mkdirs();
@ -65,7 +93,12 @@ public abstract class EnchantmentYamlConfig {
private void saveResource() {
String resourcePath = "/enchants/" + type.getName() + "/" + name + ".yml";
InputStream in = registerer.getResourceAsStream(resourcePath);
InputStream in;
if(legacy) {
in = legacyRegisterer.getResourceAsStream(resourcePath);
} else {
in = registerer.getResourceAsStream(resourcePath);
}
File outFile = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), resourcePath);
int lastIndex = resourcePath.lastIndexOf('/');
@ -99,7 +132,14 @@ public abstract class EnchantmentYamlConfig {
config.load(configFile);
String resourcePath = "/enchants/" + type.getName() + "/" + name + ".yml";
InputStream newIn = registerer.getResourceAsStream(resourcePath);
InputStream newIn;
if(legacy) {
newIn = legacyRegisterer.getResourceAsStream(resourcePath);
} else {
newIn = registerer.getResourceAsStream(resourcePath);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
YamlConfiguration newConfig = new YamlConfiguration();

View File

@ -28,6 +28,12 @@ public class EnchantmentConfig extends EnchantmentYamlConfig {
this.name = name;
}
@Deprecated
public EnchantmentConfig(String name, Class<?> registerer, EcoEnchant.EnchantmentType type) {
super(name, registerer, type);
this.name = name;
}
public String getName() {
return name;
}

View File

@ -10,6 +10,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;
@ -70,12 +71,52 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
this(key, type, EcoEnchantsPlugin.getInstance(), 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 registererClass 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
*
* @deprecated Class-based enchantment registration was deprecated in 5.6.0. Base your extensions off of {@link EnchantmentRegisterer}
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.7.0")
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Class<?> registererClass, Prerequisite... prerequisites) {
super(NamespacedKey.minecraft(key));
Logger.warn("Enchantment " + key + " was created in legacy mode!");
Logger.warn("Update your extensions");
this.type = type;
this.permissionName = key.replaceAll("_", "");
ConfigManager.addEnchantmentConfig(new EnchantmentConfig(this.permissionName, registererClass, this.type));
this.config = ConfigManager.getEnchantmentConfig(this.permissionName);
if (Bukkit.getPluginManager().getPermission("ecoenchants.fromtable." + permissionName) == null) {
Permission permission = new Permission(
"ecoenchants.fromtable." + permissionName,
"Allows getting " + permissionName + " from an Enchanting Table",
PermissionDefault.TRUE
);
permission.addParent(Objects.requireNonNull(Bukkit.getPluginManager().getPermission("ecoenchants.fromtable.*")), true);
Bukkit.getPluginManager().addPermission(permission);
}
if (!Prerequisite.areMet(prerequisites))
return;
this.update();
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 registerer The Main class of the {@link org.bukkit.plugin.Plugin} or {@link com.willfp.ecoenchants.extensions.Extension} that the enchantment was created by
* @param registerer Instance of the main class of the {@link com.willfp.ecoenchants.extensions.Extension} or {@link EnchantmentRegisterer} that the enchantment was created by
* @param prerequisites Optional {@link Prerequisite}s that must be met
*/
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, EnchantmentRegisterer registerer, Prerequisite... prerequisites) {

View File

@ -5,6 +5,7 @@ import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.enchantments.util.EnchantmentRegisterer;
import com.willfp.ecoenchants.nms.TridentStack;
import com.willfp.ecoenchants.util.NumberUtils;
import com.willfp.ecoenchants.util.optional.Prerequisite;
@ -24,6 +25,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.ApiStatus;
/**
* Wrapper for Artifact enchantments
@ -34,11 +36,11 @@ public abstract class Artifact extends EcoEnchant {
private Particle.DustOptions extra;
protected Artifact(String key, Prerequisite... prerequisites) {
this(key, EcoEnchantsPlugin.class, prerequisites);
this(key, EcoEnchantsPlugin.getInstance(), prerequisites);
}
protected Artifact(String key, Class<?> plugin, Prerequisite... prerequisites) {
super(key, EnchantmentType.ARTIFACT, plugin, prerequisites);
protected Artifact(String key, EnchantmentRegisterer registerer, Prerequisite... prerequisites) {
super(key, EnchantmentType.ARTIFACT, registerer, prerequisites);
if(!Prerequisite.areMet(prerequisites)) {
HandlerList.unregisterAll(this); // Prevent events firing
@ -47,7 +49,20 @@ public abstract class Artifact extends EcoEnchant {
this.particle = this.getParticle();
this.extra = this.getDustOptions();
}
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.7.0")
protected Artifact(String key, Class<?> registerer, Prerequisite... prerequisites) {
super(key, EnchantmentType.ARTIFACT, registerer, prerequisites);
if(!Prerequisite.areMet(prerequisites)) {
HandlerList.unregisterAll(this); // Prevent events firing
return;
}
this.particle = this.getParticle();
this.extra = this.getDustOptions();
}
public abstract Particle getParticle();

View File

@ -6,6 +6,7 @@ import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.enchantments.util.EnchantmentRegisterer;
import com.willfp.ecoenchants.enchantments.util.SpellRunnable;
import com.willfp.ecoenchants.util.optional.Prerequisite;
import org.bukkit.Bukkit;
@ -16,6 +17,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.jetbrains.annotations.ApiStatus;
import java.util.Arrays;
import java.util.HashMap;
@ -36,11 +38,17 @@ public abstract class Spell extends EcoEnchant {
);
protected Spell(String key, Prerequisite... prerequisites) {
this(key, EcoEnchantsPlugin.class, prerequisites);
this(key, EcoEnchantsPlugin.getInstance(), prerequisites);
}
protected Spell(String key, Class<?> plugin, Prerequisite... prerequisites) {
super(key, EnchantmentType.SPELL, plugin, prerequisites);
protected Spell(String key, EnchantmentRegisterer registerer, Prerequisite... prerequisites) {
super(key, EnchantmentType.SPELL, registerer, prerequisites);
}
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.7.0")
protected Spell(String key, Class<?> registerer, Prerequisite... prerequisites) {
super(key, EnchantmentType.SPELL, registerer, prerequisites);
}
public int getCooldownTime() {

View File

@ -18,7 +18,7 @@ public abstract class Extension implements EnchantmentRegisterer {
/**
* Instance of the extension
*/
private Extension instance;
private static Extension instance;
/**
* Method to validate metadata and enable extension
@ -50,7 +50,7 @@ public abstract class Extension implements EnchantmentRegisterer {
* Get instance of the extension
* @return The instance
*/
public final Extension getInstance() {
public static Extension getInstance() {
return instance;
}

View File

@ -38,8 +38,5 @@ findProject(':SprintArtifacts').projectDir = file('Extensions/SprintArtifacts')
include('Alchemy')
findProject(':Alchemy').projectDir = file('Extensions/Alchemy')
/*
Excluded for extended build times
include('MMO')
findProject(':MMO').projectDir = file('Extensions/MMO')
*/
findProject(':MMO').projectDir = file('Extensions/MMO')