diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/bosses/EcoBoss.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/bosses/EcoBoss.kt index 5ca7aa26..ef79bf6c 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/bosses/EcoBoss.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/bosses/EcoBoss.kt @@ -330,7 +330,7 @@ class EcoBoss( val player = event.killer for (drop in drops) { - drop.drop(location, player) + drop.drop(this, location, player) } xp.modify(event.event) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/events/BossTryDropItemEvent.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/events/BossTryDropItemEvent.kt new file mode 100644 index 00000000..611b4f65 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/events/BossTryDropItemEvent.kt @@ -0,0 +1,30 @@ +package com.willfp.ecobosses.events + +import com.willfp.ecobosses.bosses.EcoBoss +import com.willfp.ecobosses.bosses.LivingEcoBoss +import org.bukkit.Location +import org.bukkit.entity.Player +import org.bukkit.event.Event +import org.bukkit.event.HandlerList +import org.bukkit.inventory.ItemStack + +class BossTryDropItemEvent( + val boss: EcoBoss, + val location: Location, + var items: MutableCollection, + var chance: Double, + val player: Player? +): Event() { + override fun getHandlers(): HandlerList { + return HANDLERS + } + + companion object { + private val HANDLERS = HandlerList() + + @JvmStatic + fun getHandlerList(): HandlerList { + return HANDLERS + } + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/util/Rewards.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/util/Rewards.kt index bc0224ab..f03d437f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/util/Rewards.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/util/Rewards.kt @@ -2,6 +2,8 @@ package com.willfp.ecobosses.util import com.willfp.eco.core.drops.DropQueue import com.willfp.eco.util.NumberUtils +import com.willfp.ecobosses.bosses.EcoBoss +import com.willfp.ecobosses.events.BossTryDropItemEvent import org.bukkit.Bukkit import org.bukkit.Location import org.bukkit.entity.Player @@ -12,15 +14,19 @@ data class BossDrop( val chance: Double, val drops: Collection ) { - fun drop(location: Location, player: Player?) { - if (NumberUtils.randFloat(0.0, 100.0) < chance) { + fun drop(boss: EcoBoss, location: Location, player: Player?) { + val event = BossTryDropItemEvent(boss, location, drops.toMutableList(), chance, player) + + Bukkit.getPluginManager().callEvent(event) + + if (NumberUtils.randFloat(0.0, 100.0) < event.chance) { if (player != null) { DropQueue(player) - .setLocation(location) - .addItems(drops) + .setLocation(event.location) + .addItems(event.items) .push() } else { - for (drop in drops) { + for (drop in event.items) { location.world?.dropItemNaturally(location, drop) } }