Optimised Enchant Squared get and clean.

This commit is contained in:
alexcrea 2024-06-16 19:11:09 +02:00
parent c589a14b0b
commit 88c4f0509b
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
9 changed files with 65 additions and 23 deletions

View file

@ -26,13 +26,12 @@ import org.bukkit.inventory.InventoryView.Property.REPAIR_COST
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.Repairable
import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.group.ConflictType
import xyz.alexcrea.cuanvil.dependency.protocolib.PacketManager
import xyz.alexcrea.cuanvil.group.ConflictType
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
import kotlin.math.min
/**
* Listener for anvil events
*/

View file

@ -12,7 +12,6 @@ import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
import xyz.alexcrea.cuanvil.listener.ChatEventListener
import xyz.alexcrea.cuanvil.dependency.protocolib.PacketManager
import xyz.alexcrea.cuanvil.update.Update_1_21
import xyz.alexcrea.cuanvil.util.Metrics
import java.io.File

View file

@ -8,15 +8,15 @@ import xyz.alexcrea.cuanvil.dependency.protocolib.ProtocoLibWrapper
object DependencyManager {
lateinit var packetManager: PacketManager
var enchantmentSquaredCompatibility: EnchantmentSquaredDependency? = null;
var enchantmentSquaredCompatibility: EnchantmentSquaredDependency? = null
fun loadDependency(){
val pluginManager = Bukkit.getPluginManager();
val pluginManager = Bukkit.getPluginManager()
// ProtocolLib dependency
packetManager =
if(pluginManager.isPluginEnabled("ProtocolLib")) ProtocoLibWrapper();
else NoProtocoLib();
if(pluginManager.isPluginEnabled("ProtocolLib")) ProtocoLibWrapper()
else NoProtocoLib()
// Enchantment Squared dependency
enchantmentSquaredCompatibility =

View file

@ -1,17 +1,41 @@
package xyz.alexcrea.cuanvil.dependency
import me.athlaeos.enchantssquared.enchantments.CustomEnchant
import me.athlaeos.enchantssquared.managers.CustomEnchantManager
import org.bukkit.NamespacedKey
import org.bukkit.inventory.ItemStack
import org.bukkit.plugin.Plugin
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment
import xyz.alexcrea.cuanvil.enchant.wrapped.EnchantSquaredEnchantment
import java.util.*
class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) {
fun registerEnchantements(){
fun registerEnchantments(){
for (enchant in CustomEnchantManager.getInstance().allEnchants.values) {
WrappedEnchantment.register(EnchantSquaredEnchantment(enchant, enchantmentSquaredPlugin))
WrappedEnchantment.register(EnchantSquaredEnchantment(enchant))
}
}
fun getEnchantmentsSquared(item: ItemStack, enchantments: MutableMap<WrappedEnchantment, Int>) {
val customEnchants = CustomEnchantManager.getInstance().getItemsEnchantsFromPDC(item)
customEnchants.forEach{
(enchantment, level ) -> enchantments[getWrappedEnchant(enchantment)] = level
}
}
fun clearEnchantments(item: ItemStack) {
CustomEnchantManager.getInstance().removeAllEnchants(item)
}
fun getKeyFromEnchant(enchant: CustomEnchant): NamespacedKey{
return NamespacedKey.fromString(enchant.type.lowercase(Locale.getDefault()), this.enchantmentSquaredPlugin)!!
}
private fun getWrappedEnchant(enchant: CustomEnchant): WrappedEnchantment{
return WrappedEnchantment.getByKey(getKeyFromEnchant(enchant))!!
}
}