mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-21 14:55:17 +01:00
Display tweaks
This commit is contained in:
parent
8efa58e10f
commit
39232a5402
@ -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<Any> {
|
||||
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)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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<String, EnchantmentTarget>()
|
||||
@ -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<HashedItem, Boolean>()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user