diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/EcoBossesPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/EcoBossesPlugin.kt index 331e2f2..b178055 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/EcoBossesPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/EcoBossesPlugin.kt @@ -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() ) } 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 d9a6692..078002a 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 @@ -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 diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/defence/ImmunitiesHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/defence/ImmunitiesHandler.kt new file mode 100644 index 0000000..601bee1 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/defence/ImmunitiesHandler.kt @@ -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 -> {} + } + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/defence/PickupHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/defence/PickupHandler.kt new file mode 100644 index 0000000..9520155 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/defence/PickupHandler.kt @@ -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 + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/events/BossKillEvent.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/events/BossKillEvent.kt index 6d356cb..bdff221 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/events/BossKillEvent.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/events/BossKillEvent.kt @@ -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 diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/lifecycle/DeathListeners.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/lifecycle/DeathListeners.kt new file mode 100644 index 0000000..6807415 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecobosses/lifecycle/DeathListeners.kt @@ -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) + } +} 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 6df4a9f..bc0224a 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 @@ -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 ) { - fun drop(location: Location, player: Player) { + fun drop(location: Location, player: Player?) { if (NumberUtils.randFloat(0.0, 100.0) < chance) { - DropQueue(player) - .setLocation(location) - .addItems(drops) - .push() + 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) } }