Fixed /randomenchant and added support for modifying vanilla conflictsWith behaviour

This commit is contained in:
Auxilor 2021-05-15 17:17:39 +01:00
parent fcb7a45302
commit d61169f29e
2 changed files with 24 additions and 16 deletions

View File

@ -1,5 +1,6 @@
package com.willfp.ecoenchants.proxy.v1_16_R3.enchants;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata;
import net.minecraft.server.v1_16_R3.Enchantment;
import org.bukkit.NamespacedKey;
@ -25,6 +26,11 @@ public class EcoCraftEnchantment extends CraftEnchantment {
return metadata.getMaxLevel() == null ? this.getHandle().getMaxLevel() : metadata.getMaxLevel();
}
@Override
public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) {
return EcoEnchants.getFromEnchantment(other) == null ? super.conflictsWith(other) : other.conflictsWith(other);
}
public void register() {
try {
Field byIdField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byKey");

View File

@ -80,6 +80,7 @@ public class CommandRandomenchant extends AbstractCommand {
for (EcoEnchant ecoEnchant : ecoEnchants) {
if (ecoEnchant.canEnchantItem(itemStack)) {
if (!ecoEnchant.conflictsWithAny(onItem)) {
if (ecoEnchant.isEnabled()) {
if (onItem.stream().noneMatch(enchantment -> enchantment.conflictsWith(ecoEnchant))) {
if (!onItem.contains(ecoEnchant)) {
boolean conflicts = false;
@ -104,6 +105,7 @@ public class CommandRandomenchant extends AbstractCommand {
}
}
}
}
if (enchant == null) {
player.sendMessage(this.getPlugin().getLangYml().getMessage("no-enchants-available"));