From 51a0818d2cb2fd817ae237cdfbe1538267c7290a Mon Sep 17 00:00:00 2001 From: rudde Date: Mon, 27 May 2024 13:28:33 +0300 Subject: [PATCH 1/2] add PreFisherMinionFishEvent --- .../api/events/PreFisherMinionFishEvent.kt | 42 +++++++++++++++++++ .../minions/miniontype/FisherMinionType.kt | 14 ++++++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreFisherMinionFishEvent.kt 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) From 0f7da1330fea45082ad4516f1df1c8476690c3c8 Mon Sep 17 00:00:00 2001 From: rudde Date: Mon, 27 May 2024 13:29:48 +0300 Subject: [PATCH 2/2] remove unnecessary imports --- .../axminions/api/events/PreFisherMinionFishEvent.kt | 1 - .../axminions/minions/miniontype/FisherMinionType.kt | 1 - 2 files changed, 2 deletions(-) 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 index b03e5c5..4027002 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreFisherMinionFishEvent.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/events/PreFisherMinionFishEvent.kt @@ -1,7 +1,6 @@ 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 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 05f1d28..1931959 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,7 +1,6 @@ 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