mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-15 04:21:20 +01:00
libreforge-updater
This commit is contained in:
parent
cf482232df
commit
ac3c5058ad
@ -29,16 +29,13 @@ import com.willfp.ecoenchants.mechanics.GrindstoneSupport
|
||||
import com.willfp.ecoenchants.mechanics.LootSupport
|
||||
import com.willfp.ecoenchants.mechanics.VillagerSupport
|
||||
import com.willfp.ecoenchants.target.EnchantLookup.clearEnchantCache
|
||||
import com.willfp.ecoenchants.target.EnchantLookup.getActiveEnchantLevel
|
||||
import com.willfp.ecoenchants.target.EnchantLookup.heldEnchantLevels
|
||||
import com.willfp.libreforge.EmptyProvidedHolder.holder
|
||||
import com.willfp.libreforge.NamedValue
|
||||
import com.willfp.libreforge.ProvidedHolder
|
||||
import com.willfp.libreforge.loader.LibreforgePlugin
|
||||
import com.willfp.libreforge.loader.configs.ConfigCategory
|
||||
import com.willfp.libreforge.registerHolderPlaceholderProvider
|
||||
import com.willfp.libreforge.registerHolderProvider
|
||||
import com.willfp.libreforge.registerPlayerRefreshFunction
|
||||
import com.willfp.libreforge.registerSpecificHolderProvider
|
||||
import com.willfp.libreforge.registerSpecificRefreshFunction
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.Listener
|
||||
|
||||
@ -61,8 +58,13 @@ class EcoEnchantsPlugin : LibreforgePlugin() {
|
||||
}
|
||||
|
||||
override fun handleEnable() {
|
||||
registerHolderProvider { it.heldEnchantLevels }
|
||||
registerPlayerRefreshFunction { it.clearEnchantCache() }
|
||||
registerSpecificHolderProvider<Player> {
|
||||
it.heldEnchantLevels
|
||||
}
|
||||
|
||||
registerSpecificRefreshFunction<Player> {
|
||||
it.clearEnchantCache()
|
||||
}
|
||||
|
||||
registerHolderPlaceholderProvider<FoundEcoEnchantLevel> { it, _ ->
|
||||
listOf(
|
||||
|
@ -2,9 +2,9 @@ package com.willfp.ecoenchants.libreforge
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.fast.fast
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchant
|
||||
import com.willfp.ecoenchants.enchants.wrap
|
||||
import com.willfp.ecoenchants.type.EnchantmentType
|
||||
import com.willfp.libreforge.toDispatcher
|
||||
import com.willfp.libreforge.triggers.Trigger
|
||||
import com.willfp.libreforge.triggers.TriggerData
|
||||
import com.willfp.libreforge.triggers.TriggerParameter
|
||||
@ -35,7 +35,7 @@ class TriggerEnchantType(
|
||||
.any { it.type == type }
|
||||
) {
|
||||
this.dispatch(
|
||||
player,
|
||||
player.toDispatcher(),
|
||||
TriggerData(
|
||||
player = player,
|
||||
location = player.location,
|
||||
|
@ -10,6 +10,7 @@ import com.willfp.ecoenchants.enchants.FoundEcoEnchantLevel
|
||||
import com.willfp.libreforge.ItemProvidedHolder
|
||||
import com.willfp.libreforge.slot.SlotType
|
||||
import com.willfp.libreforge.slot.SlotTypes
|
||||
import com.willfp.libreforge.toDispatcher
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.concurrent.TimeUnit
|
||||
@ -18,18 +19,15 @@ import java.util.concurrent.TimeUnit
|
||||
typealias SlotProvider = (Player) -> Map<ItemInNumericSlot, ItemInSlot>
|
||||
|
||||
data class ItemInSlot internal constructor(
|
||||
val item: ItemStack,
|
||||
val slot: Collection<SlotType>
|
||||
val item: ItemStack, val slot: Collection<SlotType>
|
||||
) {
|
||||
constructor(
|
||||
item: ItemStack,
|
||||
slot: SlotType
|
||||
item: ItemStack, slot: SlotType
|
||||
) : this(item, listOf(slot))
|
||||
}
|
||||
|
||||
data class ItemInNumericSlot internal constructor(
|
||||
val item: ItemStack,
|
||||
val slot: Int
|
||||
val item: ItemStack, val slot: Int
|
||||
) {
|
||||
override fun hashCode(): Int {
|
||||
return HashedItem.of(item).hash * (slot + 1)
|
||||
@ -37,24 +35,20 @@ data class ItemInNumericSlot internal constructor(
|
||||
}
|
||||
|
||||
private data class HeldEnchant(
|
||||
val enchant: EcoEnchant,
|
||||
val level: Int
|
||||
val enchant: EcoEnchant, val level: Int
|
||||
)
|
||||
|
||||
object EnchantLookup {
|
||||
private val slotProviders = mutableSetOf<SlotProvider>()
|
||||
|
||||
private val itemCache = Caffeine.newBuilder()
|
||||
.expireAfterWrite(2, TimeUnit.SECONDS)
|
||||
.build<Player, Map<ItemInNumericSlot, ItemInSlot>>()
|
||||
private val itemCache =
|
||||
Caffeine.newBuilder().expireAfterWrite(2, TimeUnit.SECONDS).build<Player, Map<ItemInNumericSlot, ItemInSlot>>()
|
||||
|
||||
private val enchantCache = Caffeine.newBuilder()
|
||||
.expireAfterWrite(2, TimeUnit.SECONDS)
|
||||
private val enchantCache = Caffeine.newBuilder().expireAfterWrite(2, TimeUnit.SECONDS)
|
||||
.build<Player, Map<ItemInNumericSlot, Collection<HeldEnchant>>>()
|
||||
|
||||
// Higher frequency cache as less intensive
|
||||
private val enchantLevelCache = Caffeine.newBuilder()
|
||||
.expireAfterWrite(200, TimeUnit.MILLISECONDS)
|
||||
private val enchantLevelCache = Caffeine.newBuilder().expireAfterWrite(200, TimeUnit.MILLISECONDS)
|
||||
.build<Player, Map<ItemInNumericSlot, Map<EcoEnchant, Int>>>()
|
||||
|
||||
@JvmStatic
|
||||
@ -120,8 +114,8 @@ object EnchantLookup {
|
||||
}
|
||||
|
||||
// Basically a multimap
|
||||
found[slotID] = (found.getOrDefault(slotID, mutableListOf())
|
||||
+ HeldEnchant(enchant, level)).toMutableList()
|
||||
found[slotID] =
|
||||
(found.getOrDefault(slotID, mutableListOf()) + HeldEnchant(enchant, level)).toMutableList()
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,7 +177,7 @@ object EnchantLookup {
|
||||
for ((enchant, level) in enchants) {
|
||||
val enchantLevel = enchant.getLevel(level)
|
||||
val providedHolder = ItemProvidedHolder(enchantLevel, slot.item)
|
||||
if (enchantLevel.conditions.areMet(this, providedHolder)) {
|
||||
if (enchantLevel.conditions.areMet(this.toDispatcher(), providedHolder)) {
|
||||
inSlot[enchant] = level
|
||||
}
|
||||
}
|
||||
@ -253,7 +247,7 @@ object EnchantLookup {
|
||||
val item = this.inventory.getItem(slot) ?: return 0
|
||||
val providedHolder = ItemProvidedHolder(enchantLevel, item)
|
||||
|
||||
if (!enchantLevel.conditions.areMet(this, providedHolder)) {
|
||||
if (!enchantLevel.conditions.areMet(this.toDispatcher(), providedHolder)) {
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -313,8 +307,7 @@ object EnchantLookup {
|
||||
val level = it.holder as EcoEnchantLevel
|
||||
|
||||
ItemProvidedHolder(
|
||||
FoundEcoEnchantLevel(level, this.getActiveEnchantLevel(level.enchant)),
|
||||
it.provider
|
||||
FoundEcoEnchantLevel(level, this.getActiveEnchantLevel(level.enchant)), it.provider
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@ -338,9 +331,7 @@ object EnchantLookup {
|
||||
|
||||
for (slotID in slot.getItemSlots(player)) {
|
||||
val item = player.inventory.getItem(slotID) ?: continue
|
||||
found[
|
||||
ItemInNumericSlot(item, slotID)
|
||||
] = ItemInSlot(item, slot)
|
||||
found[ItemInNumericSlot(item, slotID)] = ItemInSlot(item, slot)
|
||||
}
|
||||
|
||||
found
|
||||
|
@ -1,5 +1,5 @@
|
||||
#libreforge-updater
|
||||
#Sun Nov 19 14:14:39 GMT 2023
|
||||
#Tue Nov 21 22:41:57 GMT 2023
|
||||
kotlin.code.style=official
|
||||
libreforge-version=4.43.1
|
||||
version=10.45.1
|
||||
libreforge-version=4.44.0
|
||||
version=10.46.0
|
||||
|
Loading…
Reference in New Issue
Block a user