Renamed WrappedEnchantment to CAEnchantment (CustomAnvilEnchantment).

created an interface out of CAEnchantment and moved the implementation to CAEnchantmentBase.
This commit is contained in:
alexcrea 2024-06-20 13:08:48 +02:00
parent fa4752ea67
commit dafe595c5b
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
20 changed files with 575 additions and 463 deletions

View file

@ -8,7 +8,7 @@ import xyz.alexcrea.cuanvil.command.EditConfigExecutor
import xyz.alexcrea.cuanvil.command.ReloadExecutor
import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.dependency.DependencyManager
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
import xyz.alexcrea.cuanvil.listener.ChatEventListener
@ -94,7 +94,7 @@ class CustomAnvil : JavaPlugin() {
DependencyManager.loadDependency()
// Register enchantments
WrappedEnchantment.registerEnchantments()
CAEnchantmentRegistry.getInstance().registerStartupEnchantments()
// Load chat listener
chatListener = ChatEventListener()

View file

@ -3,7 +3,7 @@ package io.delilaheve.util
import io.delilaheve.CustomAnvil
import io.delilaheve.util.EnchantmentUtil.enchantmentName
import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
/**
* Config option accessors
@ -239,7 +239,7 @@ object ConfigOptions {
/**
* Get the given [enchantment]'s limit
*/
fun enchantLimit(enchantment: WrappedEnchantment): Int {
fun enchantLimit(enchantment: CAEnchantment): Int {
return enchantLimit(enchantment.enchantmentName)
}
@ -273,7 +273,7 @@ object ConfigOptions {
* it's source [isFromBook]
*/
fun enchantmentValue(
enchantment: WrappedEnchantment,
enchantment: CAEnchantment,
isFromBook: Boolean
): Int {
return enchantmentValue(enchantment.enchantmentName, isFromBook)
@ -307,7 +307,7 @@ object ConfigOptions {
return enchantmentValue("sweeping", isFromBook)
}
val enchantment = WrappedEnchantment.getByName(enchantmentName)
val enchantment = CAEnchantment.getByName(enchantmentName)
if(enchantment != null){
val rarity = enchantment.defaultRarity()

View file

@ -4,7 +4,7 @@ import io.delilaheve.CustomAnvil
import org.bukkit.Material
import org.bukkit.entity.HumanEntity
import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
import xyz.alexcrea.cuanvil.group.ConflictType
import kotlin.math.max
import kotlin.math.min
@ -17,17 +17,17 @@ object EnchantmentUtil {
/**
* Enchantment name without namespace
*/
val WrappedEnchantment.enchantmentName: String
val CAEnchantment.enchantmentName: String
get() = key.key
/**
* Combine 2 sets of enchantments according to our configuration
*/
fun Map<WrappedEnchantment, Int>.combineWith(
other: Map<WrappedEnchantment, Int>,
fun Map<CAEnchantment, Int>.combineWith(
other: Map<CAEnchantment, Int>,
mat: Material,
player: HumanEntity
) = mutableMapOf<WrappedEnchantment, Int>().apply {
) = mutableMapOf<CAEnchantment, Int>().apply {
putAll(this@combineWith)
other.forEach { (enchantment, level) ->
if(!enchantment.isAllowed(player)) return@forEach

View file

@ -3,7 +3,7 @@ package io.delilaheve.util
import org.bukkit.Material.ENCHANTED_BOOK
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.Damageable
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
import kotlin.math.ceil
import kotlin.math.max
import kotlin.math.min
@ -21,13 +21,13 @@ object ItemUtil {
/**
* Find the enchantment map for this [ItemStack] and return it as a [MutableMap]
*/
fun ItemStack.findEnchantments(): MutableMap<WrappedEnchantment, Int> = WrappedEnchantment.getEnchants(this)
fun ItemStack.findEnchantments(): MutableMap<CAEnchantment, Int> = CAEnchantment.getEnchants(this)
/**
* Apply an [enchantments] map to this [ItemStack]
*/
fun ItemStack.setEnchantmentsUnsafe(enchantments: Map<WrappedEnchantment, Int>) {
WrappedEnchantment.clearEnchants(this)
fun ItemStack.setEnchantmentsUnsafe(enchantments: Map<CAEnchantment, Int>) {
CAEnchantment.clearEnchants(this)
//TODO maybe faster methode to add vanilla enchantment. maybe move this function to wrapped enchantment
enchantments.forEach { (enchantment, level) ->