mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-28 16:05:14 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
b41b34a37a
@ -106,7 +106,8 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug
|
|||||||
enchantLore.add(Display.PREFIX + formattedName)
|
enchantLore.add(Display.PREFIX + formattedName)
|
||||||
|
|
||||||
if (shouldDescribe) {
|
if (shouldDescribe) {
|
||||||
enchantLore.addAll(enchant.getFormattedDescription(level).map { Display.PREFIX + it })
|
enchantLore.addAll(enchant.getFormattedDescription(level, player)
|
||||||
|
.filter { it.isNotEmpty() }.map { Display.PREFIX + it })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import com.willfp.eco.util.StringUtils
|
|||||||
import com.willfp.eco.util.formatEco
|
import com.willfp.eco.util.formatEco
|
||||||
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
||||||
import com.willfp.ecoenchants.enchants.EcoEnchantLike
|
import com.willfp.ecoenchants.enchants.EcoEnchantLike
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
// This is an object to be able to invalidate the cache on reload
|
// This is an object to be able to invalidate the cache on reload
|
||||||
object DisplayCache {
|
object DisplayCache {
|
||||||
@ -72,14 +73,14 @@ private val resetTags = arrayOf(
|
|||||||
"§r"
|
"§r"
|
||||||
)
|
)
|
||||||
|
|
||||||
fun EcoEnchantLike.getFormattedDescription(level: Int): List<String> {
|
fun EcoEnchantLike.getFormattedDescription(level: Int, player: Player? = null): List<String> {
|
||||||
val plugin = EcoEnchantsPlugin.instance
|
val plugin = EcoEnchantsPlugin.instance
|
||||||
|
|
||||||
return DisplayCache.descriptionCache.get(DisplayableEnchant(this, level)) {
|
return DisplayCache.descriptionCache.get(DisplayableEnchant(this, level)) {
|
||||||
val descriptionFormat = plugin.configYml.getString("display.descriptions.format")
|
val descriptionFormat = plugin.configYml.getString("display.descriptions.format")
|
||||||
val wrap = plugin.configYml.getInt("display.descriptions.word-wrap")
|
val wrap = plugin.configYml.getInt("display.descriptions.word-wrap")
|
||||||
|
|
||||||
var description = descriptionFormat + this.getUnformattedDescription(level)
|
var description = descriptionFormat + this.getUnformattedDescription(level, player)
|
||||||
|
|
||||||
// Replace reset tags with description format
|
// Replace reset tags with description format
|
||||||
for (tag in resetTags) {
|
for (tag in resetTags) {
|
||||||
@ -91,3 +92,6 @@ fun EcoEnchantLike.getFormattedDescription(level: Int): List<String> {
|
|||||||
)), wrap)
|
)), wrap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Java backwards compatibility
|
||||||
|
fun EcoEnchantLike.getFormattedDescription(level: Int): List<String> = getFormattedDescription(level, null)
|
||||||
|
@ -6,6 +6,7 @@ import com.willfp.eco.core.fast.fast
|
|||||||
import com.willfp.eco.core.placeholder.InjectablePlaceholder
|
import com.willfp.eco.core.placeholder.InjectablePlaceholder
|
||||||
import com.willfp.eco.core.placeholder.PlaceholderInjectable
|
import com.willfp.eco.core.placeholder.PlaceholderInjectable
|
||||||
import com.willfp.eco.core.placeholder.StaticPlaceholder
|
import com.willfp.eco.core.placeholder.StaticPlaceholder
|
||||||
|
import com.willfp.eco.core.placeholder.context.placeholderContext
|
||||||
import com.willfp.eco.util.NumberUtils
|
import com.willfp.eco.util.NumberUtils
|
||||||
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
||||||
import com.willfp.ecoenchants.mechanics.infiniteIfNegative
|
import com.willfp.ecoenchants.mechanics.infiniteIfNegative
|
||||||
@ -18,6 +19,7 @@ import com.willfp.ecoenchants.vanilla.VanillaEnchantmentData
|
|||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.NamespacedKey
|
import org.bukkit.NamespacedKey
|
||||||
import org.bukkit.enchantments.Enchantment
|
import org.bukkit.enchantments.Enchantment
|
||||||
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ -33,7 +35,7 @@ interface EcoEnchantLike {
|
|||||||
fun canEnchantItem(item: ItemStack): Boolean
|
fun canEnchantItem(item: ItemStack): Boolean
|
||||||
|
|
||||||
// Method body goes here
|
// Method body goes here
|
||||||
fun getUnformattedDescription(level: Int): String {
|
fun getUnformattedDescription(level: Int, player: Player? = null): String {
|
||||||
// Fetch custom placeholders other than %placeholder%
|
// Fetch custom placeholders other than %placeholder%
|
||||||
val uncompiledPlaceholders = config.getSubsection("placeholders").getKeys(false).associateWith {
|
val uncompiledPlaceholders = config.getSubsection("placeholders").getKeys(false).associateWith {
|
||||||
config.getString("placeholders.$it")
|
config.getString("placeholders.$it")
|
||||||
@ -42,30 +44,34 @@ interface EcoEnchantLike {
|
|||||||
// Add %placeholder% placeholder in
|
// Add %placeholder% placeholder in
|
||||||
uncompiledPlaceholders["placeholder"] = config.getString("placeholder")
|
uncompiledPlaceholders["placeholder"] = config.getString("placeholder")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Evaluate each placeholder
|
// Evaluate each placeholder
|
||||||
val placeholders = uncompiledPlaceholders.map { (id, expr) ->
|
val placeholders = uncompiledPlaceholders.map { (id, expr) ->
|
||||||
DescriptionPlaceholder(
|
DescriptionPlaceholder(
|
||||||
id,
|
id,
|
||||||
NumberUtils.evaluateExpression(
|
NumberUtils.evaluateExpression(
|
||||||
expr,
|
expr,
|
||||||
null,
|
placeholderContext(
|
||||||
object : PlaceholderInjectable {
|
player = player,
|
||||||
override fun getPlaceholderInjections(): List<InjectablePlaceholder> {
|
injectable = object : PlaceholderInjectable {
|
||||||
return listOf(
|
override fun getPlaceholderInjections(): List<InjectablePlaceholder> {
|
||||||
StaticPlaceholder(
|
return listOf(
|
||||||
"level",
|
StaticPlaceholder(
|
||||||
) { level.toString() }
|
"level",
|
||||||
)
|
) { level.toString() }
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override fun addInjectablePlaceholder(p0: MutableIterable<InjectablePlaceholder>) {
|
override fun addInjectablePlaceholder(p0: MutableIterable<InjectablePlaceholder>) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun clearInjectedPlaceholders() {
|
override fun clearInjectedPlaceholders() {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -79,6 +85,11 @@ interface EcoEnchantLike {
|
|||||||
|
|
||||||
return description
|
return description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Java backwards compatibility
|
||||||
|
fun getUnformattedDescription(level: Int): String {
|
||||||
|
return getUnformattedDescription(level, null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val ecoEnchantLikes = Caffeine.newBuilder()
|
private val ecoEnchantLikes = Caffeine.newBuilder()
|
||||||
|
@ -19,7 +19,6 @@ import com.willfp.eco.core.items.Items
|
|||||||
import com.willfp.eco.core.items.builder.EnchantedBookBuilder
|
import com.willfp.eco.core.items.builder.EnchantedBookBuilder
|
||||||
import com.willfp.eco.core.items.builder.ItemStackBuilder
|
import com.willfp.eco.core.items.builder.ItemStackBuilder
|
||||||
import com.willfp.eco.core.items.isEmpty
|
import com.willfp.eco.core.items.isEmpty
|
||||||
import com.willfp.eco.util.StringUtils
|
|
||||||
import com.willfp.eco.util.formatEco
|
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
|
||||||
@ -27,13 +26,10 @@ import com.willfp.ecoenchants.display.EnchantSorter.sortForDisplay
|
|||||||
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
|
||||||
import org.apache.commons.lang.WordUtils
|
|
||||||
import org.bukkit.ChatColor
|
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemFlag
|
import org.bukkit.inventory.ItemFlag
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.persistence.PersistentDataType
|
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
|
||||||
object EnchantGUI {
|
object EnchantGUI {
|
||||||
@ -158,7 +154,7 @@ object EnchantGUI {
|
|||||||
setSlot(
|
setSlot(
|
||||||
plugin.configYml.getInt("enchantinfo.item.row"),
|
plugin.configYml.getInt("enchantinfo.item.row"),
|
||||||
plugin.configYml.getInt("enchantinfo.item.column"),
|
plugin.configYml.getInt("enchantinfo.item.column"),
|
||||||
enchant.getInformationSlot(plugin)
|
enchant.getInformationSlot(plugin, player)
|
||||||
)
|
)
|
||||||
|
|
||||||
setMask(
|
setMask(
|
||||||
@ -196,7 +192,7 @@ private class EnchantmentScrollPane(
|
|||||||
|
|
||||||
val enchant = enchants.getOrNull(index + size * (page - 1)) ?: return defaultSlot
|
val enchant = enchants.getOrNull(index + size * (page - 1)) ?: return defaultSlot
|
||||||
|
|
||||||
return enchant.getInformationSlot(plugin)
|
return enchant.getInformationSlot(plugin, player)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getRows() = plugin.configYml.getInt("enchant-gui.enchant-area.height")
|
override fun getRows() = plugin.configYml.getInt("enchant-gui.enchant-area.height")
|
||||||
@ -208,7 +204,7 @@ private class EnchantmentScrollPane(
|
|||||||
private val cachedEnchantmentSlots = Caffeine.newBuilder()
|
private val cachedEnchantmentSlots = Caffeine.newBuilder()
|
||||||
.build<EcoEnchant, Slot>()
|
.build<EcoEnchant, Slot>()
|
||||||
|
|
||||||
private fun EcoEnchant.getInformationSlot(plugin: EcoEnchantsPlugin): Slot {
|
private fun EcoEnchant.getInformationSlot(plugin: EcoEnchantsPlugin, player: Player): Slot {
|
||||||
return cachedEnchantmentSlots.get(this) {
|
return cachedEnchantmentSlots.get(this) {
|
||||||
val level = if (plugin.configYml.getBool("enchantinfo.item.show-max-level")) {
|
val level = if (plugin.configYml.getBool("enchantinfo.item.show-max-level")) {
|
||||||
enchant.maxLevel
|
enchant.maxLevel
|
||||||
@ -221,7 +217,7 @@ private fun EcoEnchant.getInformationSlot(plugin: EcoEnchantsPlugin): Slot {
|
|||||||
.addStoredEnchantment(enchant, level)
|
.addStoredEnchantment(enchant, level)
|
||||||
.addItemFlag(ItemFlag.HIDE_ENCHANTS)
|
.addItemFlag(ItemFlag.HIDE_ENCHANTS)
|
||||||
.setDisplayName(enchant.getFormattedName(level))
|
.setDisplayName(enchant.getFormattedName(level))
|
||||||
.addLoreLines(enchant.getFormattedDescription(level))
|
.addLoreLines(enchant.getFormattedDescription(level, player))
|
||||||
.addLoreLines {
|
.addLoreLines {
|
||||||
plugin.configYml.getStrings("enchantinfo.item.lore")
|
plugin.configYml.getStrings("enchantinfo.item.lore")
|
||||||
.map {
|
.map {
|
||||||
|
@ -20,7 +20,7 @@ effects:
|
|||||||
triggers:
|
triggers:
|
||||||
- take_damage
|
- take_damage
|
||||||
filters:
|
filters:
|
||||||
damageCause:
|
damage_cause:
|
||||||
- poison
|
- poison
|
||||||
- magic
|
- magic
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ effects:
|
|||||||
triggers:
|
triggers:
|
||||||
- take_damage
|
- take_damage
|
||||||
filters:
|
filters:
|
||||||
damageCause:
|
damage_cause:
|
||||||
- suffocation
|
- suffocation
|
||||||
|
|
||||||
conditions: [ ]
|
conditions: [ ]
|
||||||
|
Loading…
Reference in New Issue
Block a user