mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
made early bypass
This commit is contained in:
parent
8f408438dc
commit
368b4b2c84
2 changed files with 32 additions and 4 deletions
|
|
@ -102,6 +102,35 @@ object DependencyManager {
|
|||
// Then handle plugin reload
|
||||
ecoEnchantCompatibility?.handleConfigReload()
|
||||
}
|
||||
// Return true if should bypass (either by a dependency or error)
|
||||
// called before immutability test
|
||||
fun earlyTryEventPreAnvilBypass(event: PrepareAnvilEvent, player: HumanEntity): Boolean {
|
||||
try {
|
||||
return earlyUnsafeTryEventPreAnvilBypass(event, player)
|
||||
} catch (e: Exception) {
|
||||
CustomAnvil.instance.logger.log(
|
||||
Level.SEVERE,
|
||||
"Error while trying to handle custom anvil supported plugin: ",
|
||||
e
|
||||
)
|
||||
|
||||
// Just in case to avoid illegal items
|
||||
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||
|
||||
// Finally, warn the player, maybe a lot of time but better warn than do nothing
|
||||
event.view.player.sendMessage(ChatColor.RED.toString() + "Error while handling the anvil.")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private fun earlyUnsafeTryEventPreAnvilBypass(event: PrepareAnvilEvent, player: HumanEntity): Boolean {
|
||||
var bypass = false
|
||||
|
||||
// Test if the inventory is a gui(version specific)
|
||||
if (externGuiTester?.testIfGui(event.view) == true) bypass = true
|
||||
|
||||
return bypass
|
||||
}
|
||||
|
||||
// Return true if should bypass (either by a dependency or error)
|
||||
fun tryEventPreAnvilBypass(event: PrepareAnvilEvent, player: HumanEntity): Boolean {
|
||||
|
|
@ -135,10 +164,6 @@ object DependencyManager {
|
|||
// Test excellent enchantments used prepare anvil
|
||||
if (!bypass && (excellentEnchantsCompatibility?.testPrepareAnvil(event) == true)) bypass = true
|
||||
|
||||
// Test if the inventory is a gui(version specific)
|
||||
if (!bypass && (externGuiTester?.testIfGui(event.view) == true)) bypass = true
|
||||
|
||||
|
||||
return bypass
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ class PrepareAnvilListener : Listener {
|
|||
// Should find player
|
||||
val player: HumanEntity = InventoryViewUtil.getInstance().getPlayer(event.view)
|
||||
|
||||
// Test if custom anvil is bypassed before immutability test
|
||||
if (DependencyManager.earlyTryEventPreAnvilBypass(event, player)) return
|
||||
|
||||
val inventory = event.inventory
|
||||
val first = inventory.getItem(ANVIL_INPUT_LEFT) ?: return
|
||||
val second = inventory.getItem(ANVIL_INPUT_RIGHT)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue