Partially implemented eco enchant compatibility.

This commit is contained in:
alexcrea 2024-06-22 02:42:25 +02:00
parent 2e29e7f04e
commit 19806773a6
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
18 changed files with 143 additions and 35 deletions

View file

@ -90,16 +90,17 @@ public interface CAEnchantment {
@NotNull Collection<EnchantConflictGroup> getConflicts();
/**
* Test if the provided item can be compatible with this
* Test if the provided item can be compatible with this enchantment. only non-Custom Anvil conflict.
* @param baseEnchantments Validated enchantments for the item.
* @param itemMat Material of the tested item.
* @param itemSupply Provide a new instance of used item stack but with baseEnchantments as enchantments.
* @return Type of conflict this enchantment has with the provided item.
*/
@NotNull
ConflictType testConflict(@NotNull Map<CAEnchantment, Integer> baseEnchantments,
@NotNull Material itemMat,
@NotNull Supplier<ItemStack> itemSupply);
ConflictType testOtherConflicts(
@NotNull Map<CAEnchantment, Integer> baseEnchantments,
@NotNull Material itemMat,
@NotNull Supplier<ItemStack> itemSupply);
/**
* Get current level of the enchantment.

View file

@ -113,9 +113,10 @@ public abstract class CAEnchantmentBase implements CAEnchantment {
}
@Override
public @NotNull ConflictType testConflict(@NotNull Map<CAEnchantment, Integer> baseEnchantments,
@NotNull Material itemMat,
@NotNull Supplier<ItemStack> itemSupply) {
public @NotNull ConflictType testOtherConflicts(
@NotNull Map<CAEnchantment, Integer> baseEnchantments,
@NotNull Material itemMat,
@NotNull Supplier<ItemStack> itemSupply) {
return ConflictType.NO_CONFLICT;
}

View file

@ -85,7 +85,8 @@ public class CAEnchantmentRegistry {
* (By late I mean after custom anvil startup.)
* @param enchantment The enchantment to be unregistered.
*/
public void unregister(@NotNull CAEnchantment enchantment){
public void unregister(CAEnchantment enchantment){
if(enchantment == null) return;
byKeyMap.remove(enchantment.getKey());
byNameMap.remove(enchantment.getName());

View file

@ -0,0 +1,57 @@
package xyz.alexcrea.cuanvil.enchant.wrapped;
import com.willfp.ecoenchants.enchant.EcoEnchant;
import com.willfp.ecoenchants.target.EnchantmentTarget;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
import xyz.alexcrea.cuanvil.group.ConflictType;
import java.util.Map;
import java.util.function.Supplier;
public class CAEcoEnchant extends CAVanillaEnchantment {
private final @NotNull EcoEnchant ecoEnchant;
public CAEcoEnchant(@NotNull EcoEnchant enchant) {
super(enchant.getEnchantment(), EnchantmentRarity.COMMON);
this.ecoEnchant = enchant;
}
@Override
public @NotNull ConflictType testOtherConflicts(
@NotNull Map<CAEnchantment, Integer> baseEnchantments,
@NotNull Material itemMat,
@NotNull Supplier<ItemStack> itemSupply) {
if(!baseEnchantments.isEmpty()){
if(this.ecoEnchant.getConflictsWithEverything()){
return ConflictType.ENCHANTMENT_CONFLICT;
}
for (CAEnchantment other : baseEnchantments.keySet()) {
if(other instanceof CAVanillaEnchantment otherVanilla //TODO ISSUE FOUND: if vanilla is applied first conflcit is ignored. maybe export only enchantment conflict but keep target from ecoEnchant.
&& this.ecoEnchant.conflictsWith(otherVanilla.getEnchant())){
return ConflictType.ENCHANTMENT_CONFLICT;
}
}
}
// Allow enchanted book
if(Material.ENCHANTED_BOOK.equals(itemMat)){
return ConflictType.NO_CONFLICT;
}
ItemStack item = itemSupply.get();
for (EnchantmentTarget target : this.ecoEnchant.getTargets()) {
if(target.matches(item)){
return ConflictType.NO_CONFLICT;
}
}
return ConflictType.ITEM_CONFLICT;
}
}

View file

@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentBase;
import xyz.alexcrea.cuanvil.enchant.EnchantmentProperties;
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
@ -16,12 +17,15 @@ public class CAVanillaEnchantment extends CAEnchantmentBase {
private final @NotNull Enchantment enchantment;
public CAVanillaEnchantment(@NotNull Enchantment enchantment){
public CAVanillaEnchantment(@NotNull Enchantment enchantment, @Nullable EnchantmentRarity rarity){
super(enchantment.getKey(),
getRarity(enchantment),
rarity,
enchantment.getMaxLevel());
this.enchantment = enchantment;
}
public CAVanillaEnchantment(@NotNull Enchantment enchantment){
this(enchantment, getRarity(enchantment));
}
@Override
@ -77,6 +81,7 @@ public class CAVanillaEnchantment extends CAEnchantmentBase {
}
@NotNull
public static EnchantmentRarity getRarity(Enchantment enchantment){
try {
return EnchantmentProperties.valueOf(enchantment.getKey().getKey().toUpperCase(Locale.ENGLISH)).getRarity();
@ -85,4 +90,8 @@ public class CAVanillaEnchantment extends CAEnchantmentBase {
}
}
@NotNull
protected Enchantment getEnchant() {
return this.enchantment;
}
}

View file

@ -13,7 +13,6 @@ import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRecipe, CustomRecipeSubSettingGui> {

View file

@ -15,7 +15,6 @@ import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGroup, EnchantConflictSubSettingGui> {

View file

@ -17,7 +17,6 @@ import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, GroupConfigSubSettingGui> {

View file

@ -15,7 +15,6 @@ import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRepairElementListGui> {

View file

@ -20,7 +20,10 @@ import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.UUID;
public abstract class ElementListConfigGui< T > extends ChestGui implements ValueUpdatableGui {

View file

@ -6,7 +6,6 @@ import org.bukkit.entity.HumanEntity;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui;
import java.lang.reflect.Constructor;

View file

@ -11,7 +11,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui;
import java.util.ArrayList;