From 6510cd2c6a8dbaf83bb7c488faa060845d9a6ebd Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 9 Jan 2022 18:09:31 +0000 Subject: [PATCH] Fixed requirements with custom ecoenchants --- .../willfp/ecoenchants/EcoEnchantsPlugin.java | 4 +- .../CustomEcoEnchantRequirementListeners.java | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/custom/CustomEcoEnchantRequirementListeners.java 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 0f897002..19a20d28 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 @@ -15,6 +15,7 @@ import com.willfp.ecoenchants.config.VanillaEnchantsYml; import com.willfp.ecoenchants.display.EnchantDisplay; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.custom.CustomEcoEnchantRequirementListeners; import com.willfp.ecoenchants.enchantments.custom.CustomEnchantEnableListeners; import com.willfp.ecoenchants.enchantments.custom.CustomEnchantLookup; import com.willfp.ecoenchants.enchantments.support.merging.anvil.AnvilListeners; @@ -164,7 +165,8 @@ public class EcoEnchantsPlugin extends EcoPlugin { new WatcherTriggers(this), new VillagerListeners(this), new ItemConversions(this), - new CustomEnchantEnableListeners(this) + new CustomEnchantEnableListeners(this), + new CustomEcoEnchantRequirementListeners(this) ); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/custom/CustomEcoEnchantRequirementListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/custom/CustomEcoEnchantRequirementListeners.java new file mode 100644 index 00000000..e1afda2a --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/custom/CustomEcoEnchantRequirementListeners.java @@ -0,0 +1,44 @@ +package com.willfp.ecoenchants.enchantments.custom; + +import com.willfp.eco.core.EcoPlugin; +import com.willfp.eco.core.PluginDependent; +import com.willfp.eco.core.events.ArmorChangeEvent; +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; +import com.willfp.libreforge.LibReforgeUtils; +import com.willfp.libreforge.effects.ConfiguredEffect; +import com.willfp.libreforge.events.EffectActivateEvent; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityPickupItemEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.jetbrains.annotations.NotNull; + +public class CustomEcoEnchantRequirementListeners extends PluginDependent implements Listener { + /** + * Initialize new listeners and link them to a plugin. + * + * @param plugin The plugin to link to. + */ + public CustomEcoEnchantRequirementListeners(@NotNull final EcoPlugin plugin) { + super(plugin); + } + + public void onActivate(@NotNull final EffectActivateEvent event) { + if (!(event.getHolder() instanceof CustomEcoEnchantLevel level)) { + return; + } + + EcoEnchant enchant = level.getParent(); + + if (!(enchant.areRequirementsMet(event.getPlayer()))) { + event.setCancelled(true); + } + } +}