unit repair gui and internal update

This commit is contained in:
alexcrea 2026-07-01 02:39:14 +02:00
parent 799008f652
commit d1d01f90b8
Signed by: alexcrea
GPG key ID: E59DF23EE2A2266C
5 changed files with 129 additions and 71 deletions

View file

@ -6,6 +6,7 @@ import org.bukkit.NamespacedKey
import org.bukkit.inventory.ItemStack
import xyz.alexcrea.cuanvil.dependency.DependencyManager
import xyz.alexcrea.cuanvil.dependency.plugins.EcoItemDependencyUtil
import javax.annotation.Nullable
object MaterialUtil {
@ -35,11 +36,13 @@ object MaterialUtil {
return this.type.key
}
@Nullable
private fun bukkitMaterialFromKey(key: NamespacedKey): Material? {
//TODO on paper only transition Registry.MATERIAL.get(key)
return Material.matchMaterial(key.toString())
}
@Nullable
fun getMatFromKey(key: NamespacedKey): Material? {
if(DependencyManager.ecoEnchantCompatibility != null) {
val result = EcoItemDependencyUtil.ecoItemMaterialFromKey(key)

View file

@ -13,7 +13,7 @@ object UnitRepairUtil {
private const val DEFAULT_DEFAULT_UNIT_REPAIR = 0.25
// Path to user default unit repair value
private const val UNIT_REPAIR_DEFAULT_PATH = "default_repair_amount"
public const val UNIT_REPAIR_DEFAULT_PATH = "default_repair_amount"
/**
* Get the % of repair by unit [other] will do to this [ItemStack].
@ -25,14 +25,9 @@ object UnitRepairUtil {
if (other == null) return null
val config = ConfigHolder.UNIT_REPAIR_HOLDER.config
val material = other.customType
val selfType = this.customType
val result = findRepairValue(this, other, config) ?: return null
var result = checkSection(config, material.toString(), selfType)
if (result != null) return result
result = checkSection(config, material.key, selfType)
if (result != null) return result
if(result > 0) return result
// Get default
val userDefault = config.getDouble(UNIT_REPAIR_DEFAULT_PATH, DEFAULT_DEFAULT_UNIT_REPAIR)
@ -41,6 +36,20 @@ object UnitRepairUtil {
return userDefault
}
private fun findRepairValue(
self: ItemStack,
other: ItemStack,
config: FileConfiguration
): Double? {
val material = other.customType
val selfType = self.customType
val result = checkSection(config, material.toString(), selfType)
if (result != null) return result
return checkSection(config, material.key, selfType)
}
fun checkSection(
config: FileConfiguration,
path: String,