diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/display/EnchantDisplay.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/display/EnchantDisplay.kt index 9b38297e..51b1a177 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/display/EnchantDisplay.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/display/EnchantDisplay.kt @@ -28,11 +28,15 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug props: DisplayProperties, vararg args: Any ) { + if (!itemStack.isEnchantable && plugin.configYml.getBool("display.require-enchantable")) { + return + } + val fast = itemStack.fast() val pdc = fast.persistentDataContainer - // Args represent hide enchants - if (args[0] == true) { + // Args represent hide enchants - adding extra check ported from 8.x.x + if (args[0] == true || pdc.has(internalHideEnchants, PersistentDataType.INTEGER)) { fast.addItemFlags(ItemFlag.HIDE_ENCHANTS) if (itemStack.type == Material.ENCHANTED_BOOK) { fast.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS) @@ -99,6 +103,10 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug } override fun revert(itemStack: ItemStack) { + if (!itemStack.isEnchantable && plugin.configYml.getBool("display.require-enchantable")) { + return + } + val fast = itemStack.fast() val pdc = fast.persistentDataContainer @@ -115,12 +123,12 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug override fun generateVarArgs(itemStack: ItemStack): Array { val fast = itemStack.fast() - val pdc = fast.persistentDataContainer + // I'm not including the internal hide enchants check here because... I don't know why. + // I'm copying over from 8.x.x because I know it worked then. return arrayOf( fast.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || fast.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS) - || pdc.has(internalHideEnchants, PersistentDataType.INTEGER) ) } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/target/EnchantmentTarget.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/target/EnchantmentTarget.kt index b08454da..15c31818 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/target/EnchantmentTarget.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/target/EnchantmentTarget.kt @@ -7,7 +7,7 @@ import com.willfp.eco.core.recipe.parts.EmptyTestableItem import com.willfp.ecoenchants.EcoEnchantsPlugin import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack -import java.util.* +import java.util.Objects interface EnchantmentTarget { val id: String @@ -26,7 +26,7 @@ interface EnchantmentTarget { } class ConfiguredEnchantmentTarget( - private val config: Config + config: Config ) : EnchantmentTarget { override val id = config.getString("id") override val displayName = config.getFormattedString("display-name") diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/target/EnchantmentTargets.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/target/EnchantmentTargets.kt index ce8abb15..0963c080 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/target/EnchantmentTargets.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/target/EnchantmentTargets.kt @@ -1,9 +1,12 @@ package com.willfp.ecoenchants.target +import com.github.benmanes.caffeine.cache.Caffeine import com.google.common.collect.ImmutableSet +import com.willfp.eco.core.items.HashedItem import com.willfp.ecoenchants.EcoEnchantsPlugin import org.bukkit.Material import org.bukkit.inventory.ItemStack +import java.util.concurrent.TimeUnit object EnchantmentTargets { private val BY_ID = mutableMapOf() @@ -38,7 +41,9 @@ object EnchantmentTargets { } val ItemStack.isEnchantable: Boolean - get() = getForItem(this).isNotEmpty() || this.type == Material.BOOK || this.type == Material.ENCHANTED_BOOK + get() = enchantableCache.get(HashedItem.of(this)) { + getForItem(this).isNotEmpty() || this.type == Material.BOOK || this.type == Material.ENCHANTED_BOOK + } /** * Get all targets. @@ -77,7 +82,8 @@ object EnchantmentTargets { /** * Add new [EnchantmentTarget] to EcoEnchants. * - * Only for internal use, targets are automatically added in the constructor. + * Only for internal use, targets are automatically added in the + * constructor. * * @param target The [EnchantmentTarget] to add. */ @@ -86,3 +92,7 @@ object EnchantmentTargets { BY_ID[target.id] = target } } + +private val enchantableCache = Caffeine.newBuilder() + .expireAfterWrite(5, TimeUnit.SECONDS) + .build() diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 69b7d8e1..8ba17f80 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -71,6 +71,8 @@ display: word-wrap: 32 # Number of characters to have on each line format: "&8" + require-enchantable: true # If EcoEnchants should not display on non-enchantable items. + # Options for the /enchantinfo GUI enchantinfo: rows: 3 # How many rows for the GUI