mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
fix max damage not being checked
This commit is contained in:
parent
c703dc68f9
commit
68f63a8ec7
2 changed files with 30 additions and 1 deletions
|
|
@ -0,0 +1,18 @@
|
|||
package xyz.alexcrea.cuanvil.util
|
||||
|
||||
import org.bukkit.inventory.meta.Damageable
|
||||
|
||||
// I LOVE support of old versions and needing to do modules like that
|
||||
// That truly is my favorite activity
|
||||
// TODO clean this one of legacy removal branch
|
||||
object MaxDamageCheckerUtil {
|
||||
|
||||
/**
|
||||
* @return max damage or int max if not set
|
||||
*/
|
||||
fun getMaxDamage(meta: Damageable): Int {
|
||||
if(!meta.hasMaxDamage()) return Integer.MAX_VALUE
|
||||
return meta.maxDamage
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,7 +4,9 @@ import org.bukkit.Material.ENCHANTED_BOOK
|
|||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.Damageable
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||
import xyz.alexcrea.cuanvil.update.UpdateUtils
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
|
||||
import xyz.alexcrea.cuanvil.util.MaxDamageCheckerUtil
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
|
@ -36,6 +38,13 @@ object ItemUtil {
|
|||
|
||||
}
|
||||
|
||||
private fun maxDamage(damageable: Damageable): Int {
|
||||
val ver = UpdateUtils.currentMinecraftVersion()
|
||||
if(ver.major <= 1 && ver.minor <= 20 && ver.patch < 5) return Integer.MAX_VALUE
|
||||
|
||||
return MaxDamageCheckerUtil.getMaxDamage(damageable)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this [ItemStack]s durability from a combination of the
|
||||
* [first] and [second] item's durability values
|
||||
|
|
@ -55,7 +64,9 @@ object ItemUtil {
|
|||
val secondDurability = durability - secondDamage
|
||||
val combinedDurability = firstDurability + secondDurability
|
||||
val newDurability = min(combinedDurability, durability)
|
||||
it.damage = durability - newDurability
|
||||
|
||||
val maxDamage = maxDamage(it)
|
||||
it.damage = min(durability - newDurability, maxDamage)
|
||||
itemMeta = it
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue