Add PreFisherMinionFishEvent

Add PreFisherMinionFishEvent
This commit is contained in:
TomTom 2024-05-30 15:58:55 +02:00 committed by GitHub
commit 7455961f37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 1 deletions

View File

@ -0,0 +1,41 @@
package com.artillexstudios.axminions.api.events
import com.artillexstudios.axminions.api.minions.Minion
import org.bukkit.event.Cancellable
import org.bukkit.event.HandlerList
import org.bukkit.inventory.ItemStack
class PreFisherMinionFishEvent(minion: Minion, var item: List<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 getLoots(): List<ItemStack> {
return item
}
fun setLoots(item: List<ItemStack>) {
this.item = item
}
fun setLoot(item: ItemStack) {
this.item = listOf(item)
}
override fun setCancelled(cancelled: Boolean) {
isCancelled = cancelled
}
}

View File

@ -1,6 +1,7 @@
package com.artillexstudios.axminions.minions.miniontype
import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.events.PreFisherMinionFishEvent
import com.artillexstudios.axminions.api.minions.Minion
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
import com.artillexstudios.axminions.api.utils.LocationUtils
@ -8,6 +9,7 @@ import com.artillexstudios.axminions.api.utils.fastFor
import com.artillexstudios.axminions.api.warnings.Warnings
import com.artillexstudios.axminions.minions.MinionTicker
import com.artillexstudios.axminions.nms.NMSHandler
import org.bukkit.Bukkit
import java.util.concurrent.ThreadLocalRandom
import kotlin.math.roundToInt
import org.bukkit.Location
@ -72,7 +74,16 @@ class FisherMinionType : MinionType("fisher", AxMinionsPlugin.INSTANCE.getResour
Warnings.remove(minion, Warnings.NO_TOOL)
val loot = NMSHandler.get().generateRandomFishingLoot(minion, waterLocation!!)
var loot = NMSHandler.get().generateRandomFishingLoot(minion, waterLocation!!)
val preFishEvent = PreFisherMinionFishEvent(minion, loot)
Bukkit.getPluginManager().callEvent(preFishEvent)
if (preFishEvent.isCancelled) {
return
}
if (preFishEvent.item != loot) {
loot = preFishEvent.item
}
val xp = ThreadLocalRandom.current().nextInt(6) + 1
minion.addToContainerOrDrop(loot)