mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add dependency error safety.
This commit is contained in:
parent
1db6385082
commit
0d034c890e
2 changed files with 32 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ import io.delilaheve.CustomAnvil
|
||||||
import io.delilaheve.util.ConfigOptions
|
import io.delilaheve.util.ConfigOptions
|
||||||
import io.delilaheve.util.ItemUtil.canMergeWith
|
import io.delilaheve.util.ItemUtil.canMergeWith
|
||||||
import io.delilaheve.util.ItemUtil.unitRepair
|
import io.delilaheve.util.ItemUtil.unitRepair
|
||||||
|
import org.bukkit.ChatColor
|
||||||
import org.bukkit.GameMode
|
import org.bukkit.GameMode
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
|
@ -23,6 +24,7 @@ import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe
|
||||||
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
|
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
|
||||||
import xyz.alexcrea.cuanvil.util.CustomRecipeUtil
|
import xyz.alexcrea.cuanvil.util.CustomRecipeUtil
|
||||||
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
||||||
|
import java.util.logging.Level
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class AnvilResultListener: Listener {
|
class AnvilResultListener: Listener {
|
||||||
|
|
@ -45,8 +47,22 @@ class AnvilResultListener: Listener {
|
||||||
if (event.rawSlot != ANVIL_OUTPUT_SLOT) {
|
if (event.rawSlot != ANVIL_OUTPUT_SLOT) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test if the event should bypass custom anvil.
|
// Test if the event should bypass custom anvil.
|
||||||
if(DependencyManager.tryClickAnvilResultBypass(event, inventory)) return
|
var shouldBypass: Boolean
|
||||||
|
try {
|
||||||
|
shouldBypass = DependencyManager.tryClickAnvilResultBypass(event, inventory)
|
||||||
|
} catch (e: Exception){
|
||||||
|
shouldBypass = true
|
||||||
|
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
|
||||||
|
player.sendMessage(ChatColor.RED.toString() + "Error while handling the anvil.")
|
||||||
|
}
|
||||||
|
if(shouldBypass) return
|
||||||
|
|
||||||
val output = inventory.getItem(ANVIL_OUTPUT_SLOT) ?: return
|
val output = inventory.getItem(ANVIL_OUTPUT_SLOT) ?: return
|
||||||
val leftItem = inventory.getItem(ANVIL_INPUT_LEFT) ?: return
|
val leftItem = inventory.getItem(ANVIL_INPUT_LEFT) ?: return
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import xyz.alexcrea.cuanvil.util.AnvilColorUtil
|
||||||
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
|
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
|
||||||
import xyz.alexcrea.cuanvil.util.CustomRecipeUtil
|
import xyz.alexcrea.cuanvil.util.CustomRecipeUtil
|
||||||
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
||||||
|
import java.util.logging.Level
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener for anvil events
|
* Listener for anvil events
|
||||||
|
|
@ -45,7 +46,20 @@ class PrepareAnvilListener : Listener {
|
||||||
val player: HumanEntity = event.viewers.first()
|
val player: HumanEntity = event.viewers.first()
|
||||||
|
|
||||||
// Test if the event should bypass custom anvil.
|
// Test if the event should bypass custom anvil.
|
||||||
if(DependencyManager.tryEventPreAnvilBypass(event, player)) return
|
var shouldBypass: Boolean
|
||||||
|
try {
|
||||||
|
shouldBypass = DependencyManager.tryEventPreAnvilBypass(event, player)
|
||||||
|
} catch (e: Exception){
|
||||||
|
shouldBypass = true
|
||||||
|
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
|
||||||
|
player.sendMessage(ChatColor.RED.toString() + "Error while handling the anvil.")
|
||||||
|
}
|
||||||
|
if(shouldBypass) return
|
||||||
|
|
||||||
val inventory = event.inventory
|
val inventory = event.inventory
|
||||||
val first = inventory.getItem(ANVIL_INPUT_LEFT) ?: return
|
val first = inventory.getItem(ANVIL_INPUT_LEFT) ?: return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue