From 85d2d873eb83584dc84f7b422a58d0dbf31ac97d Mon Sep 17 00:00:00 2001 From: alexcrea <42614139+alexcrea@users.noreply.github.com> Date: Tue, 24 Dec 2024 11:23:05 +0100 Subject: [PATCH] Fix type limit not existing for modern eco enchant --- .../cuanvil/enchant/wrapped/CAEcoEnchant.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CAEcoEnchant.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CAEcoEnchant.java index b3a4635..6e74b73 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CAEcoEnchant.java +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CAEcoEnchant.java @@ -2,6 +2,7 @@ package xyz.alexcrea.cuanvil.enchant.wrapped; import com.willfp.ecoenchants.enchant.EcoEnchant; import com.willfp.ecoenchants.target.EnchantmentTarget; +import com.willfp.ecoenchants.type.EnchantmentType; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -9,6 +10,7 @@ import xyz.alexcrea.cuanvil.enchant.AdditionalTestEnchantment; import xyz.alexcrea.cuanvil.enchant.CAEnchantment; import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity; +import java.util.HashMap; import java.util.Map; public class CAEcoEnchant extends CABukkitEnchantment implements AdditionalTestEnchantment { @@ -22,17 +24,32 @@ public class CAEcoEnchant extends CABukkitEnchantment implements AdditionalTestE @Override public boolean isEnchantConflict(@NotNull Map enchantments, @NotNull Material itemMat) { - if(enchantments.isEmpty()) return false; + if (enchantments.isEmpty()) return false; if (this.ecoEnchant.getConflictsWithEverything()) { return true; } + HashMap typeAmountMap = new HashMap<>(); + for (CAEnchantment other : enchantments.keySet()) { - if(other instanceof CABukkitEnchantment otherVanilla - && this.ecoEnchant.conflictsWith(otherVanilla.getEnchant())){ + if (other instanceof CABukkitEnchantment otherVanilla + && this.ecoEnchant.conflictsWith(otherVanilla.getEnchant())) { return true; } + + if (other instanceof CAEcoEnchant ecoOther) { + EnchantmentType type = ecoOther.ecoEnchant.getType(); + typeAmountMap.putIfAbsent(type, 0); + + int amount = typeAmountMap.get(type) + 1; + if (amount > type.getLimit()) { + return true; + } + + typeAmountMap.put(type, amount); + } + } return false; @@ -42,12 +59,12 @@ public class CAEcoEnchant extends CABukkitEnchantment implements AdditionalTestE public boolean isItemConflict(@NotNull Map enchantments, @NotNull Material itemMat, @NotNull ItemStack item) { - if(Material.ENCHANTED_BOOK.equals(itemMat)){ + if (Material.ENCHANTED_BOOK.equals(itemMat)) { return false; } for (EnchantmentTarget target : this.ecoEnchant.getTargets()) { - if(target.matches(item)){ + if (target.matches(item)) { return false; } }