mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-20 15:39:31 +00:00
@@ -190,6 +190,18 @@ class EcoBoss(
|
||||
map
|
||||
}
|
||||
|
||||
private val commands: Map<BossLifecycle, Iterable<LocalCommands>> = run {
|
||||
val map = mutableMapOf<BossLifecycle, Iterable<LocalCommands>>()
|
||||
|
||||
for (value in BossLifecycle.values()) {
|
||||
map[value] = config.getSubsections("messages.${value.name.lowercase()}").map {
|
||||
LocalCommands.fromConfig(it)
|
||||
}
|
||||
}
|
||||
|
||||
map
|
||||
}
|
||||
|
||||
private val commandRewards: Map<Int, Iterable<CommandReward>> = run {
|
||||
val map = mutableMapOf<Int, Iterable<CommandReward>>()
|
||||
|
||||
@@ -324,6 +336,8 @@ class EcoBoss(
|
||||
fun handleLifecycle(lifecycle: BossLifecycle, location: Location, entity: LivingEntity?) {
|
||||
sounds[lifecycle]?.play(location)
|
||||
messages[lifecycle]?.forEach { it.broadcast(location, entity?.topDamagers ?: emptyList()) }
|
||||
commands[lifecycle]?.forEach { it.dispatch(location, entity?.topDamagers ?: emptyList()) }
|
||||
|
||||
}
|
||||
|
||||
fun processRewards(event: BossKillEvent) {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.willfp.ecobosses.util
|
||||
|
||||
import com.willfp.eco.core.config.interfaces.Config
|
||||
import com.willfp.eco.util.NumberUtils
|
||||
import com.willfp.eco.util.formatEco
|
||||
import com.willfp.eco.util.savedDisplayName
|
||||
import com.willfp.ecobosses.EcoBossesPlugin
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Location
|
||||
|
||||
data class LocalCommands(
|
||||
val commands: Iterable<String>,
|
||||
) {
|
||||
fun dispatch(location: Location, topDamagers: List<Damager>) {
|
||||
val toDispatch = commands.toMutableList()
|
||||
toDispatch.replaceAll {
|
||||
var command = it
|
||||
|
||||
for (i in 1..20) {
|
||||
val damager = topDamagers.getOrNull(i - 1)
|
||||
val damage = if (damager?.damage != null) NumberUtils.format(damager.damage) else
|
||||
EcoBossesPlugin.instance.langYml.getFormattedString("na")
|
||||
val player = if (damager?.uuid != null) Bukkit.getOfflinePlayer(damager.uuid).savedDisplayName else
|
||||
EcoBossesPlugin.instance.langYml.getFormattedString("na")
|
||||
|
||||
command = command.replace("%damage_${i}%", damage)
|
||||
.replace("%damage_${i}_player%", player)
|
||||
}
|
||||
|
||||
command = command.replace("%x%", location.blockX.toString())
|
||||
.replace("%y%", location.blockY.toString())
|
||||
.replace("%z%", location.blockZ.toString())
|
||||
|
||||
command.formatEco()
|
||||
}
|
||||
|
||||
for (s in toDispatch) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun fromConfig(config: Config): LocalCommands {
|
||||
return LocalCommands(
|
||||
config.getStrings("commands"),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user