mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-29 12:45:18 +01:00
custom fail message for MinionChestLinkEvent
This commit is contained in:
parent
05b36a3669
commit
9410d74832
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user