Make the singular type enchantment work as expected

This commit is contained in:
alexcrea 2024-12-24 09:49:12 +01:00
parent 3f6314ad09
commit 050d8bec8f
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
3 changed files with 24 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package com.willfp.ecoenchants.enchantments; package com.willfp.ecoenchants.enchantments;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -19,4 +20,7 @@ public class EcoEnchant {
return null; return null;
} }
public EnchantmentType getType() {
return null;
}
} }

View file

@ -0,0 +1,9 @@
package com.willfp.ecoenchants.enchantments.meta;
public class EnchantmentType {
public boolean isSingular() {
return false;
}
}

View file

@ -2,6 +2,7 @@ package xyz.alexcrea.cuanvil.enchant.wrapped;
import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -25,11 +26,21 @@ public class CALegacyEcoEnchant extends CABukkitEnchantment implements Additiona
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;
EnchantmentType type = this.ecoEnchant.getType();
boolean isSingular = type.isSingular();
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 (isSingular &&
other != this &&
(other instanceof CALegacyEcoEnchant otherEco) &&
type.equals(otherEco.ecoEnchant.getType())) {
return true;
}
} }
return false; return false;