diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreFisherMinionFishEvent.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreFisherMinionFishEvent.kt new file mode 100644 index 0000000..b03e5c5 --- /dev/null +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreFisherMinionFishEvent.kt @@ -0,0 +1,42 @@ +package com.artillexstudios.axminions.api.events + +import com.artillexstudios.axminions.api.minions.Minion +import org.bukkit.block.Block +import org.bukkit.event.Cancellable +import org.bukkit.event.HandlerList +import org.bukkit.inventory.ItemStack + +class PreFisherMinionFishEvent(minion: Minion, var item: List) : 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 { + return item + } + + fun setLoots(item: List) { + this.item = item + } + + fun setLoot(item: ItemStack) { + this.item = listOf(item) + } + + override fun setCancelled(cancelled: Boolean) { + isCancelled = cancelled + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FisherMinionType.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FisherMinionType.kt index 54d4dc7..05f1d28 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FisherMinionType.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FisherMinionType.kt @@ -1,6 +1,8 @@ package com.artillexstudios.axminions.minions.miniontype import com.artillexstudios.axminions.AxMinionsPlugin +import com.artillexstudios.axminions.api.events.PreFarmerMinionHarvestEvent +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 +10,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 +75,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)