Merge branch 'Auxilor:master' into patch-1

This commit is contained in:
MillionthOdin16 2022-09-25 19:04:46 -04:00 committed by GitHub
commit 90d6f765d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 60 additions and 27 deletions

View File

@ -95,9 +95,7 @@ class EcoEnchantsPlugin : LibReforgePlugin() {
}
companion object {
/**
* Instance of EcoEnchants.
*/
/** Instance of EcoEnchants. */
@JvmStatic
lateinit var instance: EcoEnchantsPlugin
private set

View File

@ -4,6 +4,7 @@ import com.willfp.eco.core.display.Display
import com.willfp.eco.core.display.DisplayModule
import com.willfp.eco.core.display.DisplayPriority
import com.willfp.eco.core.display.DisplayProperties
import com.willfp.eco.core.fast.FastItemStack
import com.willfp.eco.core.fast.fast
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.commands.CommandToggleDescriptions.Companion.seesEnchantmentDescriptions
@ -15,11 +16,15 @@ import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemFlag
import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataContainer
import org.bukkit.persistence.PersistentDataType
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.set
@Suppress("DEPRECATION")
class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plugin, DisplayPriority.HIGH) {
private val internalHideEnchants =
private val hideStateKey =
plugin.namespacedKeyFactory.create("ecoenchantlore-skip") // Same for backwards compatibility
override fun display(
@ -28,6 +33,10 @@ 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
@ -37,8 +46,10 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug
if (itemStack.type == Material.ENCHANTED_BOOK) {
fast.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS)
}
pdc.set(internalHideEnchants, PersistentDataType.INTEGER, 1)
pdc.set(hideStateKey, PersistentDataType.INTEGER, 1)
return
} else {
pdc.set(hideStateKey, PersistentDataType.INTEGER, 0)
}
val lore = fast.lore
@ -99,10 +110,14 @@ 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
if (!pdc.has(internalHideEnchants, PersistentDataType.INTEGER)) {
if (pdc.hideState != 1) {
fast.removeItemFlags(ItemFlag.HIDE_ENCHANTS)
if (itemStack.type == Material.ENCHANTED_BOOK) {
@ -110,17 +125,25 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug
}
}
pdc.remove(internalHideEnchants)
pdc.remove(hideStateKey)
}
override fun generateVarArgs(itemStack: ItemStack): Array<Any> {
val fast = itemStack.fast()
val pdc = fast.persistentDataContainer
return arrayOf(
fast.hasItemFlag(ItemFlag.HIDE_ENCHANTS)
|| fast.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
|| pdc.has(internalHideEnchants, PersistentDataType.INTEGER)
)
return when (fast.hideState) {
1 -> arrayOf(true)
0 -> arrayOf(false)
else -> arrayOf(
fast.hasItemFlag(ItemFlag.HIDE_ENCHANTS)
|| fast.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)
)
}
}
private val FastItemStack.hideState: Int
get() = this.persistentDataContainer.hideState
private val PersistentDataContainer.hideState: Int
get() = this.get(hideStateKey, PersistentDataType.INTEGER) ?: -1
}

View File

@ -100,7 +100,7 @@ object RaritySorter : EnchantmentSorter {
for (rarity in rarities) {
for (enchantment in children.getSafely(0).sort(enchantments, children.drop(1))) {
if (rarity != enchantment.wrap().rarity) {
if (rarity != enchantment.wrap().enchantmentRarity) {
continue
}

View File

@ -64,7 +64,7 @@ abstract class EcoEnchant(
override val type = EnchantmentTypes.getByID(config.getString("type")) ?: EnchantmentTypes.values().first()
override val rarity =
override val enchantmentRarity =
EnchantmentRarities.getByID(config.getString("rarity")) ?: EnchantmentRarities.values().first()
private val conflictNames = config.getStrings("conflicts")

View File

@ -27,7 +27,7 @@ interface EcoEnchantLike {
val displayName: String
val unformattedDisplayName: String
val enchant: Enchantment
val rarity: EnchantmentRarity
val enchantmentRarity: EnchantmentRarity
// Includes all extra logic not found in vanilla canEnchantItem
fun canEnchantItem(item: ItemStack): Boolean
@ -103,7 +103,7 @@ class VanillaEcoEnchantLike(
EnchantmentTypes.getByID(plugin.vanillaEnchantsYml.getString("${enchant.key.key}.type"))
?: EnchantmentTypes.values().first()
override val rarity: EnchantmentRarity =
override val enchantmentRarity: EnchantmentRarity =
EnchantmentRarities.getByID(plugin.vanillaEnchantsYml.getString("${enchant.key.key}.rarity"))
?: EnchantmentRarities.values().first()

View File

@ -44,7 +44,7 @@ object EnchantInfo {
plugin.configYml.getStrings("enchantinfo.item.lore")
.map {
it.replace("%max_level%", enchant.maxLevel.toString())
.replace("%rarity%", enchant.rarity.displayName)
.replace("%rarity%", enchant.enchantmentRarity.displayName)
.replace(
"%targets%",
enchant.targets.joinToString(", ") { target -> target.displayName }

View File

@ -91,11 +91,11 @@ class EnchantingTableSupport(
continue
}
if (NumberUtils.randFloat(0.0, 1.0) > enchantment.rarity.tableChance * multiplier) {
if (NumberUtils.randFloat(0.0, 1.0) > enchantment.enchantmentRarity.tableChance * multiplier) {
continue
}
if (enchantment.rarity.minimumLevel > cost) {
if (enchantment.enchantmentRarity.minimumLevel > cost) {
continue
}

View File

@ -53,7 +53,7 @@ class LootSupport(
continue
}
if (NumberUtils.randFloat(0.0, 1.0) > enchantment.rarity.lootChance * multiplier) {
if (NumberUtils.randFloat(0.0, 1.0) > enchantment.enchantmentRarity.lootChance * multiplier) {
continue
}

View File

@ -50,7 +50,7 @@ class VillagerSupport(
continue
}
if (NumberUtils.randFloat(0.0, 1.0) > enchantment.rarity.villagerChance * multiplier) {
if (NumberUtils.randFloat(0.0, 1.0) > enchantment.enchantmentRarity.villagerChance * multiplier) {
continue
}

View File

@ -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")

View File

@ -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>()

View File

@ -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

View File

@ -1,4 +1,4 @@
#libreforge-updater
#Thu Sep 22 17:32:02 BST 2022
version=9.0.0-b30
version=9.0.0-b33
plugin-name=EcoEnchants