Updated extension loading

This commit is contained in:
Auxilor 2020-11-27 18:08:13 +00:00
parent 08e387238c
commit 73a2411dc4
3 changed files with 25 additions and 4 deletions

View File

@ -4,18 +4,24 @@ import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import org.bukkit.NamespacedKey;
import com.willfp.ecoenchants.util.Logger;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionEffect;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.stream.Collectors;
public class Alchemy extends EcoEnchant {
public Alchemy() {
super("alchemy", EnchantmentType.NORMAL, AlchemyMain.class);
}
private static final FixedMetadataValue TRUE = new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true);
@EventHandler
public void onPotionEffect(EntityPotionEffectEvent event) {
if(event.getNewEffect() == null) return;
@ -23,6 +29,9 @@ public class Alchemy extends EcoEnchant {
LivingEntity entity = (LivingEntity) event.getEntity();
if(entity.hasMetadata(event.getNewEffect().toString()))
return;
int level = EnchantChecks.getArmorPoints(entity, this);
if(level == 0) return;
@ -40,7 +49,16 @@ public class Alchemy extends EcoEnchant {
effect.hasIcon()
);
entity.setMetadata(newEffect.toString(), TRUE);
entity.removePotionEffect(effect.getType());
entity.addPotionEffect(newEffect);
Bukkit.getScheduler().runTask(EcoEnchantsPlugin.getInstance(), () -> {
newEffect.apply(entity);
});
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
entity.removeMetadata(newEffect.toString(), EcoEnchantsPlugin.getInstance());
}, 1);
}
}

View File

@ -1,8 +1,11 @@
package com.willfp.ecoenchants.alchemy;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.extensions.Extension;
public class AlchemyMain extends Extension {
public static final EcoEnchant ALCHEMY = new Alchemy();
@Override
public void onEnable() {

View File

@ -78,7 +78,7 @@ public class EcoExtensionLoader implements ExtensionLoader {
String mainClass = extensionYml.getString("main");
String name = extensionYml.getString("name");
String version = extensionYml.getString("version");
Extension.ExtensionMetadata metadata = new Extension.ExtensionMetadata(name, version);
Extension.ExtensionMetadata metadata = new Extension.ExtensionMetadata(version, name);
Class<?> cls;
Object object = null;