mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-25 12:05:56 +01:00
add PreFisherMinionFishEvent
This commit is contained in:
parent
c35bae34da
commit
51a0818d2c
@ -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<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
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package com.artillexstudios.axminions.minions.miniontype
|
package com.artillexstudios.axminions.minions.miniontype
|
||||||
|
|
||||||
import com.artillexstudios.axminions.AxMinionsPlugin
|
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.Minion
|
||||||
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
|
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
|
||||||
import com.artillexstudios.axminions.api.utils.LocationUtils
|
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.api.warnings.Warnings
|
||||||
import com.artillexstudios.axminions.minions.MinionTicker
|
import com.artillexstudios.axminions.minions.MinionTicker
|
||||||
import com.artillexstudios.axminions.nms.NMSHandler
|
import com.artillexstudios.axminions.nms.NMSHandler
|
||||||
|
import org.bukkit.Bukkit
|
||||||
import java.util.concurrent.ThreadLocalRandom
|
import java.util.concurrent.ThreadLocalRandom
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import org.bukkit.Location
|
import org.bukkit.Location
|
||||||
@ -72,7 +75,16 @@ class FisherMinionType : MinionType("fisher", AxMinionsPlugin.INSTANCE.getResour
|
|||||||
|
|
||||||
Warnings.remove(minion, Warnings.NO_TOOL)
|
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
|
val xp = ThreadLocalRandom.current().nextInt(6) + 1
|
||||||
|
|
||||||
minion.addToContainerOrDrop(loot)
|
minion.addToContainerOrDrop(loot)
|
||||||
|
Loading…
Reference in New Issue
Block a user