diff --git a/build.gradle.kts b/build.gradle.kts index 28cb586..507b783 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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") diff --git a/libs/ExcellentEnchants-4.2.2.jar b/libs/ExcellentEnchants-4.2.2.jar new file mode 100644 index 0000000..23d9630 Binary files /dev/null and b/libs/ExcellentEnchants-4.2.2.jar differ diff --git a/libs/nightcore-2.6.4.jar b/libs/nightcore-2.6.4.jar new file mode 100644 index 0000000..0404681 Binary files /dev/null and b/libs/nightcore-2.6.4.jar differ diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CAEEEnchantment.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CAEEEnchantment.java new file mode 100644 index 0000000..dfe60ff --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CAEEEnchantment.java @@ -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 enchantments, @NotNull Material itemMat) { + if(!definition.hasConflicts()) return false; + + Set conflicts = definition.getConflicts(); + + for (CAEnchantment caEnchantment : enchantments.keySet()) { + if(conflicts.contains(caEnchantment.getName())) return true; + } + + return false; + } + + @Override + public boolean isItemConflict(@NotNull Map enchantments, @NotNull Material itemMat, @NotNull ItemStack item) { + if(Material.ENCHANTED_BOOK.equals(itemMat)) return false; + + return !definition.getSupportedItems().is(item); + } +} diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index 06d4393..1d50f20 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -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() } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/ExcellentEnchantsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/ExcellentEnchantsDependency.kt new file mode 100644 index 0000000..5b2ab81 --- /dev/null +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/ExcellentEnchantsDependency.kt @@ -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 !") + } + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5cb7359..0e56616 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -49,12 +49,13 @@ 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 - Disenchantment - EnchantsSquared - EcoEnchants - - eco \ No newline at end of file + - eco + - ExcellentEnchants