mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-20 07:29:21 +00:00
More work
This commit is contained in:
@@ -7,7 +7,9 @@ import com.willfp.ecobosses.bosses.bossHolders
|
||||
import com.willfp.ecobosses.commands.CommandEcobosses
|
||||
import com.willfp.ecobosses.config.EcoBossesYml
|
||||
import com.willfp.ecobosses.defence.DamageMultiplierHandler
|
||||
import com.willfp.ecobosses.defence.ImmunitiesHandler
|
||||
import com.willfp.ecobosses.defence.MountHandler
|
||||
import com.willfp.ecobosses.defence.PickupHandler
|
||||
import com.willfp.ecobosses.integrations.levelledmobs.IntegrationLevelledMobs
|
||||
import com.willfp.ecobosses.lifecycle.LifecycleHandlers
|
||||
import com.willfp.ecobosses.spawn.SpawnEggHandler
|
||||
@@ -42,7 +44,9 @@ class EcoBossesPlugin : LibReforgePlugin(525, 10635, "&9") {
|
||||
LifecycleHandlers(),
|
||||
SpawnEggHandler(),
|
||||
DamageMultiplierHandler(),
|
||||
MountHandler()
|
||||
MountHandler(),
|
||||
PickupHandler(),
|
||||
ImmunitiesHandler()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.bukkit.Bukkit
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.entity.EntityDeathEvent
|
||||
import java.util.Objects
|
||||
import java.util.UUID
|
||||
|
||||
@@ -217,12 +218,12 @@ class EcoBoss(
|
||||
messages[lifecycle]?.forEach { it.broadcast(location) }
|
||||
}
|
||||
|
||||
fun processRewards(player: Player, location: Location, entity: LivingEntity) {
|
||||
fun processRewards(player: Player?, location: Location, entity: LivingEntity, event: EntityDeathEvent) {
|
||||
for (drop in drops) {
|
||||
drop.drop(location, player)
|
||||
}
|
||||
|
||||
xp.drop(location, player)
|
||||
xp.modify(event)
|
||||
|
||||
for ((index, damager) in entity.topDamagers.withIndex()) {
|
||||
val rewards = commandRewards[index] ?: continue
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.willfp.ecobosses.defence
|
||||
|
||||
import com.willfp.ecobosses.bosses.Bosses
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.entity.EntityDamageEvent
|
||||
|
||||
class ImmunitiesHandler : Listener {
|
||||
@EventHandler(
|
||||
ignoreCancelled = true
|
||||
)
|
||||
fun handle(event: EntityDamageEvent) {
|
||||
val entity = event.entity as? LivingEntity ?: return
|
||||
val boss = Bosses[entity]?.boss ?: return
|
||||
|
||||
when (event.cause) {
|
||||
EntityDamageEvent.DamageCause.SUFFOCATION -> {
|
||||
if (boss.isImmuneToSuffocation) {
|
||||
event.isCancelled = true
|
||||
}
|
||||
}
|
||||
|
||||
EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION -> {
|
||||
if (boss.isImmuneToExplosions) {
|
||||
event.isCancelled = true
|
||||
}
|
||||
}
|
||||
|
||||
EntityDamageEvent.DamageCause.HOT_FLOOR, EntityDamageEvent.DamageCause.FIRE,
|
||||
EntityDamageEvent.DamageCause.FIRE_TICK, EntityDamageEvent.DamageCause.LAVA -> {
|
||||
if (boss.isImmuneToFire) {
|
||||
event.isCancelled = true
|
||||
}
|
||||
}
|
||||
|
||||
EntityDamageEvent.DamageCause.DROWNING -> {
|
||||
if (boss.isImmuneToDrowning) {
|
||||
event.isCancelled = true
|
||||
}
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.willfp.ecobosses.defence
|
||||
|
||||
import com.willfp.ecobosses.bosses.Bosses
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent
|
||||
|
||||
class PickupHandler : Listener {
|
||||
@EventHandler(
|
||||
ignoreCancelled = true
|
||||
)
|
||||
fun handle(event: EntityPickupItemEvent) {
|
||||
val entity = event.entity as? LivingEntity ?: return
|
||||
val boss = Bosses[entity]?.boss ?: return
|
||||
|
||||
event.isCancelled = true
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,12 @@ package com.willfp.ecobosses.events
|
||||
|
||||
import com.willfp.ecobosses.bosses.LivingEcoBoss
|
||||
import com.willfp.ecobosses.lifecycle.BossLifecycle
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.HandlerList
|
||||
|
||||
class BossKillEvent(
|
||||
boss: LivingEcoBoss,
|
||||
killer: Player?
|
||||
) : BossDeathEvent(boss) {
|
||||
override fun getHandlers(): HandlerList {
|
||||
return HANDLERS
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.willfp.ecobosses.lifecycle
|
||||
|
||||
import com.willfp.eco.core.events.EntityDeathByEntityEvent
|
||||
import com.willfp.ecobosses.bosses.Bosses
|
||||
import com.willfp.ecobosses.events.BossKillEvent
|
||||
import com.willfp.libreforge.tryAsPlayer
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.entity.EntityDeathEvent
|
||||
|
||||
class DeathListeners: Listener {
|
||||
@EventHandler(
|
||||
ignoreCancelled = true
|
||||
)
|
||||
fun handle(event: EntityDeathByEntityEvent) {
|
||||
val boss = Bosses[event.victim] ?: return
|
||||
|
||||
boss.kill(BossLifecycle.KILL)
|
||||
|
||||
val deathEvent = BossKillEvent(boss, event.killer.tryAsPlayer())
|
||||
Bukkit.getPluginManager().callEvent(deathEvent)
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
ignoreCancelled = true
|
||||
)
|
||||
fun handle(event: EntityDeathEvent) {
|
||||
val boss = Bosses[event.entity] ?: return
|
||||
|
||||
boss.kill(BossLifecycle.KILL)
|
||||
|
||||
val deathEvent = BossKillEvent(boss, null)
|
||||
Bukkit.getPluginManager().callEvent(deathEvent)
|
||||
}
|
||||
}
|
||||
@@ -5,18 +5,25 @@ import com.willfp.eco.util.NumberUtils
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.entity.EntityDeathEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
data class BossDrop(
|
||||
val chance: Double,
|
||||
val drops: Collection<ItemStack>
|
||||
) {
|
||||
fun drop(location: Location, player: Player) {
|
||||
fun drop(location: Location, player: Player?) {
|
||||
if (NumberUtils.randFloat(0.0, 100.0) < chance) {
|
||||
if (player != null) {
|
||||
DropQueue(player)
|
||||
.setLocation(location)
|
||||
.addItems(drops)
|
||||
.push()
|
||||
} else {
|
||||
for (drop in drops) {
|
||||
location.world?.dropItemNaturally(location, drop)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,10 +48,7 @@ data class XpReward(
|
||||
val minimum: Int,
|
||||
val maximum: Int
|
||||
) {
|
||||
fun drop(location: Location, player: Player) {
|
||||
DropQueue(player)
|
||||
.setLocation(location)
|
||||
.addXP(NumberUtils.randInt(minimum, maximum))
|
||||
.push()
|
||||
fun modify(event: EntityDeathEvent) {
|
||||
event.droppedExp = NumberUtils.randInt(minimum, maximum)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user