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 {
@ -22,17 +24,32 @@ public class CAEcoEnchant extends CABukkitEnchantment implements AdditionalTestE
@Override @Override
public boolean isEnchantConflict(@NotNull Map<CAEnchantment, Integer> enchantments, @NotNull Material itemMat) { public boolean isEnchantConflict(@NotNull Map<CAEnchantment, Integer> enchantments, @NotNull Material itemMat) {
if(enchantments.isEmpty()) return false; if (enchantments.isEmpty()) return false;
if (this.ecoEnchant.getConflictsWithEverything()) { if (this.ecoEnchant.getConflictsWithEverything()) {
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;
@ -42,12 +59,12 @@ public class CAEcoEnchant extends CABukkitEnchantment implements AdditionalTestE
public boolean isItemConflict(@NotNull Map<CAEnchantment, Integer> enchantments, public boolean isItemConflict(@NotNull Map<CAEnchantment, Integer> enchantments,
@NotNull Material itemMat, @NotNull Material itemMat,
@NotNull ItemStack item) { @NotNull ItemStack item) {
if(Material.ENCHANTED_BOOK.equals(itemMat)){ if (Material.ENCHANTED_BOOK.equals(itemMat)) {
return false; return false;
} }
for (EnchantmentTarget target : this.ecoEnchant.getTargets()) { for (EnchantmentTarget target : this.ecoEnchant.getTargets()) {
if(target.matches(item)){ if (target.matches(item)) {
return false; return false;
} }
} }