mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-26 15:45:12 +01:00
Fixed /randomenchant and added support for modifying vanilla conflictsWith behaviour
This commit is contained in:
parent
fcb7a45302
commit
d61169f29e
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user