Skip to content

Commit

Permalink
Added BossTryDropItemEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Feb 10, 2022
1 parent b152313 commit 1e00b28
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ItemStack>,
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,15 +14,19 @@ data class BossDrop(
val chance: Double,
val drops: Collection<ItemStack>
) {
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)
}
}
Expand Down

0 comments on commit 1e00b28

Please sign in to comment.