mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-25 12:05:56 +01:00
add MinionPreBreakEvent
This commit is contained in:
parent
9410d74832
commit
0d2725ec8d
@ -0,0 +1,33 @@
|
||||
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.HandlerList
|
||||
|
||||
class MinionPreBreakEvent(private val player: Player, minion: Minion) : MinionEvent(minion), Cancellable {
|
||||
companion object {
|
||||
private val handlerList = HandlerList()
|
||||
|
||||
@JvmStatic
|
||||
fun getHandlerList(): HandlerList = handlerList
|
||||
}
|
||||
|
||||
private var isCancelled = false
|
||||
|
||||
override fun getHandlers(): HandlerList {
|
||||
return MinionPreBreakEvent.handlerList
|
||||
}
|
||||
|
||||
fun getPlayer(): Player {
|
||||
return player
|
||||
}
|
||||
|
||||
override fun isCancelled(): Boolean {
|
||||
return isCancelled
|
||||
}
|
||||
|
||||
override fun setCancelled(cancelled: Boolean) {
|
||||
isCancelled = cancelled
|
||||
}
|
||||
}
|
@ -47,6 +47,8 @@ class MinionPlaceListener : Listener {
|
||||
return
|
||||
}
|
||||
|
||||
val prePlaceEvent = MinionPrePlaceEvent(event.player, event.clickedBlock!!.location)
|
||||
|
||||
val level = meta.persistentDataContainer.get(Keys.LEVEL, PersistentDataType.INTEGER) ?: 0
|
||||
val stats = meta.persistentDataContainer.get(Keys.STATISTICS, PersistentDataType.LONG) ?: 0
|
||||
val charge = meta.persistentDataContainer.get(Keys.CHARGE, PersistentDataType.LONG) ?: 0
|
||||
@ -58,6 +60,9 @@ class MinionPlaceListener : Listener {
|
||||
|
||||
if (meta.persistentDataContainer.has(Keys.PLACED, PersistentDataType.BYTE)) return
|
||||
|
||||
Bukkit.getPluginManager().callEvent(prePlaceEvent)
|
||||
if(prePlaceEvent.isCancelled) return
|
||||
|
||||
meta.persistentDataContainer.set(Keys.PLACED, PersistentDataType.BYTE, 0)
|
||||
item.itemMeta = meta
|
||||
|
||||
@ -67,10 +72,6 @@ class MinionPlaceListener : Listener {
|
||||
|
||||
val chunk = location.chunk
|
||||
|
||||
val prePlaceEvent = MinionPrePlaceEvent(event.player, event.clickedBlock!!.location)
|
||||
Bukkit.getPluginManager().callEvent(prePlaceEvent)
|
||||
if(prePlaceEvent.isCancelled) return
|
||||
|
||||
AxMinionsPlugin.dataQueue.submit {
|
||||
val placed = AxMinionsPlugin.dataHandler.getMinionAmount(event.player.uniqueId)
|
||||
|
||||
|
@ -16,6 +16,8 @@ import com.artillexstudios.axminions.AxMinionsPlugin
|
||||
import com.artillexstudios.axminions.api.AxMinionsAPI
|
||||
import com.artillexstudios.axminions.api.config.Config
|
||||
import com.artillexstudios.axminions.api.config.Messages
|
||||
import com.artillexstudios.axminions.api.events.MinionPreBreakEvent
|
||||
import com.artillexstudios.axminions.api.events.MinionPrePlaceEvent
|
||||
import com.artillexstudios.axminions.api.minions.Direction
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
|
||||
@ -164,6 +166,10 @@ class Minion(
|
||||
}
|
||||
|
||||
private fun breakMinion(event: PacketEntityInteractEvent) {
|
||||
val preBreakEvent = MinionPreBreakEvent(event.player, this)
|
||||
Bukkit.getPluginManager().callEvent(preBreakEvent)
|
||||
if(preBreakEvent.isCancelled) return
|
||||
|
||||
LinkingListener.linking.remove(event.player)
|
||||
remove()
|
||||
setTicking(false)
|
||||
|
Loading…
Reference in New Issue
Block a user