mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-21 16:09:24 +00:00
Continued rewrite some more
This commit is contained in:
@@ -57,7 +57,7 @@ allprojects {
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate('com.willfp.libreforge', 'com.willfp.ecoarmor.libreforge')
|
||||
relocate('com.willfp.libreforge', 'com.willfp.ecobosses.libreforge')
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
package com.willfp.ecobosses
|
||||
|
||||
import com.willfp.eco.core.command.impl.PluginCommand
|
||||
import com.willfp.eco.core.integrations.IntegrationLoader
|
||||
import com.willfp.ecobosses.bosses.EcoBosses
|
||||
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.MountHandler
|
||||
import com.willfp.ecobosses.integrations.levelledmobs.IntegrationLevelledMobs
|
||||
import com.willfp.ecobosses.lifecycle.LifecycleHandlers
|
||||
import com.willfp.ecobosses.spawn.SpawnEggHandler
|
||||
import com.willfp.ecobosses.util.DiscoverRecipeListener
|
||||
import com.willfp.ecobosses.util.TopDamagerListener
|
||||
import com.willfp.libreforge.LibReforgePlugin
|
||||
import org.bukkit.event.Listener
|
||||
|
||||
@@ -30,7 +37,18 @@ class EcoBossesPlugin : LibReforgePlugin(525, 10635, "&9") {
|
||||
|
||||
override fun loadListeners(): List<Listener> {
|
||||
return listOf(
|
||||
DiscoverRecipeListener(this)
|
||||
DiscoverRecipeListener(this),
|
||||
TopDamagerListener(),
|
||||
LifecycleHandlers(),
|
||||
SpawnEggHandler(),
|
||||
DamageMultiplierHandler(),
|
||||
MountHandler()
|
||||
)
|
||||
}
|
||||
|
||||
override fun loadAdditionalIntegrations(): List<IntegrationLoader> {
|
||||
return listOf(
|
||||
IntegrationLoader("LevelledMobs") { this.eventManager.registerListener(IntegrationLevelledMobs()) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.willfp.ecobosses.bosses
|
||||
|
||||
import com.willfp.ecobosses.EcoBossesPlugin
|
||||
import com.willfp.libreforge.Holder
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
import kotlin.math.pow
|
||||
|
||||
val Player.bossHolders: Iterable<Holder>
|
||||
@@ -21,4 +24,24 @@ val Player.bossHolders: Iterable<Holder>
|
||||
}
|
||||
|
||||
return holders
|
||||
}
|
||||
}
|
||||
|
||||
private val spawnEggKey = EcoBossesPlugin.instance.namespacedKeyFactory.create("spawn_egg")
|
||||
|
||||
var ItemStack.bossEgg: EcoBoss?
|
||||
set(value) {
|
||||
val meta = this.itemMeta ?: return
|
||||
val pdc = meta.persistentDataContainer
|
||||
if (value == null) {
|
||||
pdc.remove(spawnEggKey)
|
||||
} else {
|
||||
pdc.set(spawnEggKey, PersistentDataType.STRING, value.id)
|
||||
}
|
||||
this.itemMeta = meta
|
||||
}
|
||||
get() {
|
||||
val meta = this.itemMeta ?: return null
|
||||
val pdc = meta.persistentDataContainer
|
||||
val id = pdc.get(spawnEggKey, PersistentDataType.STRING) ?: return null
|
||||
return Bosses.getByID(id)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.willfp.eco.core.entities.Entities
|
||||
import com.willfp.eco.core.entities.TestableEntity
|
||||
import com.willfp.eco.core.items.Items
|
||||
import com.willfp.eco.util.toComponent
|
||||
import com.willfp.ecobosses.lifecycle.BossLifecycle
|
||||
import com.willfp.ecobosses.tick.BossBarTicker
|
||||
import com.willfp.ecobosses.tick.BossTicker
|
||||
import com.willfp.ecobosses.tick.DisplayNameTicker
|
||||
@@ -17,10 +18,12 @@ import com.willfp.ecobosses.util.ConfiguredSound
|
||||
import com.willfp.ecobosses.util.LocalBroadcast
|
||||
import com.willfp.ecobosses.util.PlayableSound
|
||||
import com.willfp.ecobosses.util.XpReward
|
||||
import com.willfp.ecobosses.util.topDamagers
|
||||
import com.willfp.libreforge.Holder
|
||||
import com.willfp.libreforge.conditions.ConfiguredCondition
|
||||
import com.willfp.libreforge.effects.Effects
|
||||
import net.kyori.adventure.bossbar.BossBar
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.entity.Player
|
||||
@@ -47,6 +50,20 @@ class EcoBoss(
|
||||
|
||||
val bossBarRadius = config.getDouble("bossBar.radius")
|
||||
|
||||
val isPreventingMounts = config.getBool("defence.preventMounts")
|
||||
|
||||
val isImmuneToExplosions = config.getBool("defence.explosionImmune")
|
||||
|
||||
val isImmuneToFire = config.getBool("defence.fireImmune")
|
||||
|
||||
val isImmuneToDrowning = config.getBool("defence.drowningImmune")
|
||||
|
||||
val isImmuneToSuffocation = config.getBool("defence.suffocationImmune")
|
||||
|
||||
val meleeDamageMultiplier = config.getDouble("defence.meleeDamageMultiplier")
|
||||
|
||||
val projectileDamageMultiplier = config.getDouble("defence.projectileDamageMultiplier")
|
||||
|
||||
private val bossBarColor = BossBar.Color.valueOf(config.getString("bossBar.color").uppercase())
|
||||
|
||||
private val bossBarStyle = BossBar.Overlay.valueOf(config.getString("bossBar.style").uppercase())
|
||||
@@ -200,12 +217,30 @@ class EcoBoss(
|
||||
messages[lifecycle]?.forEach { it.broadcast(location) }
|
||||
}
|
||||
|
||||
fun processRewards(player: Player, location: Location) {
|
||||
fun processRewards(player: Player, location: Location, entity: LivingEntity) {
|
||||
for (drop in drops) {
|
||||
drop.drop(location, player)
|
||||
}
|
||||
|
||||
xp.drop(location, player)
|
||||
|
||||
for ((index, damager) in entity.topDamagers.withIndex()) {
|
||||
val rewards = commandRewards[index] ?: continue
|
||||
val player = Bukkit.getPlayer(damager.uuid) ?: continue
|
||||
for (reward in rewards) {
|
||||
reward.reward(player)
|
||||
}
|
||||
}
|
||||
|
||||
for (nearbyPlayer in entity.getNearbyEntities(
|
||||
nearbyCommandRewardRadius,
|
||||
nearbyCommandRewardRadius,
|
||||
nearbyCommandRewardRadius
|
||||
).filterIsInstance<Player>()) {
|
||||
for (command in nearbyCommands) {
|
||||
command.reward(nearbyPlayer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.willfp.ecobosses.bosses
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.ecobosses.lifecycle.BossLifecycle
|
||||
import com.willfp.ecobosses.tick.BossTicker
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.entity.Mob
|
||||
import java.util.UUID
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.willfp.ecobosses.defence
|
||||
|
||||
import com.willfp.ecobosses.bosses.Bosses
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.entity.Projectile
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent
|
||||
|
||||
class DamageMultiplierHandler : Listener {
|
||||
@EventHandler(
|
||||
ignoreCancelled = true
|
||||
)
|
||||
fun handle(event: EntityDamageByEntityEvent) {
|
||||
val entity = event.entity as? LivingEntity ?: return
|
||||
val boss = Bosses[entity]?.boss ?: return
|
||||
|
||||
if (event.damager is Player) {
|
||||
event.damage *= boss.meleeDamageMultiplier
|
||||
}
|
||||
|
||||
if (event.damager is Projectile) {
|
||||
event.damage *= boss.projectileDamageMultiplier
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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.spigotmc.event.entity.EntityMountEvent
|
||||
|
||||
class MountHandler : Listener {
|
||||
@EventHandler(
|
||||
ignoreCancelled = true
|
||||
)
|
||||
fun handle(event: EntityMountEvent) {
|
||||
val entity = event.entity as? LivingEntity ?: return
|
||||
val boss = Bosses[entity]?.boss ?: return
|
||||
|
||||
if (boss.isPreventingMounts) {
|
||||
event.isCancelled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.willfp.ecobosses.events
|
||||
|
||||
import com.willfp.ecobosses.bosses.LivingEcoBoss
|
||||
import com.willfp.ecobosses.lifecycle.BossLifecycle
|
||||
import org.bukkit.event.Event
|
||||
import org.bukkit.event.HandlerList
|
||||
|
||||
abstract class BossDeathEvent(
|
||||
val boss: LivingEcoBoss,
|
||||
) : Event() {
|
||||
override fun getHandlers(): HandlerList {
|
||||
return HANDLERS
|
||||
}
|
||||
|
||||
abstract val lifecycle: BossLifecycle
|
||||
|
||||
companion object {
|
||||
private val HANDLERS = HandlerList()
|
||||
|
||||
@JvmStatic
|
||||
fun getHandlerList(): HandlerList {
|
||||
return HANDLERS
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.willfp.ecobosses.events
|
||||
|
||||
import com.willfp.ecobosses.bosses.LivingEcoBoss
|
||||
import com.willfp.ecobosses.lifecycle.BossLifecycle
|
||||
import org.bukkit.event.HandlerList
|
||||
|
||||
class BossDespawnEvent(
|
||||
boss: LivingEcoBoss,
|
||||
) : BossDeathEvent(boss) {
|
||||
override fun getHandlers(): HandlerList {
|
||||
return HANDLERS
|
||||
}
|
||||
|
||||
override val lifecycle: BossLifecycle = BossLifecycle.DESPAWN
|
||||
|
||||
companion object {
|
||||
private val HANDLERS = HandlerList()
|
||||
|
||||
@JvmStatic
|
||||
fun getHandlerList(): HandlerList {
|
||||
return HANDLERS
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.willfp.ecobosses.events
|
||||
|
||||
import com.willfp.ecobosses.bosses.LivingEcoBoss
|
||||
import com.willfp.ecobosses.lifecycle.BossLifecycle
|
||||
import org.bukkit.event.HandlerList
|
||||
|
||||
class BossKillEvent(
|
||||
boss: LivingEcoBoss,
|
||||
) : BossDeathEvent(boss) {
|
||||
override fun getHandlers(): HandlerList {
|
||||
return HANDLERS
|
||||
}
|
||||
|
||||
override val lifecycle: BossLifecycle = BossLifecycle.KILL
|
||||
|
||||
companion object {
|
||||
private val HANDLERS = HandlerList()
|
||||
|
||||
@JvmStatic
|
||||
fun getHandlerList(): HandlerList {
|
||||
return HANDLERS
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.willfp.ecobosses.events
|
||||
|
||||
import com.willfp.ecobosses.bosses.EcoBoss
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.event.Cancellable
|
||||
import org.bukkit.event.Event
|
||||
import org.bukkit.event.HandlerList
|
||||
|
||||
class BossSpawnEvent(
|
||||
val boss: EcoBoss,
|
||||
val location: Location,
|
||||
val reason: SpawnReason
|
||||
) : Event(), Cancellable {
|
||||
private var isCancelled: Boolean = false
|
||||
|
||||
override fun isCancelled(): Boolean {
|
||||
return isCancelled
|
||||
}
|
||||
|
||||
override fun setCancelled(cancelled: Boolean) {
|
||||
isCancelled = cancelled
|
||||
}
|
||||
|
||||
override fun getHandlers(): HandlerList {
|
||||
return HANDLERS
|
||||
}
|
||||
|
||||
enum class SpawnReason {
|
||||
TOTEM,
|
||||
EGG,
|
||||
COMMAND,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val HANDLERS = HandlerList()
|
||||
|
||||
@JvmStatic
|
||||
fun getHandlerList(): HandlerList {
|
||||
return HANDLERS
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.ecobosses.bosses
|
||||
package com.willfp.ecobosses.lifecycle
|
||||
|
||||
enum class BossLifecycle {
|
||||
SPAWN,
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.willfp.ecobosses.lifecycle
|
||||
|
||||
import com.willfp.ecobosses.bosses.Bosses
|
||||
import com.willfp.ecobosses.events.BossDeathEvent
|
||||
import com.willfp.ecobosses.events.BossSpawnEvent
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.entity.EntityDamageEvent
|
||||
|
||||
class LifecycleHandlers : Listener {
|
||||
@EventHandler(
|
||||
ignoreCancelled = true,
|
||||
priority = EventPriority.MONITOR
|
||||
)
|
||||
fun onInjure(event: EntityDamageEvent) {
|
||||
val entity = event.entity as? LivingEntity ?: return
|
||||
val boss = Bosses[entity] ?: return
|
||||
|
||||
boss.boss.handleLifecycle(BossLifecycle.INJURE, entity.location)
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
ignoreCancelled = true,
|
||||
priority = EventPriority.MONITOR
|
||||
)
|
||||
fun onInjure(event: BossDeathEvent) {
|
||||
event.boss.boss.handleLifecycle(event.lifecycle, event.boss.entity?.location ?: return)
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
ignoreCancelled = true,
|
||||
priority = EventPriority.MONITOR
|
||||
)
|
||||
fun onInjure(event: BossSpawnEvent) {
|
||||
event.boss.handleLifecycle(BossLifecycle.SPAWN, event.location)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.willfp.ecobosses.spawn
|
||||
|
||||
import com.willfp.ecobosses.bosses.bossEgg
|
||||
import com.willfp.ecobosses.events.BossSpawnEvent
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.event.Event
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.block.Action
|
||||
import org.bukkit.event.player.PlayerInteractEvent
|
||||
import org.bukkit.inventory.EquipmentSlot
|
||||
|
||||
class SpawnEggHandler : Listener {
|
||||
@EventHandler(
|
||||
ignoreCancelled = true
|
||||
)
|
||||
fun handle(event: PlayerInteractEvent) {
|
||||
if (event.action != Action.RIGHT_CLICK_BLOCK) {
|
||||
return
|
||||
}
|
||||
|
||||
val item = event.item ?: return
|
||||
val boss = item.bossEgg ?: return
|
||||
|
||||
event.isCancelled = true
|
||||
event.setUseItemInHand(Event.Result.DENY)
|
||||
|
||||
val location = event.clickedBlock?.location?.add(0.0, 1.5, 0.0) ?: return
|
||||
|
||||
val spawnEvent = BossSpawnEvent(boss, location, BossSpawnEvent.SpawnReason.EGG)
|
||||
|
||||
Bukkit.getPluginManager().callEvent(spawnEvent)
|
||||
|
||||
if (spawnEvent.isCancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.hand == EquipmentSlot.HAND) {
|
||||
val hand = event.player.inventory.itemInMainHand
|
||||
hand.amount = hand.amount - 1
|
||||
} else {
|
||||
val hand = event.player.inventory.itemInOffHand
|
||||
hand.amount = hand.amount - 1
|
||||
}
|
||||
|
||||
boss.spawn(location)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.ecobosses.tick
|
||||
|
||||
import com.willfp.ecobosses.bosses.BossLifecycle
|
||||
import com.willfp.ecobosses.lifecycle.BossLifecycle
|
||||
import com.willfp.ecobosses.bosses.LivingEcoBoss
|
||||
|
||||
class LifespanTicker : BossTicker {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.willfp.ecobosses.util
|
||||
|
||||
import com.willfp.ecobosses.EcoBossesPlugin
|
||||
import com.willfp.libreforge.tryAsPlayer
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent
|
||||
import java.util.UUID
|
||||
|
||||
data class Damager(
|
||||
val uuid: UUID,
|
||||
var damage: Double
|
||||
)
|
||||
|
||||
private const val metaKey = "TOP_DAMAGERS"
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
var LivingEntity.topDamagers: List<Damager>
|
||||
get() = (this.getMetadata(metaKey).getOrNull(0) as? List<Damager>) ?: emptyList()
|
||||
private set(value) {
|
||||
this.removeMetadata(metaKey, EcoBossesPlugin.instance)
|
||||
this.setMetadata(metaKey, EcoBossesPlugin.instance.metadataValueFactory.create(value))
|
||||
}
|
||||
|
||||
class TopDamagerListener : Listener {
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
fun handle(event: EntityDamageByEntityEvent) {
|
||||
val uuid = event.damager.tryAsPlayer()?.uniqueId ?: return
|
||||
|
||||
val victim = event.entity as? LivingEntity ?: return
|
||||
|
||||
val topDamagers = victim.topDamagers.toMutableList()
|
||||
|
||||
val damager = topDamagers.firstOrNull { it.uuid == uuid } ?: Damager(uuid, 0.0)
|
||||
damager.damage += event.damage
|
||||
topDamagers.removeIf { it.uuid == uuid }
|
||||
topDamagers.add(damager)
|
||||
victim.topDamagers = topDamagers.sortedByDescending { it.damage }
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,15 @@ bosses:
|
||||
mob: iron_golem
|
||||
displayName: "&8Steel Golem &7| &c%health%♥ &7| &e%time%"
|
||||
effects: [ ]
|
||||
defence:
|
||||
preventMounts: true
|
||||
explosionImmune: true
|
||||
fireImmune: true
|
||||
drowningImmune: true
|
||||
suffocationImmune: true
|
||||
|
||||
meleeDamageMultiplier: 0.8
|
||||
projectileDamageMultiplier: 0.2
|
||||
rewards:
|
||||
xp:
|
||||
minimum: 30000
|
||||
|
||||
Reference in New Issue
Block a user