Fixed bugs with hide stored enchants

This commit is contained in:
Auxilor 2024-06-23 17:18:49 +01:00
parent c4b71948df
commit 9bff63b3ec
2 changed files with 25 additions and 4 deletions

View File

@ -1,19 +1,33 @@
package com.willfp.ecoenchants.proxy.v1_21 package com.willfp.ecoenchants.proxy.v1_21
import com.willfp.eco.core.Prerequisite
import com.willfp.eco.core.fast.FastItemStack import com.willfp.eco.core.fast.FastItemStack
import com.willfp.ecoenchants.display.HideStoredEnchantsProxy import com.willfp.ecoenchants.display.HideStoredEnchantsProxy
import org.bukkit.inventory.ItemFlag import org.bukkit.inventory.ItemFlag
import javax.print.attribute.PrintRequestAttribute
class HideStoredEnchants: HideStoredEnchantsProxy { class HideStoredEnchants: HideStoredEnchantsProxy {
override fun hideStoredEnchants(fis: FastItemStack) { override fun hideStoredEnchants(fis: FastItemStack) {
fis.addItemFlags(ItemFlag.HIDE_STORED_ENCHANTS) if (Prerequisite.HAS_PAPER.isMet) {
fis.addItemFlags(ItemFlag.HIDE_STORED_ENCHANTS)
} else {
fis.addItemFlags(ItemFlag.HIDE_ADDITIONAL_TOOLTIP)
}
} }
override fun areStoredEnchantsHidden(fis: FastItemStack): Boolean { override fun areStoredEnchantsHidden(fis: FastItemStack): Boolean {
return fis.hasItemFlag(ItemFlag.HIDE_STORED_ENCHANTS) return if (Prerequisite.HAS_PAPER.isMet) {
fis.hasItemFlag(ItemFlag.HIDE_STORED_ENCHANTS)
} else {
fis.hasItemFlag(ItemFlag.HIDE_ADDITIONAL_TOOLTIP)
}
} }
override fun showStoredEnchants(fis: FastItemStack) { override fun showStoredEnchants(fis: FastItemStack) {
fis.removeItemFlags(ItemFlag.HIDE_STORED_ENCHANTS) if (Prerequisite.HAS_PAPER.isMet) {
fis.removeItemFlags(ItemFlag.HIDE_STORED_ENCHANTS)
} else {
fis.removeItemFlags(ItemFlag.HIDE_ADDITIONAL_TOOLTIP)
}
} }
} }

View File

@ -1,6 +1,7 @@
package com.willfp.ecoenchants.enchant package com.willfp.ecoenchants.enchant
import com.github.benmanes.caffeine.cache.Caffeine import com.github.benmanes.caffeine.cache.Caffeine
import com.willfp.eco.core.Prerequisite
import com.willfp.eco.core.config.base.LangYml import com.willfp.eco.core.config.base.LangYml
import com.willfp.eco.core.drops.DropQueue import com.willfp.eco.core.drops.DropQueue
import com.willfp.eco.core.fast.fast import com.willfp.eco.core.fast.fast
@ -24,6 +25,7 @@ import com.willfp.eco.util.formatEco
import com.willfp.eco.util.lineWrap import com.willfp.eco.util.lineWrap
import com.willfp.ecoenchants.EcoEnchantsPlugin import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.display.EnchantSorter.sortForDisplay import com.willfp.ecoenchants.display.EnchantSorter.sortForDisplay
import com.willfp.ecoenchants.display.HideStoredEnchantsProxy
import com.willfp.ecoenchants.display.getFormattedDescription import com.willfp.ecoenchants.display.getFormattedDescription
import com.willfp.ecoenchants.display.getFormattedName import com.willfp.ecoenchants.display.getFormattedName
import com.willfp.ecoenchants.target.EnchantmentTargets.applicableEnchantments import com.willfp.ecoenchants.target.EnchantmentTargets.applicableEnchantments
@ -206,7 +208,7 @@ private val cachedEnchantmentSlots = Caffeine.newBuilder()
.build<EcoEnchant, Slot>() .build<EcoEnchant, Slot>()
private fun EcoEnchant.getInformationSlot(plugin: EcoEnchantsPlugin, player: Player): Slot { private fun EcoEnchant.getInformationSlot(plugin: EcoEnchantsPlugin, player: Player): Slot {
return cachedEnchantmentSlots.get(this) { return cachedEnchantmentSlots.get(this) { it ->
val level = if (plugin.configYml.getBool("enchantinfo.item.show-max-level")) { val level = if (plugin.configYml.getBool("enchantinfo.item.show-max-level")) {
it.maximumLevel it.maximumLevel
} else { } else {
@ -248,6 +250,11 @@ private fun EcoEnchant.getInformationSlot(plugin: EcoEnchantsPlugin, player: Pla
} }
} }
.build() .build()
.fast()
.apply {
plugin.getProxy(HideStoredEnchantsProxy::class.java).hideStoredEnchants(this)
}
.unwrap()
) )
} }
} }