mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +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,
|
props: DisplayProperties,
|
||||||
vararg args: Any
|
vararg args: Any
|
||||||
) {
|
) {
|
||||||
|
if (!itemStack.isEnchantable && plugin.configYml.getBool("display.require-enchantable")) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val fast = itemStack.fast()
|
val fast = itemStack.fast()
|
||||||
val pdc = fast.persistentDataContainer
|
val pdc = fast.persistentDataContainer
|
||||||
|
|
||||||
// Args represent hide enchants
|
// Args represent hide enchants - adding extra check ported from 8.x.x
|
||||||
if (args[0] == true) {
|
if (args[0] == true || pdc.has(internalHideEnchants, PersistentDataType.INTEGER)) {
|
||||||
fast.addItemFlags(ItemFlag.HIDE_ENCHANTS)
|
fast.addItemFlags(ItemFlag.HIDE_ENCHANTS)
|
||||||
if (itemStack.type == Material.ENCHANTED_BOOK) {
|
if (itemStack.type == Material.ENCHANTED_BOOK) {
|
||||||
fast.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
fast.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
|
||||||
@ -99,6 +103,10 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun revert(itemStack: ItemStack) {
|
override fun revert(itemStack: ItemStack) {
|
||||||
|
if (!itemStack.isEnchantable && plugin.configYml.getBool("display.require-enchantable")) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val fast = itemStack.fast()
|
val fast = itemStack.fast()
|
||||||
val pdc = fast.persistentDataContainer
|
val pdc = fast.persistentDataContainer
|
||||||
|
|
||||||
@ -115,12 +123,12 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug
|
|||||||
|
|
||||||
override fun generateVarArgs(itemStack: ItemStack): Array<Any> {
|
override fun generateVarArgs(itemStack: ItemStack): Array<Any> {
|
||||||
val fast = itemStack.fast()
|
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(
|
return arrayOf(
|
||||||
fast.hasItemFlag(ItemFlag.HIDE_ENCHANTS)
|
fast.hasItemFlag(ItemFlag.HIDE_ENCHANTS)
|
||||||
|| fast.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
|
|| 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 com.willfp.ecoenchants.EcoEnchantsPlugin
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import java.util.*
|
import java.util.Objects
|
||||||
|
|
||||||
interface EnchantmentTarget {
|
interface EnchantmentTarget {
|
||||||
val id: String
|
val id: String
|
||||||
@ -26,7 +26,7 @@ interface EnchantmentTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ConfiguredEnchantmentTarget(
|
class ConfiguredEnchantmentTarget(
|
||||||
private val config: Config
|
config: Config
|
||||||
) : EnchantmentTarget {
|
) : EnchantmentTarget {
|
||||||
override val id = config.getString("id")
|
override val id = config.getString("id")
|
||||||
override val displayName = config.getFormattedString("display-name")
|
override val displayName = config.getFormattedString("display-name")
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package com.willfp.ecoenchants.target
|
package com.willfp.ecoenchants.target
|
||||||
|
|
||||||
|
import com.github.benmanes.caffeine.cache.Caffeine
|
||||||
import com.google.common.collect.ImmutableSet
|
import com.google.common.collect.ImmutableSet
|
||||||
|
import com.willfp.eco.core.items.HashedItem
|
||||||
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
object EnchantmentTargets {
|
object EnchantmentTargets {
|
||||||
private val BY_ID = mutableMapOf<String, EnchantmentTarget>()
|
private val BY_ID = mutableMapOf<String, EnchantmentTarget>()
|
||||||
@ -38,7 +41,9 @@ object EnchantmentTargets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val ItemStack.isEnchantable: Boolean
|
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.
|
* Get all targets.
|
||||||
@ -77,7 +82,8 @@ object EnchantmentTargets {
|
|||||||
/**
|
/**
|
||||||
* Add new [EnchantmentTarget] to EcoEnchants.
|
* 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.
|
* @param target The [EnchantmentTarget] to add.
|
||||||
*/
|
*/
|
||||||
@ -86,3 +92,7 @@ object EnchantmentTargets {
|
|||||||
BY_ID[target.id] = target
|
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
|
word-wrap: 32 # Number of characters to have on each line
|
||||||
format: "&8"
|
format: "&8"
|
||||||
|
|
||||||
|
require-enchantable: true # If EcoEnchants should not display on non-enchantable items.
|
||||||
|
|
||||||
# Options for the /enchantinfo GUI
|
# Options for the /enchantinfo GUI
|
||||||
enchantinfo:
|
enchantinfo:
|
||||||
rows: 3 # How many rows for the GUI
|
rows: 3 # How many rows for the GUI
|
||||||
|
Loading…
Reference in New Issue
Block a user