custom fail message for MinionChestLinkEvent

This commit is contained in:
rudde 2024-04-30 13:12:23 +03:00
parent 05b36a3669
commit 9410d74832
2 changed files with 21 additions and 11 deletions

View File

@ -15,7 +15,7 @@ class MinionChestLinkEvent(minion: Minion, private val player: Player, private v
}
private var isCancelled = false
private var failMessage: String? = null
override fun getHandlers(): HandlerList {
return handlerList
@ -25,6 +25,14 @@ class MinionChestLinkEvent(minion: Minion, private val player: Player, private v
return player
}
fun getFailMessage(): String? {
return failMessage
}
fun setFailMessage(message: String) {
failMessage = message
}
fun getBlock(): Block {
return block
}

View File

@ -30,6 +30,18 @@ class LinkingListener : Listener {
if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) return
val minion = linking.remove(event.player) ?: return
val linkEvent = MinionChestLinkEvent(
minion,
event.player,
event.clickedBlock!!
)
Bukkit.getPluginManager().callEvent(linkEvent)
if (linkEvent.isCancelled) {
event.player.sendMessage(StringUtils.formatToString(linkEvent.getFailMessage() ?: (Messages.PREFIX() + Messages.LINK_FAIL())))
return
}
event.isCancelled = true
if (minion.getLocation()
.distanceSquared(event.clickedBlock!!.location) > Config.MAX_LINKING_DISTANCE() * Config.MAX_LINKING_DISTANCE()
@ -38,16 +50,6 @@ class LinkingListener : Listener {
return
}
val linkEvent = MinionChestLinkEvent(
linking.getValue(event.player),
event.player,
event.clickedBlock!!
)
Bukkit.getPluginManager().callEvent(linkEvent)
if (linkEvent.isCancelled) {
return
}
event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.LINK_SUCCESS()))
minion.setLinkedChest(event.clickedBlock!!.location)
}