mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2025-01-06 18:47:48 +01:00
add MinionToolEvent
This commit is contained in:
parent
c35bae34da
commit
3284681ef9
@ -0,0 +1,39 @@
|
|||||||
|
package com.artillexstudios.axminions.api.events
|
||||||
|
|
||||||
|
import com.artillexstudios.axminions.api.minions.Minion
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import org.bukkit.event.Cancellable
|
||||||
|
import org.bukkit.event.Event
|
||||||
|
import org.bukkit.event.HandlerList
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
|
||||||
|
class MinionToolEvent(minion: Minion, private val player: Player, private val newTool: ItemStack) : MinionEvent(minion), Cancellable {
|
||||||
|
companion object {
|
||||||
|
private val handlerList = HandlerList()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun getHandlerList(): HandlerList = handlerList
|
||||||
|
}
|
||||||
|
|
||||||
|
private var isCancelled = false
|
||||||
|
|
||||||
|
override fun getHandlers(): HandlerList {
|
||||||
|
return handlerList
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isCancelled(): Boolean {
|
||||||
|
return isCancelled
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getPlayer(): Player {
|
||||||
|
return player
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getNewTool(): ItemStack {
|
||||||
|
return newTool
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setCancelled(cancelled: Boolean) {
|
||||||
|
isCancelled = cancelled
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import com.artillexstudios.axminions.AxMinionsPlugin
|
|||||||
import com.artillexstudios.axminions.api.AxMinionsAPI
|
import com.artillexstudios.axminions.api.AxMinionsAPI
|
||||||
import com.artillexstudios.axminions.api.config.Config
|
import com.artillexstudios.axminions.api.config.Config
|
||||||
import com.artillexstudios.axminions.api.config.Messages
|
import com.artillexstudios.axminions.api.config.Messages
|
||||||
|
import com.artillexstudios.axminions.api.events.MinionToolEvent
|
||||||
import com.artillexstudios.axminions.api.minions.Direction
|
import com.artillexstudios.axminions.api.minions.Direction
|
||||||
import com.artillexstudios.axminions.api.minions.Minion
|
import com.artillexstudios.axminions.api.minions.Minion
|
||||||
import com.artillexstudios.axminions.api.minions.miniontype.MinionTypes
|
import com.artillexstudios.axminions.api.minions.miniontype.MinionTypes
|
||||||
@ -14,6 +15,7 @@ import com.artillexstudios.axminions.api.utils.fastFor
|
|||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import net.md_5.bungee.api.ChatMessageType
|
import net.md_5.bungee.api.ChatMessageType
|
||||||
import net.md_5.bungee.api.chat.TextComponent
|
import net.md_5.bungee.api.chat.TextComponent
|
||||||
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.Sound
|
import org.bukkit.Sound
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
@ -65,6 +67,9 @@ class MinionInventoryListener : Listener {
|
|||||||
player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.WRONG_TOOL()))
|
player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.WRONG_TOOL()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
val minionToolEvent = MinionToolEvent(minion, player, event.currentItem!!)
|
||||||
|
Bukkit.getPluginManager().callEvent(minionToolEvent)
|
||||||
|
if (minionToolEvent.isCancelled) return
|
||||||
|
|
||||||
if (minion.getTool()?.type != Material.AIR) {
|
if (minion.getTool()?.type != Material.AIR) {
|
||||||
val current = event.currentItem!!.clone()
|
val current = event.currentItem!!.clone()
|
||||||
@ -88,6 +93,9 @@ class MinionInventoryListener : Listener {
|
|||||||
player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.ERROR_INVENTORY_FULL()))
|
player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.ERROR_INVENTORY_FULL()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
val minionToolEvent = MinionToolEvent(minion, player, ItemStack(Material.AIR))
|
||||||
|
Bukkit.getPluginManager().callEvent(minionToolEvent)
|
||||||
|
if (minionToolEvent.isCancelled) return
|
||||||
|
|
||||||
val tool = minion.getTool()?.clone() ?: return
|
val tool = minion.getTool()?.clone() ?: return
|
||||||
minion.setTool(ItemStack(Material.AIR))
|
minion.setTool(ItemStack(Material.AIR))
|
||||||
|
Loading…
Reference in New Issue
Block a user