mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
suppress or remove most warnings
This commit is contained in:
parent
6ea8430247
commit
fc4df29033
6 changed files with 30 additions and 14 deletions
|
|
@ -30,7 +30,7 @@ import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
|||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.componentLore
|
||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError
|
||||
import java.lang.reflect.Constructor
|
||||
import java.lang.IllegalStateException
|
||||
import java.util.logging.Level
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
|
|
@ -337,10 +337,14 @@ object DependencyManager {
|
|||
|
||||
|
||||
private val prepareAnvilConstructor =
|
||||
PrepareAnvilEvent::class.java.constructors.first() as Constructor<PrepareAnvilEvent>
|
||||
PrepareAnvilEvent::class.java.constructors.first()
|
||||
|
||||
fun createFakeEvent(view: AnvilView, result: ItemStack?): PrepareAnvilEvent {
|
||||
return prepareAnvilConstructor.newInstance(view, result)
|
||||
val result = prepareAnvilConstructor.newInstance(view, result)
|
||||
if(result !is PrepareAnvilEvent)
|
||||
throw IllegalStateException("Could not create a PrepareAnvilEvent ?")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import org.bukkit.NamespacedKey
|
|||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
class ItemsAdderDependency(plugin: Plugin) : GenericPluginDependency(plugin) {
|
||||
var isLoaded: Boolean = false
|
||||
get() {
|
||||
|
|
|
|||
|
|
@ -10,13 +10,20 @@ class LegacyEcoEnchantDependency {
|
|||
|
||||
|
||||
private var ecoEnchantOldEnchantments: MutableSet<EcoEnchant>? = null
|
||||
private fun unregisterEnchantment(enchant: Any) {
|
||||
EnchantmentApi.unregisterEnchantment((enchant as Enchantment).key)
|
||||
}
|
||||
|
||||
private fun registerEnchantment(ecoEnchant: EcoEnchant, enchant: Any) {
|
||||
EnchantmentApi.registerEnchantment(CALegacyEcoEnchant(ecoEnchant, enchant as Enchantment))
|
||||
}
|
||||
|
||||
fun registerEnchantments() {
|
||||
val enchantments = EcoEnchants.values()
|
||||
for (ecoEnchant in enchantments) {
|
||||
ecoEnchant as Enchantment
|
||||
|
||||
EnchantmentApi.unregisterEnchantment(ecoEnchant) // As eco enchants is loaded before custom anvil and register enchantment to registry, we need to unregister old "vanilla" enchant.
|
||||
EnchantmentApi.registerEnchantment(CALegacyEcoEnchant(ecoEnchant, ecoEnchant))
|
||||
// As eco enchants is loaded before custom anvil and register enchantment to registry, we need to unregister old "vanilla" enchant.
|
||||
unregisterEnchantment(ecoEnchant)
|
||||
registerEnchantment(ecoEnchant, ecoEnchant)
|
||||
}
|
||||
|
||||
ecoEnchantOldEnchantments = HashSet(enchantments)
|
||||
|
|
@ -31,13 +38,13 @@ class LegacyEcoEnchantDependency {
|
|||
// Add new enchantments
|
||||
for (ecoEnchant in newEnchantments)
|
||||
if (!this.ecoEnchantOldEnchantments!!.contains(ecoEnchant))
|
||||
EnchantmentApi.registerEnchantment(CALegacyEcoEnchant(ecoEnchant, ecoEnchant as Enchantment))
|
||||
registerEnchantment(ecoEnchant, ecoEnchant)
|
||||
|
||||
|
||||
// Remove old enchantments that not now currently used
|
||||
this.ecoEnchantOldEnchantments!!.removeAll(newEnchantments)
|
||||
for (oldEnchantment in this.ecoEnchantOldEnchantments!!) {
|
||||
EnchantmentApi.unregisterEnchantment(oldEnchantment as Enchantment)
|
||||
unregisterEnchantment(oldEnchantment)
|
||||
}
|
||||
|
||||
this.ecoEnchantOldEnchantments = HashSet(newEnchantments)
|
||||
|
|
|
|||
|
|
@ -18,9 +18,13 @@ class ToolStatsDependency(plugin: Plugin) : GenericPluginDependency(plugin) {
|
|||
getTokenMethod.trySetAccessible()
|
||||
}
|
||||
|
||||
private fun ItemChecker.getTokenSafe(item: ItemStack?): Array<String> {
|
||||
if (item == null) return arrayOf()
|
||||
return getTokenMethod.invoke(this, item) as Array<String>
|
||||
private fun ItemChecker.getTokenSafe(item: ItemStack?): Array<*> {
|
||||
if (item == null) return arrayOf<Any>()
|
||||
val result = getTokenMethod.invoke(this, item)
|
||||
if(result !is Array<*>)
|
||||
throw IllegalStateException("Could not get token from ToolStats")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
override fun testAnvilResult(event: InventoryClickEvent): Boolean {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue