Add compatibility with ExcellentEnchants

This commit is contained in:
alexcrea 2024-10-12 22:40:31 +02:00
parent 7c283dc7f8
commit ffb9b4d756
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
7 changed files with 88 additions and 3 deletions

View file

@ -36,6 +36,10 @@ dependencies {
compileOnly("com.willfp:EcoEnchants:12.5.1")
compileOnly("com.willfp:eco:6.70.1")
// ExcellentEnchants
compileOnly(files("libs/nightcore-2.6.4.jar"))
compileOnly(files("libs/ExcellentEnchants-4.2.2.jar"))
// Disenchantment
compileOnly("cz.kominekjan:Disenchantment:v5.4.0")

Binary file not shown.

BIN
libs/nightcore-2.6.4.jar Normal file

Binary file not shown.

View file

@ -0,0 +1,46 @@
package xyz.alexcrea.cuanvil.enchant.wrapped;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment;
import su.nightexpress.excellentenchants.api.enchantment.Definition;
import xyz.alexcrea.cuanvil.enchant.AdditionalTestEnchantment;
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
import java.util.Map;
import java.util.Set;
public class CAEEEnchantment extends CABukkitEnchantment implements AdditionalTestEnchantment {
@NotNull CustomEnchantment eeenchantment;
@NotNull Definition definition;
public CAEEEnchantment(@NotNull CustomEnchantment enchantment) {
super(enchantment.getBukkitEnchantment(), EnchantmentRarity.getRarity(enchantment.getDefinition().getAnvilCost()));
this.eeenchantment = enchantment;
this.definition = enchantment.getDefinition();
}
@Override
public boolean isEnchantConflict(@NotNull Map<CAEnchantment, Integer> enchantments, @NotNull Material itemMat) {
if(!definition.hasConflicts()) return false;
Set<String> conflicts = definition.getConflicts();
for (CAEnchantment caEnchantment : enchantments.keySet()) {
if(conflicts.contains(caEnchantment.getName())) return true;
}
return false;
}
@Override
public boolean isItemConflict(@NotNull Map<CAEnchantment, Integer> enchantments, @NotNull Material itemMat, @NotNull ItemStack item) {
if(Material.ENCHANTED_BOOK.equals(itemMat)) return false;
return !definition.getSupportedItems().is(item);
}
}

View file

@ -23,6 +23,8 @@ object DependencyManager {
var enchantmentSquaredCompatibility: EnchantmentSquaredDependency? = null
var ecoEnchantCompatibility: EcoEnchantDependency? = null
var excellentEnchantsCompatibility: ExcellentEnchantsDependency? = null
var disenchantmentCompatibility: DisenchantmentDependency? = null
fun loadDependency(){
@ -53,6 +55,11 @@ object DependencyManager {
ecoEnchantCompatibility!!.disableAnvilListener()
}
// Excellent Enchants dependency
if(pluginManager.isPluginEnabled("ExcellentEnchants")){
excellentEnchantsCompatibility = ExcellentEnchantsDependency(pluginManager.getPlugin("ExcellentEnchants")!!)
}
// Disenchantment dependency
if(pluginManager.isPluginEnabled("Disenchantment")){
disenchantmentCompatibility = DisenchantmentDependency()
@ -69,6 +76,7 @@ object DependencyManager {
fun registerEnchantments() {
enchantmentSquaredCompatibility?.registerEnchantments()
ecoEnchantCompatibility?.registerEnchantments()
excellentEnchantsCompatibility?.registerEnchantments()
}

View file

@ -0,0 +1,26 @@
package xyz.alexcrea.cuanvil.dependency
import io.delilaheve.CustomAnvil
import org.bukkit.plugin.Plugin
import su.nightexpress.excellentenchants.registry.EnchantRegistry
import xyz.alexcrea.cuanvil.api.EnchantmentApi
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEEnchantment
class ExcellentEnchantsDependency(private val excellentEnchantsPlugin: Plugin){
init {
CustomAnvil.instance.logger.info("Excellent Enchants Detected !")
}
fun registerEnchantments() {
CustomAnvil.instance.logger.info("Preparing Excellent Enchants compatibility...")
for (enchantment in EnchantRegistry.getRegistered()) {
EnchantmentApi.unregisterEnchantment(enchantment.bukkitEnchantment.key) // As excellent enchants is loaded before custom anvil and register enchantment to registry, we need to unregister old "vanilla" enchant.
EnchantmentApi.registerEnchantment(CAEEEnchantment(enchantment))
}
CustomAnvil.instance.logger.info("\"Excellent Enchants should now work as expected !")
}
}

View file

@ -49,8 +49,8 @@ permissions:
description: Allow player to use hexadecimal color if permission is required (toggleable)
# soft depend on old name, so I can disable it if it is on the same server
# as it is the old name for this plugin
# soft depend on old name (UnsafeEnchantsPlus), so I can disable it if it is on the same server (old name for this plugin)
# Also depend to other plugin for compatibility
softdepend:
- UnsafeEnchantsPlus
- ProtocolLib
@ -58,3 +58,4 @@ softdepend:
- EnchantsSquared
- EcoEnchants
- eco
- ExcellentEnchants