mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
fix small issue
I may have forgotten how to use reflexion. ups
This commit is contained in:
parent
566e3471dd
commit
d9cf3ef507
3 changed files with 34 additions and 10 deletions
|
|
@ -130,7 +130,10 @@ object DependencyManager {
|
|||
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.")
|
||||
event.view.player.sendMessage(
|
||||
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
|
||||
ChatColor.RED.toString() + "Error while handling the anvil."
|
||||
)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -159,7 +162,10 @@ object DependencyManager {
|
|||
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.")
|
||||
event.view.player.sendMessage(
|
||||
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
|
||||
ChatColor.RED.toString() + "Error while handling the anvil."
|
||||
)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -177,7 +183,7 @@ object DependencyManager {
|
|||
if (!bypass && (excellentEnchantsCompatibility?.testPrepareAnvil(event) == true)) bypass = true
|
||||
|
||||
for (genericDependency in genericDependencies) {
|
||||
genericDependency.testPrepareAnvil(event)
|
||||
if (!bypass && genericDependency.testPrepareAnvil(event)) bypass = true
|
||||
}
|
||||
|
||||
return bypass
|
||||
|
|
@ -199,7 +205,10 @@ object DependencyManager {
|
|||
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.")
|
||||
event.view.player.sendMessage(
|
||||
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
|
||||
ChatColor.RED.toString() + "Error while handling the anvil."
|
||||
)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -223,7 +232,10 @@ object DependencyManager {
|
|||
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||
|
||||
// Finally, warn the player, maybe a lot of time but better warn than do nothing
|
||||
event.whoClicked.sendMessage(ChatColor.RED.toString() + "Error while handling the anvil.")
|
||||
event.whoClicked.sendMessage(
|
||||
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
|
||||
ChatColor.RED.toString() + "Error while handling the anvil."
|
||||
)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import org.bukkit.event.inventory.PrepareAnvilEvent
|
|||
import org.bukkit.plugin.Plugin
|
||||
import org.bukkit.plugin.RegisteredListener
|
||||
|
||||
abstract class GenericPluginDependency(private val plugin: Plugin) {
|
||||
abstract class GenericPluginDependency(protected val plugin: Plugin) {
|
||||
|
||||
protected val preAnvil = ArrayList<RegisteredListener>()
|
||||
protected val postAnvil = ArrayList<RegisteredListener>()
|
||||
|
|
@ -33,18 +33,27 @@ abstract class GenericPluginDependency(private val plugin: Plugin) {
|
|||
|
||||
protected abstract fun postAnvilEvents(): Collection<RegisteredListener>
|
||||
|
||||
open fun testPrepareAnvil(event: PrepareAnvilEvent) {
|
||||
open fun testPrepareAnvil(event: PrepareAnvilEvent): Boolean {
|
||||
val previousResult = event.result
|
||||
event.result = null
|
||||
|
||||
for (registeredListener in preAnvil) {
|
||||
registeredListener.callEvent(event)
|
||||
if (event.result != null) return true
|
||||
}
|
||||
|
||||
event.result = previousResult;
|
||||
return false
|
||||
}
|
||||
|
||||
open fun testAnvilResult(event: InventoryClickEvent): Boolean {
|
||||
for (registeredListener in postAnvil) {
|
||||
registeredListener.callEvent(event)
|
||||
|
||||
if (event.inventory.getItem(2) == null) return true
|
||||
}
|
||||
|
||||
return event.inventory.getItem(2) == null
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.plugins
|
||||
|
||||
import lol.hyper.toolstats.ToolStats
|
||||
import lol.hyper.toolstats.tools.ItemChecker
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
|
@ -27,8 +28,10 @@ class ToolStatsDependency(plugin: Plugin) : GenericPluginDependency(plugin) {
|
|||
val left = event.inventory.getItem(PrepareAnvilListener.ANVIL_INPUT_LEFT)
|
||||
val result = event.inventory.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT)
|
||||
|
||||
val leftTokens = getTokenMethod.invoke(left) as Array<String>
|
||||
val resultToken = getTokenMethod.invoke(result) as Array<String>
|
||||
val itemChecker = (plugin as ToolStats).itemChecker
|
||||
|
||||
val leftTokens = getTokenMethod.invoke(itemChecker, left) as Array<String>
|
||||
val resultToken = getTokenMethod.invoke(itemChecker, result) as Array<String>
|
||||
|
||||
return !leftTokens.contentDeepEquals(resultToken);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue