mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-19 23:19:17 +00:00
Added BossTryDropItemEvent
This commit is contained in:
@@ -330,7 +330,7 @@ class EcoBoss(
|
|||||||
val player = event.killer
|
val player = event.killer
|
||||||
|
|
||||||
for (drop in drops) {
|
for (drop in drops) {
|
||||||
drop.drop(location, player)
|
drop.drop(this, location, player)
|
||||||
}
|
}
|
||||||
|
|
||||||
xp.modify(event.event)
|
xp.modify(event.event)
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ package com.willfp.ecobosses.util
|
|||||||
|
|
||||||
import com.willfp.eco.core.drops.DropQueue
|
import com.willfp.eco.core.drops.DropQueue
|
||||||
import com.willfp.eco.util.NumberUtils
|
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.Bukkit
|
||||||
import org.bukkit.Location
|
import org.bukkit.Location
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
@@ -12,15 +14,19 @@ data class BossDrop(
|
|||||||
val chance: Double,
|
val chance: Double,
|
||||||
val drops: Collection<ItemStack>
|
val drops: Collection<ItemStack>
|
||||||
) {
|
) {
|
||||||
fun drop(location: Location, player: Player?) {
|
fun drop(boss: EcoBoss, location: Location, player: Player?) {
|
||||||
if (NumberUtils.randFloat(0.0, 100.0) < chance) {
|
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) {
|
if (player != null) {
|
||||||
DropQueue(player)
|
DropQueue(player)
|
||||||
.setLocation(location)
|
.setLocation(event.location)
|
||||||
.addItems(drops)
|
.addItems(event.items)
|
||||||
.push()
|
.push()
|
||||||
} else {
|
} else {
|
||||||
for (drop in drops) {
|
for (drop in event.items) {
|
||||||
location.world?.dropItemNaturally(location, drop)
|
location.world?.dropItemNaturally(location, drop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user