Fix type limit not existing for modern eco enchant

This commit is contained in:
alexcrea 2024-12-24 11:23:05 +01:00
parent 343f57fdc7
commit 85d2d873eb
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F

View file

@ -2,6 +2,7 @@ package xyz.alexcrea.cuanvil.enchant.wrapped;
import com.willfp.ecoenchants.enchant.EcoEnchant; import com.willfp.ecoenchants.enchant.EcoEnchant;
import com.willfp.ecoenchants.target.EnchantmentTarget; import com.willfp.ecoenchants.target.EnchantmentTarget;
import com.willfp.ecoenchants.type.EnchantmentType;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; 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.CAEnchantment;
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity; import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class CAEcoEnchant extends CABukkitEnchantment implements AdditionalTestEnchantment { public class CAEcoEnchant extends CABukkitEnchantment implements AdditionalTestEnchantment {
@ -28,11 +30,26 @@ public class CAEcoEnchant extends CABukkitEnchantment implements AdditionalTestE
return true; return true;
} }
HashMap<EnchantmentType, Integer> typeAmountMap = new HashMap<>();
for (CAEnchantment other : enchantments.keySet()) { for (CAEnchantment other : enchantments.keySet()) {
if (other instanceof CABukkitEnchantment otherVanilla if (other instanceof CABukkitEnchantment otherVanilla
&& this.ecoEnchant.conflictsWith(otherVanilla.getEnchant())) { && this.ecoEnchant.conflictsWith(otherVanilla.getEnchant())) {
return true; 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; return false;