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

View File

@ -30,6 +30,18 @@ class LinkingListener : Listener {
if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) return if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) return
val minion = linking.remove(event.player) ?: 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 event.isCancelled = true
if (minion.getLocation() if (minion.getLocation()
.distanceSquared(event.clickedBlock!!.location) > Config.MAX_LINKING_DISTANCE() * Config.MAX_LINKING_DISTANCE() .distanceSquared(event.clickedBlock!!.location) > Config.MAX_LINKING_DISTANCE() * Config.MAX_LINKING_DISTANCE()
@ -38,16 +50,6 @@ class LinkingListener : Listener {
return 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())) event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.LINK_SUCCESS()))
minion.setLinkedChest(event.clickedBlock!!.location) minion.setLinkedChest(event.clickedBlock!!.location)
} }