diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchants.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchants.kt index 26366747..ac070637 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchants.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EcoEnchants.kt @@ -37,6 +37,19 @@ object EcoEnchants { return ImmutableSet.copyOf(BY_KEY.keys) } + /** + * Get [EcoEnchant] matching id. + * + * @param id The id to search for. + * @return The matching [EcoEnchant], or null if not found. + */ + @JvmStatic + fun getByID(id: String?): EcoEnchant? { + return if (id == null) { + null + } else BY_KEY[id] + } + /** * Get [EcoEnchant] matching key. * @@ -44,10 +57,10 @@ object EcoEnchants { * @return The matching [EcoEnchant], or null if not found. */ @JvmStatic - fun getByKey(key: String?): EcoEnchant? { + fun getByKey(key: NamespacedKey?): EcoEnchant? { return if (key == null) { null - } else BY_KEY[key] + } else getByID(key.key) } /** diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/impl/EnchantmentPermanenceCurse.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/impl/EnchantmentPermanenceCurse.kt new file mode 100644 index 00000000..ae57a590 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/impl/EnchantmentPermanenceCurse.kt @@ -0,0 +1,12 @@ +package com.willfp.ecoenchants.enchants.impl + +import com.willfp.ecoenchants.EcoEnchantsPlugin +import com.willfp.ecoenchants.enchants.EcoEnchant + +class EnchantmentPermanenceCurse( + plugin: EcoEnchantsPlugin +) : EcoEnchant( + "permanence_curse", + plugin, + force = false +) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/AnvilSupport.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/AnvilSupport.kt index 0c5e81a9..36c6c9c0 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/AnvilSupport.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/AnvilSupport.kt @@ -4,6 +4,7 @@ import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.fast.fast import com.willfp.eco.core.proxy.ProxyConstants import com.willfp.eco.util.StringUtils +import com.willfp.ecoenchants.enchants.EcoEnchants import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy import org.bukkit.ChatColor import org.bukkit.Material @@ -142,6 +143,14 @@ class AnvilSupport( ChatColor.stripColor(itemName) }.let { if (it.isNullOrEmpty()) left.fast().displayName else it } + val permanenceCurse = EcoEnchants.getByID("permanence_curse") + + if (permanenceCurse != null) { + if (left.fast().getEnchants(true).containsKey(permanenceCurse)) { + return FAIL + } + } + if (right == null || right.type == Material.AIR) { if (left.fast().displayName == formattedItemName) { return FAIL diff --git a/eco-core/core-plugin/src/main/resources/enchants/breaklessness_curse.yml b/eco-core/core-plugin/src/main/resources/enchants/breaklessness_curse.yml index 736bcd63..046b0bb4 100644 --- a/eco-core/core-plugin/src/main/resources/enchants/breaklessness_curse.yml +++ b/eco-core/core-plugin/src/main/resources/enchants/breaklessness_curse.yml @@ -14,7 +14,7 @@ max-level: 1 tradeable: true discoverable: true -enchantable: true +enchantable: false effects: - id: cancel_event diff --git a/eco-core/core-plugin/src/main/resources/enchants/harmlessness_curse.yml b/eco-core/core-plugin/src/main/resources/enchants/harmlessness_curse.yml index b357e608..c5f74764 100644 --- a/eco-core/core-plugin/src/main/resources/enchants/harmlessness_curse.yml +++ b/eco-core/core-plugin/src/main/resources/enchants/harmlessness_curse.yml @@ -12,7 +12,7 @@ max-level: 1 tradeable: true discoverable: true -enchantable: true +enchantable: false effects: - id: cancel_event diff --git a/eco-core/core-plugin/src/main/resources/enchants/hunger_curse.yml b/eco-core/core-plugin/src/main/resources/enchants/hunger_curse.yml index 54c4ef57..06399167 100644 --- a/eco-core/core-plugin/src/main/resources/enchants/hunger_curse.yml +++ b/eco-core/core-plugin/src/main/resources/enchants/hunger_curse.yml @@ -11,7 +11,7 @@ max-level: 1 tradeable: true discoverable: true -enchantable: true +enchantable: false effects: - id: hunger_multiplier diff --git a/eco-core/core-plugin/src/main/resources/enchants/curse_of_misfortune.yml b/eco-core/core-plugin/src/main/resources/enchants/misfortune_curse.yml similarity index 95% rename from eco-core/core-plugin/src/main/resources/enchants/curse_of_misfortune.yml rename to eco-core/core-plugin/src/main/resources/enchants/misfortune_curse.yml index 403017c9..e86b8f1e 100644 --- a/eco-core/core-plugin/src/main/resources/enchants/curse_of_misfortune.yml +++ b/eco-core/core-plugin/src/main/resources/enchants/misfortune_curse.yml @@ -14,7 +14,7 @@ max-level: 1 tradeable: true discoverable: true -enchantable: true +enchantable: false effects: - id: cancel_event diff --git a/eco-core/core-plugin/src/main/resources/enchants/permanence_curse.yml b/eco-core/core-plugin/src/main/resources/enchants/permanence_curse.yml new file mode 100644 index 00000000..8fbcb564 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/permanence_curse.yml @@ -0,0 +1,15 @@ +display-name: "Curse of Permanence" +description: "Prevents modifying this item in an anvil" +type: curse + +targets: + - all +conflicts: [ ] +rarity: legendary +max-level: 1 + +tradeable: true +discoverable: true +enchantable: false + +conditions: [ ]