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,24 +80,26 @@ public class CommandRandomenchant extends AbstractCommand {
for (EcoEnchant ecoEnchant : ecoEnchants) {
if (ecoEnchant.canEnchantItem(itemStack)) {
if (!ecoEnchant.conflictsWithAny(onItem)) {
if (onItem.stream().noneMatch(enchantment -> enchantment.conflictsWith(ecoEnchant))) {
if (!onItem.contains(ecoEnchant)) {
boolean conflicts = false;
for (Enchantment enchantment : onItem) {
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
EcoEnchant ecoEnchantOnItem = EcoEnchants.getFromEnchantment(enchantment);
if (ecoEnchantOnItem.getType().equals(ecoEnchant.getType()) && ecoEnchantOnItem.getType().isSingular()) {
conflicts = true;
if (ecoEnchant.isEnabled()) {
if (onItem.stream().noneMatch(enchantment -> enchantment.conflictsWith(ecoEnchant))) {
if (!onItem.contains(ecoEnchant)) {
boolean conflicts = false;
for (Enchantment enchantment : onItem) {
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
EcoEnchant ecoEnchantOnItem = EcoEnchants.getFromEnchantment(enchantment);
if (ecoEnchantOnItem.getType().equals(ecoEnchant.getType()) && ecoEnchantOnItem.getType().isSingular()) {
conflicts = true;
}
}
}
}
if (this.getPlugin().getConfigYml().getBool("anvil.hard-cap.enabled")
&& !player.hasPermission("ecoenchants.randomenchant.bypasshardcap")
&& onItem.size() >= this.getPlugin().getConfigYml().getInt("anvil.hard-cap.cap")) {
conflicts = true;
}
if (!conflicts) {
enchant = ecoEnchant;
if (this.getPlugin().getConfigYml().getBool("anvil.hard-cap.enabled")
&& !player.hasPermission("ecoenchants.randomenchant.bypasshardcap")
&& onItem.size() >= this.getPlugin().getConfigYml().getInt("anvil.hard-cap.cap")) {
conflicts = true;
}
if (!conflicts) {
enchant = ecoEnchant;
}
}
}
}