diff --git a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/enchants/EcoCraftEnchantment.java b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/enchants/EcoCraftEnchantment.java index c7fd2c36..6b5a508e 100644 --- a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/enchants/EcoCraftEnchantment.java +++ b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/enchants/EcoCraftEnchantment.java @@ -23,7 +23,11 @@ public class EcoCraftEnchantment extends CraftEnchantment { @Override public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) { - return other instanceof EcoEnchant ? other.conflictsWith(this) : super.conflictsWith(other); + if (other instanceof EcoEnchant) { + return other.conflictsWith(this); + } + + return metadata.conflicts() == null ? super.conflictsWith(other) : metadata.conflicts().contains(other.getKey()); } public void register() { diff --git a/eco-core/core-nms/v1_17_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_17_R1/enchants/EcoCraftEnchantment.java b/eco-core/core-nms/v1_17_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_17_R1/enchants/EcoCraftEnchantment.java index b3da0b84..e9f4ec23 100644 --- a/eco-core/core-nms/v1_17_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_17_R1/enchants/EcoCraftEnchantment.java +++ b/eco-core/core-nms/v1_17_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_17_R1/enchants/EcoCraftEnchantment.java @@ -23,7 +23,11 @@ public class EcoCraftEnchantment extends CraftEnchantment { @Override public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) { - return other instanceof EcoEnchant ? other.conflictsWith(this) : super.conflictsWith(other); + if (other instanceof EcoEnchant) { + return other.conflictsWith(this); + } + + return metadata.conflicts() == null ? super.conflictsWith(other) : metadata.conflicts().contains(other.getKey()); } public void register() { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantmentMetadata.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantmentMetadata.java index 8e57594a..fd06eff0 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantmentMetadata.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantmentMetadata.java @@ -1,6 +1,11 @@ package com.willfp.ecoenchants.enchantments.support.vanilla; +import org.bukkit.NamespacedKey; + +import java.util.Set; + public record VanillaEnchantmentMetadata( - Integer maxLevel + Integer maxLevel, + Set conflicts ) { } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantments.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantments.java index 80ae250d..cf9bdb81 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantments.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantments.java @@ -9,8 +9,10 @@ import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; @UtilityClass @@ -47,8 +49,22 @@ public class VanillaEnchantments { s1 -> Integer.parseInt(s1.split(":")[1]) )); + Map> conflicts = plugin.getVanillaEnchantsYml().getStrings("conflicts").stream() + .collect(Collectors.toMap( + s -> Enchantment.getByKey(NamespacedKey.minecraft(s.split(":")[0].toLowerCase())), + s1 -> { + String[] split = s1.split(":"); + Set keys = new HashSet<>(); + for (int i = 1; i < split.length; i++) { + keys.add(NamespacedKey.minecraft(split[i])); + } + + return keys; + } + )); + for (Enchantment enchantment : enchantments) { - VanillaEnchantmentMetadata metadata = new VanillaEnchantmentMetadata(maxLevels.get(enchantment)); + VanillaEnchantmentMetadata metadata = new VanillaEnchantmentMetadata(maxLevels.get(enchantment), conflicts.get(enchantment)); map.put(enchantment, metadata); } diff --git a/eco-core/core-plugin/src/main/resources/vanillaenchants.yml b/eco-core/core-plugin/src/main/resources/vanillaenchants.yml index 7b3facb6..e4b30f13 100644 --- a/eco-core/core-plugin/src/main/resources/vanillaenchants.yml +++ b/eco-core/core-plugin/src/main/resources/vanillaenchants.yml @@ -14,4 +14,14 @@ enabled: false # There may be potential conflicts if modifying vanilla enchantme # Currently, it is *not* possible to modify the enchantment levels from enchanting tables. # It will work with anvils however, but since it is still possible to get enchantments at their vanilla # max levels, then it isn't recommended to lower the max level of a vanilla enchantment, only to raise it. -max-levels: [] \ No newline at end of file +max-levels: [] + +# Set custom conflicts for vanilla enchantments. +# To do this, add each enchantment like this: +# - ":::..... etc" +# For example, to make mending conflict with efficiency and sharpness, you would do this: +# conflicts: +# - "mending:efficiency:sharpness" +# +# Beware that this will *override* conflicts, not add to them. +conflicts: [] \ No newline at end of file