mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-02 21:20:55 +00:00
chaos: boss bar
This commit is contained in:
parent
6c16884ae2
commit
086f7dba10
@ -4,8 +4,13 @@ import gay.pizza.foundation.chaos.model.ChaosConfig
|
||||
import gay.pizza.foundation.chaos.modules.ChaosModule
|
||||
import gay.pizza.foundation.chaos.modules.ChaosModules
|
||||
import net.kyori.adventure.text.Component
|
||||
import org.bukkit.boss.BarColor
|
||||
import org.bukkit.boss.BarStyle
|
||||
import org.bukkit.boss.BossBar
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.HandlerList
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.player.PlayerJoinEvent
|
||||
import org.bukkit.plugin.Plugin
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
@ -17,6 +22,8 @@ class ChaosController(val plugin: Plugin, val config: ChaosConfig) : Listener {
|
||||
private var allowedModules: List<ChaosModule> = emptyList()
|
||||
private var activeModules = mutableSetOf<ChaosModule>()
|
||||
|
||||
var bossBar: BossBar? = null
|
||||
|
||||
fun load() {
|
||||
if (state.get()) {
|
||||
return
|
||||
@ -24,6 +31,10 @@ class ChaosController(val plugin: Plugin, val config: ChaosConfig) : Listener {
|
||||
allowedModules = allModules.filter { config.enable[it.id()] ?: true }
|
||||
state.set(true)
|
||||
selectorController.schedule()
|
||||
bossBar = plugin.server.createBossBar("Chaos Mode", BarColor.RED, BarStyle.SOLID)
|
||||
for (player in plugin.server.onlinePlayers) {
|
||||
bossBar?.addPlayer(player)
|
||||
}
|
||||
}
|
||||
|
||||
fun activateAll() {
|
||||
@ -39,14 +50,19 @@ class ChaosController(val plugin: Plugin, val config: ChaosConfig) : Listener {
|
||||
plugin.server.pluginManager.registerEvents(module, plugin)
|
||||
module.activate()
|
||||
activeModules.add(module)
|
||||
plugin.server.broadcast(Component.text("Chaos Module Activated: ${module.id()}"))
|
||||
updateBossBar()
|
||||
}
|
||||
|
||||
fun deactivate(module: ChaosModule) {
|
||||
HandlerList.unregisterAll(module)
|
||||
module.deactivate()
|
||||
activeModules.remove(module)
|
||||
plugin.server.broadcast(Component.text("Chaos Module Deactivated: ${module.id()}"))
|
||||
updateBossBar()
|
||||
}
|
||||
|
||||
fun updateBossBar() {
|
||||
val activeModuleText = activeModules.joinToString(", ") { it.name() }
|
||||
bossBar?.setTitle("Chaos Mode: $activeModuleText")
|
||||
}
|
||||
|
||||
fun deactivateAll() {
|
||||
@ -55,11 +71,18 @@ class ChaosController(val plugin: Plugin, val config: ChaosConfig) : Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onPlayerJoin(event: PlayerJoinEvent) {
|
||||
bossBar?.addPlayer(event.player)
|
||||
}
|
||||
|
||||
fun unload() {
|
||||
if (!state.get()) {
|
||||
return
|
||||
}
|
||||
deactivateAll()
|
||||
bossBar?.removeAll()
|
||||
bossBar = null
|
||||
state.set(false)
|
||||
selectorController.cancel()
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.event.Listener
|
||||
|
||||
interface ChaosModule : Listener {
|
||||
fun id(): String
|
||||
fun name(): String
|
||||
fun what(): String
|
||||
fun activate() {}
|
||||
fun deactivate() {}
|
||||
|
@ -5,6 +5,8 @@ import org.bukkit.plugin.Plugin
|
||||
object ChaosModules {
|
||||
fun all(plugin: Plugin) = listOf(
|
||||
NearestPlayerEntitySpawn(plugin),
|
||||
TeleportAllEntitiesNearestPlayer(plugin)
|
||||
TeleportAllEntitiesNearestPlayer(plugin),
|
||||
KillRandomPlayer(plugin),
|
||||
TntAllPlayers(plugin)
|
||||
)
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package gay.pizza.foundation.chaos.modules
|
||||
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
class KillRandomPlayer(val plugin: Plugin) : ChaosModule {
|
||||
override fun id(): String = "kill-random-player"
|
||||
override fun name(): String = "Random Kill"
|
||||
override fun what(): String = "Kill a random player."
|
||||
|
||||
override fun activate() {
|
||||
val player = plugin.server.onlinePlayers.randomOrNull() ?: return
|
||||
player.damage(1000000.0)
|
||||
}
|
||||
}
|
@ -7,7 +7,8 @@ import org.bukkit.plugin.Plugin
|
||||
|
||||
class NearestPlayerEntitySpawn(val plugin: Plugin) : ChaosModule {
|
||||
override fun id(): String = "nearest-player-entity-spawn"
|
||||
override fun what(): String = "Teleports all entities on spawn to the nearest player."
|
||||
override fun name(): String = "Monster Me"
|
||||
override fun what(): String = "Teleport all spawned entities to the nearest player"
|
||||
|
||||
@EventHandler
|
||||
fun onMobSpawn(e: EntitySpawnEvent) {
|
||||
|
@ -5,7 +5,8 @@ import org.bukkit.plugin.Plugin
|
||||
|
||||
class TeleportAllEntitiesNearestPlayer(val plugin: Plugin) : ChaosModule {
|
||||
override fun id(): String = "teleport-all-entities-nearest-player"
|
||||
override fun what(): String = "Teleports all entities to the nearest player."
|
||||
override fun name(): String = "Monster Me Once"
|
||||
override fun what(): String = "Teleport all entities to the nearest player"
|
||||
|
||||
override fun activate() {
|
||||
for (world in plugin.server.worlds) {
|
||||
|
@ -0,0 +1,16 @@
|
||||
package gay.pizza.foundation.chaos.modules
|
||||
|
||||
import org.bukkit.entity.TNTPrimed
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
class TntAllPlayers(val plugin: Plugin) : ChaosModule {
|
||||
override fun id(): String = "tnt-all-players"
|
||||
override fun name(): String = "TNT Us All"
|
||||
override fun what(): String = "TNT All Players"
|
||||
|
||||
override fun activate() {
|
||||
for (player in plugin.server.onlinePlayers) {
|
||||
player.world.spawn(player.location, TNTPrimed::class.java)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user