From 190f334656ffcdd93114ff0a4c119482a590031b Mon Sep 17 00:00:00 2001 From: alexcrea Date: Fri, 10 Apr 2026 12:09:58 +0200 Subject: [PATCH 1/7] prepare to use item adder dependency for clone --- .../cuanvil/dependency/DependencyManager.kt | 113 ++++++++---------- .../plugins/ItemsAdderDependency.java | 12 ++ .../cuanvil/listener/PrepareAnvilListener.kt | 8 +- 3 files changed, 69 insertions(+), 64 deletions(-) create mode 100644 src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.java diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index df2fbce..523f99d 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -5,10 +5,12 @@ import io.delilaheve.CustomAnvil import net.kyori.adventure.text.Component import org.bukkit.Bukkit import org.bukkit.ChatColor +import org.bukkit.command.CommandSender import org.bukkit.entity.HumanEntity import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.PrepareAnvilEvent import org.bukkit.inventory.AnvilInventory +import org.bukkit.inventory.Inventory import org.bukkit.inventory.ItemStack import xyz.alexcrea.cuanvil.api.event.listener.CAClickResultBypassEvent import xyz.alexcrea.cuanvil.api.event.listener.CAEarlyPreAnvilBypassEvent @@ -46,6 +48,8 @@ object DependencyManager { var axPlayerWarpsCompatibility: AxPlayerWarpsDependency? = null + var itemsAdderCompatibility: ItemsAdderDependency? = null + val genericDependencies = ArrayList() fun loadDependency() { @@ -98,6 +102,12 @@ object DependencyManager { axPlayerWarpsCompatibility = AxPlayerWarpsDependency() } + if (pluginManager.isPluginEnabled("ItemsAdder")){ + val dependency = ItemsAdderDependency(pluginManager.getPlugin("ItemsAdder")!!) + itemsAdderCompatibility = dependency + genericDependencies.add(dependency) + } + // "Generic" dependencies if (pluginManager.isPluginEnabled("ToolStats")) genericDependencies.add(ToolStatsDependency(pluginManager.getPlugin("ToolStats")!!)) @@ -138,27 +148,35 @@ object DependencyManager { ecoEnchantCompatibility?.handleConfigReload() } + private fun logException(target: CommandSender, e: Exception) { + CustomAnvil.instance.logger.log( + Level.SEVERE, + "Error while trying to handle custom anvil supported plugin: ", + e + ) + trackError(e) + + // Finally, warn the player + target.sendMessage( + "[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " + + ChatColor.RED.toString() + "Error while handling the anvil." + ) + } + + private fun logExceptionAndClear(target: CommandSender, inventory: Inventory, e: Exception) { + // Just in case to avoid illegal items + inventory.setItem(ANVIL_OUTPUT_SLOT, null) + + logException(target, e) + } + // Return true if should bypass (either by a dependency or error) // called before immutability test fun earlyTryEventPreAnvilBypass(event: PrepareAnvilEvent, player: HumanEntity): Boolean { try { return earlyUnsafeTryEventPreAnvilBypass(event, player) } catch (e: Exception) { - CustomAnvil.instance.logger.log( - Level.SEVERE, - "Error while trying to handle custom anvil supported plugin: ", - e - ) - trackError(e) - - // Just in case to avoid illegal items - event.inventory.setItem(ANVIL_OUTPUT_SLOT, null) - - // Finally, warn the player, maybe a lot of time but better warn than do nothing - event.view.player.sendMessage( - "[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " + - ChatColor.RED.toString() + "Error while handling the anvil." - ) + logExceptionAndClear(event.view.player, event.inventory, e) return true } } @@ -184,21 +202,7 @@ object DependencyManager { try { return unsafeTryEventPreAnvilBypass(event, player) } catch (e: Exception) { - CustomAnvil.instance.logger.log( - Level.SEVERE, - "Error while trying to handle custom anvil supported plugin: ", - e - ) - trackError(e) - - // Just in case to avoid illegal items - event.inventory.setItem(ANVIL_OUTPUT_SLOT, null) - - // Finally, warn the player, maybe a lot of time but better warn than do nothing - event.view.player.sendMessage( - "[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " + - ChatColor.RED.toString() + "Error while handling the anvil." - ) + logExceptionAndClear(event.view.player, event.inventory, e) return true } } @@ -238,21 +242,7 @@ object DependencyManager { unsafeTryTreatAnvilResult(treatEvent) return treatEvent; } catch (e: Exception) { - CustomAnvil.instance.logger.log( - Level.SEVERE, - "Error while trying to handle custom anvil supported plugin: ", - e - ) - trackError(e) - - // Just in case to avoid illegal items - event.inventory.setItem(ANVIL_OUTPUT_SLOT, null) - - // Finally, warn the player, maybe a lot of time but better warn than do nothing - event.view.player.sendMessage( - "[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " + - ChatColor.RED.toString() + "Error while handling the anvil." - ) + logExceptionAndClear(event.view.player, event.inventory, e) return null } } @@ -268,21 +258,7 @@ object DependencyManager { try { return unsafeTryClickAnvilResultBypass(event, inventory) } catch (e: Exception) { - CustomAnvil.instance.logger.log( - Level.SEVERE, - "Error while trying to handle custom anvil supported plugin: ", - e - ) - trackError(e) - - // Just in case to avoid illegal items - event.inventory.setItem(ANVIL_OUTPUT_SLOT, null) - - // Finally, warn the player, maybe a lot of time but better warn than do nothing - event.whoClicked.sendMessage( - "[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " + - ChatColor.RED.toString() + "Error while handling the anvil." - ) + logExceptionAndClear(event.view.player, event.inventory, e) return true } } @@ -316,6 +292,23 @@ object DependencyManager { return bypass } + // Clone item and use plugin specific clone if needed + fun cloneItem(event: PrepareAnvilEvent, item: ItemStack): ItemStack { + try { + return unsafeCloneItem(item) + } catch (e: Exception) { + logException(event.view.player, e) + return item.clone() + } + } + + private fun unsafeCloneItem(item: ItemStack): ItemStack { + var cloned: ItemStack? = null + + if(cloned == null) cloned = item.clone() + return cloned + } + fun stripLore(item: ItemStack): MutableList { val dummy = item.clone() diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.java b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.java new file mode 100644 index 0000000..7034b9a --- /dev/null +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.java @@ -0,0 +1,12 @@ +package xyz.alexcrea.cuanvil.dependency.plugins; + +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +public class ItemsAdderDependency extends GenericPluginDependency{ + + public ItemsAdderDependency(@NotNull Plugin plugin) { + super(plugin); + } + +} diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt index 7126dd9..03865f0 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt @@ -155,7 +155,7 @@ class PrepareAnvilListener : Listener { val amount = CustomRecipeUtil.getCustomRecipeAmount(recipe, first, second) - val resultItem: ItemStack = recipe.resultItem!!.clone() + val resultItem: ItemStack = DependencyManager.cloneItem(event, recipe.resultItem!!) resultItem.amount *= amount // Maybe add an option on custom craft to ignore/not ignore penalty ?? @@ -179,7 +179,7 @@ class PrepareAnvilListener : Listener { event: PrepareAnvilEvent, inventory: AnvilInventory, player: HumanEntity, first: ItemStack ) { - val resultItem = first.clone() + val resultItem = DependencyManager.cloneItem(event, first) var anvilCost = handleRename(resultItem, inventory, player) // Test/stop if nothing changed. @@ -251,7 +251,7 @@ class PrepareAnvilListener : Listener { .combineWith(second.findEnchantments(), first, player) var hasChanged = !isIdentical(first.findEnchantments(), newEnchants) - val resultItem = first.clone() + val resultItem = DependencyManager.cloneItem(event, first) var anvilCost = 0 if(hasChanged){ resultItem.setEnchantmentsUnsafe(newEnchants) @@ -307,7 +307,7 @@ class PrepareAnvilListener : Listener { ): Boolean { val unitRepairAmount = first.getRepair(second) ?: return false - val resultItem = first.clone() + val resultItem = DependencyManager.cloneItem(event, first) var anvilCost = handleRename(resultItem, inventory, player) val repairAmount = resultItem.unitRepair(second.amount, unitRepairAmount) From 638df714fd8050c7ff96a5779ea85fe421d9513e Mon Sep 17 00:00:00 2001 From: alexcrea Date: Sun, 12 Apr 2026 11:12:34 +0200 Subject: [PATCH 2/7] Rename .java to .kt --- .../{ItemsAdderDependency.java => ItemsAdderDependency.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/{ItemsAdderDependency.java => ItemsAdderDependency.kt} (100%) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.java b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt similarity index 100% rename from src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.java rename to src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt From e00c5e8b479b385fa6b0119ae239d301a2720a0a Mon Sep 17 00:00:00 2001 From: alexcrea Date: Sun, 12 Apr 2026 11:12:38 +0200 Subject: [PATCH 3/7] clone use item adder on custom items adder item --- build.gradle.kts | 6 +++++ .../cuanvil/dependency/DependencyManager.kt | 6 ++--- .../plugins/ItemsAdderDependency.kt | 27 ++++++++++++++----- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index da11be5..a8211b0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -37,6 +37,9 @@ repositories { // ExcellentEnchants maven(url = "https://repo.nightexpressdev.com/releases") + // ItemsAdder + maven(url = "https://maven.devs.beer/") + // for fast stats maven { name = "thenextlvlReleases" @@ -97,6 +100,9 @@ dependencies { // SuperEnchants compileOnly(files("libs/SuperEnchants-4.6.2-all.jar")) + // ItemsAdder API + compileOnly("dev.lone:api-itemsadder:4.0.10") + // Include nms implementation(project(":nms:nms-common")) implementation(project(":nms:nms-paper")) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index 523f99d..0b5f396 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -303,10 +303,10 @@ object DependencyManager { } private fun unsafeCloneItem(item: ItemStack): ItemStack { - var cloned: ItemStack? = null + val cloned = itemsAdderCompatibility?.tryClone(item) + if(cloned != null) return cloned - if(cloned == null) cloned = item.clone() - return cloned + return item.clone() } fun stripLore(item: ItemStack): MutableList { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt index 7034b9a..2a7a0b8 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt @@ -1,12 +1,27 @@ -package xyz.alexcrea.cuanvil.dependency.plugins; +package xyz.alexcrea.cuanvil.dependency.plugins -import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; +import dev.lone.itemsadder.api.CustomStack +import dev.lone.itemsadder.api.ItemsAdder +import io.delilaheve.CustomAnvil +import org.bukkit.inventory.ItemStack +import org.bukkit.plugin.Plugin -public class ItemsAdderDependency extends GenericPluginDependency{ +class ItemsAdderDependency(plugin: Plugin) : GenericPluginDependency(plugin) { + var isLoaded: Boolean = false + get() { + if (field) return true - public ItemsAdderDependency(@NotNull Plugin plugin) { - super(plugin); + // We can't be sure the event is registered before being triggered so we need to use this function + field = ItemsAdder.areItemsLoaded() + return field + } + + fun tryClone(item: ItemStack): ItemStack? { + if(!isLoaded) return null + val customItem = CustomStack.byItemStack(item) ?: return null + + CustomAnvil.instance.logger.warning("testing equal: ${customItem.itemStack == item}") + return customItem.itemStack } } From 459e3351fdef22a0d368e2a9215c2467daf4cbda Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 21 Apr 2026 15:36:51 +0200 Subject: [PATCH 4/7] item adder namespace considered for unit merge --- .../enchant/wrapped/CAEEV5_4Enchantment.java | 1 - .../plugins/ItemsAdderDependency.kt | 17 ++++++++++++++--- .../xyz/alexcrea/cuanvil/util/MaterialUtil.kt | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CAEEV5_4Enchantment.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CAEEV5_4Enchantment.java index a86877f..7fb8627 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CAEEV5_4Enchantment.java +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CAEEV5_4Enchantment.java @@ -1,6 +1,5 @@ package xyz.alexcrea.cuanvil.enchant.wrapped; -import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt index 2a7a0b8..d8c9506 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt @@ -2,7 +2,7 @@ package xyz.alexcrea.cuanvil.dependency.plugins import dev.lone.itemsadder.api.CustomStack import dev.lone.itemsadder.api.ItemsAdder -import io.delilaheve.CustomAnvil +import org.bukkit.NamespacedKey import org.bukkit.inventory.ItemStack import org.bukkit.plugin.Plugin @@ -20,8 +20,19 @@ class ItemsAdderDependency(plugin: Plugin) : GenericPluginDependency(plugin) { if(!isLoaded) return null val customItem = CustomStack.byItemStack(item) ?: return null - CustomAnvil.instance.logger.warning("testing equal: ${customItem.itemStack == item}") - return customItem.itemStack + return CustomStack.getInstance(customItem.namespacedID)?.itemStack + } + + fun fromKey(key: NamespacedKey): ItemStack? { + if(!isLoaded) return null + return CustomStack.getInstance(key.toString())?.itemStack + } + + fun getKey(item: ItemStack) : NamespacedKey? { + if(!isLoaded) return null + val customItem = CustomStack.byItemStack(item) ?: return null + + return NamespacedKey.fromString(customItem.namespacedID) } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt index c4907c8..5253e09 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt @@ -4,6 +4,7 @@ import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.NamespacedKey import org.bukkit.inventory.ItemStack +import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.dependency.plugins.EcoItemDependencyUtil object MaterialUtil { @@ -27,6 +28,12 @@ object MaterialUtil { if(result != null) return result } + val itemAdder = DependencyManager.itemsAdderCompatibility + if(itemAdder != null) { + val result = itemAdder.getKey(this) + if (result != null) return result + } + return this.type.key } @@ -41,6 +48,12 @@ object MaterialUtil { if(result != null) return result } + val itemAdder = DependencyManager.itemsAdderCompatibility + if(itemAdder != null) { + val result = itemAdder.fromKey(key) + if (result != null) return result.type + } + return bukkitMaterialFromKey(key) } @@ -50,6 +63,12 @@ object MaterialUtil { if(result != null) return result } + val itemAdder = DependencyManager.itemsAdderCompatibility + if(itemAdder != null) { + val result = itemAdder.fromKey(key) + if (result != null) return result + } + return ItemStack(bukkitMaterialFromKey(key)!!) } From 41a62d810a0a2802152ba4e059b00977e8e03595 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 23 Apr 2026 12:22:40 +0200 Subject: [PATCH 5/7] get "all material" info from other plugins --- .../plugins/EcoItemDependencyUtil.kt | 4 +++ .../plugins/ItemsAdderDependency.kt | 4 +++ .../xyz/alexcrea/cuanvil/util/MaterialUtil.kt | 27 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EcoItemDependencyUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EcoItemDependencyUtil.kt index 14c7d9f..7e84231 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EcoItemDependencyUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EcoItemDependencyUtil.kt @@ -31,4 +31,8 @@ object EcoItemDependencyUtil { return ecoi.itemStack } + fun getItems(): List { + return EcoItems.values().map { item -> item.id } + } + } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt index d8c9506..7f977e1 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt @@ -35,4 +35,8 @@ class ItemsAdderDependency(plugin: Plugin) : GenericPluginDependency(plugin) { return NamespacedKey.fromString(customItem.namespacedID) } + fun idsCount(): Set { + return CustomStack.getNamespacedIdsInRegistry() + } + } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt index 5253e09..f8aface 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt @@ -76,5 +76,32 @@ object MaterialUtil { return getMatFromKey(key) != null } + fun getMaterialCount(): Int { + var count = Material.entries.size + if(HasEcoItem) { + count += EcoItemDependencyUtil.getItems().size + } + + val itemAdder = DependencyManager.itemsAdderCompatibility + if(itemAdder != null) { + count += itemAdder.idsCount().size + } + + return count + } + + fun getMaterials(): MutableList { + val all = ArrayList(Material.entries.map { it.key }) + if(HasEcoItem) { + all.addAll(EcoItemDependencyUtil.getItems()) + } + + val itemAdder = DependencyManager.itemsAdderCompatibility + if(itemAdder != null) { + all.addAll(itemAdder.idsCount().map { NamespacedKey.fromString(it) }) + } + + return all + } } \ No newline at end of file From 440b2b27418d552f2058f0f5d93743c616bc9b07 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 23 Apr 2026 12:23:40 +0200 Subject: [PATCH 6/7] create negative material set for iterator --- .../alexcrea/cuanvil/group/ExcludeGroup.kt | 2 +- .../cuanvil/group/NegativeMaterialSet.kt | 22 +++++++++++++++++++ .../cuanvil/{group => util}/NegativeSet.kt | 8 +++---- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt rename src/main/kotlin/xyz/alexcrea/cuanvil/{group => util}/NegativeSet.kt (81%) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt index 58ea48c..d752db5 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt @@ -6,7 +6,7 @@ import java.util.* class ExcludeGroup(name: String) : AbstractMaterialGroup(name) { override fun createDefaultSet(): MutableSet { - return NegativeSet(HashSet()) + return NegativeMaterialSet() } private var includedGroup: MutableSet = HashSet() diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt new file mode 100644 index 0000000..d87004d --- /dev/null +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt @@ -0,0 +1,22 @@ +package xyz.alexcrea.cuanvil.group + +import org.bukkit.NamespacedKey +import xyz.alexcrea.cuanvil.util.MaterialUtil +import xyz.alexcrea.cuanvil.util.NegativeSet + +class NegativeMaterialSet: NegativeSet() { + + override fun iterator(): MutableIterator { + val materials = MaterialUtil.getMaterials() + materials.removeIf { negate.contains(it) } + + return materials.iterator() + } + + override fun isEmpty(): Boolean { + return negate.size >= MaterialUtil.getMaterialCount() + } + + override val size get() = MaterialUtil.getMaterialCount() - negate.size + +} \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeSet.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/NegativeSet.kt similarity index 81% rename from src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeSet.kt rename to src/main/kotlin/xyz/alexcrea/cuanvil/util/NegativeSet.kt index 386ba5f..a94175b 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeSet.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/NegativeSet.kt @@ -1,6 +1,6 @@ -package xyz.alexcrea.cuanvil.group +package xyz.alexcrea.cuanvil.util -class NegativeSet(val negate: MutableSet) : MutableSet { +open class NegativeSet(val negate: MutableSet = HashSet()) : MutableSet { override fun iterator(): MutableIterator { TODO("Not yet implemented") // can't be implemented I guess @@ -15,7 +15,7 @@ class NegativeSet(val negate: MutableSet) : MutableSet { } override fun addAll(elements: Collection): Boolean { - return negate.removeAll(elements) + return negate.removeAll(elements.toSet()) } override fun removeAll(elements: Collection): Boolean { @@ -34,7 +34,7 @@ class NegativeSet(val negate: MutableSet) : MutableSet { TODO("Not yet implemented") } - override val size get() = TODO("Not yet implemented") + override val size: Int get() = TODO("Not yet implemented") override fun contains(element: T): Boolean { return !negate.contains(element) From a6cdd797508c263c7d5bd72ade4d75cfcb090c3f Mon Sep 17 00:00:00 2001 From: alexcrea Date: Sun, 17 May 2026 17:33:51 +0200 Subject: [PATCH 7/7] check the same way as item adder for eco items --- .../kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt index f8aface..6b55662 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt @@ -19,11 +19,9 @@ object MaterialUtil { return Material.AIR.key == this } - private val HasEcoItem = Bukkit.getPluginManager().isPluginEnabled("EcoItems") - val ItemStack.customType: NamespacedKey get() { - if(HasEcoItem) { + if(DependencyManager.ecoEnchantCompatibility != null) { val result = EcoItemDependencyUtil.ecoItemNamespace(this) if(result != null) return result } @@ -43,7 +41,7 @@ object MaterialUtil { } fun getMatFromKey(key: NamespacedKey): Material? { - if(HasEcoItem) { + if(DependencyManager.ecoEnchantCompatibility != null) { val result = EcoItemDependencyUtil.ecoItemMaterialFromKey(key) if(result != null) return result } @@ -58,7 +56,7 @@ object MaterialUtil { } fun itemFromKey(key: NamespacedKey): ItemStack { - if(HasEcoItem) { + if(DependencyManager.ecoEnchantCompatibility != null) { val result = EcoItemDependencyUtil.newEcoItemstack(key) if(result != null) return result } @@ -78,7 +76,7 @@ object MaterialUtil { fun getMaterialCount(): Int { var count = Material.entries.size - if(HasEcoItem) { + if(DependencyManager.ecoEnchantCompatibility != null) { count += EcoItemDependencyUtil.getItems().size } @@ -92,7 +90,7 @@ object MaterialUtil { fun getMaterials(): MutableList { val all = ArrayList(Material.entries.map { it.key }) - if(HasEcoItem) { + if(DependencyManager.ecoEnchantCompatibility != null) { all.addAll(EcoItemDependencyUtil.getItems()) }