mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Optimised Enchant Squared get and clean.
This commit is contained in:
parent
c589a14b0b
commit
88c4f0509b
9 changed files with 65 additions and 23 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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))!!
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue