mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
fix from rebase
This commit is contained in:
parent
ef5585fd42
commit
2241fbd720
3 changed files with 14 additions and 18 deletions
|
|
@ -4,9 +4,7 @@ import org.bukkit.Material.ENCHANTED_BOOK
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.inventory.meta.Damageable
|
import org.bukkit.inventory.meta.Damageable
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||||
import xyz.alexcrea.cuanvil.update.UpdateUtils
|
|
||||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
|
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
|
||||||
import xyz.alexcrea.cuanvil.util.MaxDamageCheckerUtil
|
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
@ -38,13 +36,6 @@ 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
|
* Set this [ItemStack]s durability from a combination of the
|
||||||
* [first] and [second] item's durability values
|
* [first] and [second] item's durability values
|
||||||
|
|
@ -64,8 +55,8 @@ object ItemUtil {
|
||||||
val secondDurability = durability - secondDamage
|
val secondDurability = durability - secondDamage
|
||||||
val combinedDurability = firstDurability + secondDurability
|
val combinedDurability = firstDurability + secondDurability
|
||||||
val newDurability = min(combinedDurability, durability)
|
val newDurability = min(combinedDurability, durability)
|
||||||
|
val maxDamage = if(it.hasMaxDamage()) it.maxDamage else Int.MAX_VALUE
|
||||||
|
|
||||||
val maxDamage = maxDamage(it)
|
|
||||||
it.damage = min(durability - newDurability, maxDamage)
|
it.damage = min(durability - newDurability, maxDamage)
|
||||||
itemMeta = it
|
itemMeta = it
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package xyz.alexcrea.cuanvil.dependency
|
package xyz.alexcrea.cuanvil.dependency
|
||||||
|
|
||||||
import com.maddoxh.superEnchants.SuperEnchants
|
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import net.kyori.adventure.text.Component
|
import net.kyori.adventure.text.Component
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
|
|
@ -118,7 +117,7 @@ object DependencyManager {
|
||||||
genericDependencies.add(GenericPluginDependency(pluginManager.getPlugin("ItemsAdder")!!))
|
genericDependencies.add(GenericPluginDependency(pluginManager.getPlugin("ItemsAdder")!!))
|
||||||
|
|
||||||
if (pluginManager.isPluginEnabled("SuperEnchants")){
|
if (pluginManager.isPluginEnabled("SuperEnchants")){
|
||||||
val compatibility = SuperEnchantDependency(pluginManager.getPlugin("SuperEnchants")!! as SuperEnchants)
|
val compatibility = SuperEnchantDependency(pluginManager.getPlugin("SuperEnchants")!!)
|
||||||
if(compatibility.registerEnchantments())
|
if(compatibility.registerEnchantments())
|
||||||
genericDependencies.add(compatibility)
|
genericDependencies.add(compatibility)
|
||||||
}
|
}
|
||||||
|
|
@ -165,11 +164,11 @@ object DependencyManager {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun logExceptionAndClear(target: CommandSender, view: AnvilView, e: Exception) {
|
private fun logExceptionAndClear(view: AnvilView, e: Exception) {
|
||||||
// Just in case to avoid illegal items
|
// Just in case to avoid illegal items
|
||||||
view.setItem(ANVIL_OUTPUT_SLOT, null)
|
view.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||||
|
|
||||||
logException(target, e)
|
logException(view.player, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if should bypass (either by a dependency or error)
|
// Return true if should bypass (either by a dependency or error)
|
||||||
|
|
@ -178,7 +177,7 @@ object DependencyManager {
|
||||||
try {
|
try {
|
||||||
return earlyUnsafeTryEventPreAnvilBypass(event, player)
|
return earlyUnsafeTryEventPreAnvilBypass(event, player)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logExceptionAndClear(event.view.player, event.view, e)
|
logExceptionAndClear(event.view, e)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -204,7 +203,7 @@ object DependencyManager {
|
||||||
try {
|
try {
|
||||||
return unsafeTryEventPreAnvilBypass(event, player)
|
return unsafeTryEventPreAnvilBypass(event, player)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logExceptionAndClear(event.view.player, event.view, e)
|
logExceptionAndClear(event.view, e)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -262,7 +261,7 @@ object DependencyManager {
|
||||||
try {
|
try {
|
||||||
return unsafeTryClickAnvilResultBypass(event, view)
|
return unsafeTryClickAnvilResultBypass(event, view)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logExceptionAndClear(event.view.player, event.view, e)
|
logExceptionAndClear(view, e)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,23 @@ import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandExecutor
|
import org.bukkit.command.CommandExecutor
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent
|
import org.bukkit.event.inventory.InventoryClickEvent
|
||||||
|
import org.bukkit.plugin.Plugin
|
||||||
import org.bukkit.plugin.RegisteredListener
|
import org.bukkit.plugin.RegisteredListener
|
||||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||||
import xyz.alexcrea.cuanvil.enchant.bulk.SuperEnchantBulkOperation
|
import xyz.alexcrea.cuanvil.enchant.bulk.SuperEnchantBulkOperation
|
||||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CASuperEnchantEnchantment
|
import xyz.alexcrea.cuanvil.enchant.wrapped.CASuperEnchantEnchantment
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
|
|
||||||
class SuperEnchantDependency(override val plugin: SuperEnchants): GenericPluginDependency(plugin, false) {
|
class SuperEnchantDependency: GenericPluginDependency {
|
||||||
|
|
||||||
|
override val plugin: SuperEnchants
|
||||||
lateinit var enchManager: EnchantManager
|
lateinit var enchManager: EnchantManager
|
||||||
val enchantments = ArrayList<CASuperEnchantEnchantment>()
|
val enchantments = ArrayList<CASuperEnchantEnchantment>()
|
||||||
|
|
||||||
|
constructor(plugin: Plugin) : super(plugin) {
|
||||||
|
this.plugin = plugin as SuperEnchants
|
||||||
|
}
|
||||||
|
|
||||||
fun registerEnchantments(): Boolean{
|
fun registerEnchantments(): Boolean{
|
||||||
CustomAnvil.instance.logger.info("Preparing Super Enchant compatibility...")
|
CustomAnvil.instance.logger.info("Preparing Super Enchant compatibility...")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue