mirror of
				https://github.com/GayPizzaSpecifications/foundation.git
				synced 2025-11-04 03:39:37 +00:00 
			
		
		
		
	chaos: boss bar
This commit is contained in:
		@ -4,8 +4,13 @@ import gay.pizza.foundation.chaos.model.ChaosConfig
 | 
				
			|||||||
import gay.pizza.foundation.chaos.modules.ChaosModule
 | 
					import gay.pizza.foundation.chaos.modules.ChaosModule
 | 
				
			||||||
import gay.pizza.foundation.chaos.modules.ChaosModules
 | 
					import gay.pizza.foundation.chaos.modules.ChaosModules
 | 
				
			||||||
import net.kyori.adventure.text.Component
 | 
					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.HandlerList
 | 
				
			||||||
import org.bukkit.event.Listener
 | 
					import org.bukkit.event.Listener
 | 
				
			||||||
 | 
					import org.bukkit.event.player.PlayerJoinEvent
 | 
				
			||||||
import org.bukkit.plugin.Plugin
 | 
					import org.bukkit.plugin.Plugin
 | 
				
			||||||
import java.util.concurrent.atomic.AtomicBoolean
 | 
					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 allowedModules: List<ChaosModule> = emptyList()
 | 
				
			||||||
  private var activeModules = mutableSetOf<ChaosModule>()
 | 
					  private var activeModules = mutableSetOf<ChaosModule>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  var bossBar: BossBar? = null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun load() {
 | 
					  fun load() {
 | 
				
			||||||
    if (state.get()) {
 | 
					    if (state.get()) {
 | 
				
			||||||
      return
 | 
					      return
 | 
				
			||||||
@ -24,6 +31,10 @@ class ChaosController(val plugin: Plugin, val config: ChaosConfig) : Listener {
 | 
				
			|||||||
    allowedModules = allModules.filter { config.enable[it.id()] ?: true }
 | 
					    allowedModules = allModules.filter { config.enable[it.id()] ?: true }
 | 
				
			||||||
    state.set(true)
 | 
					    state.set(true)
 | 
				
			||||||
    selectorController.schedule()
 | 
					    selectorController.schedule()
 | 
				
			||||||
 | 
					    bossBar = plugin.server.createBossBar("Chaos Mode", BarColor.RED, BarStyle.SOLID)
 | 
				
			||||||
 | 
					    for (player in plugin.server.onlinePlayers) {
 | 
				
			||||||
 | 
					      bossBar?.addPlayer(player)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun activateAll() {
 | 
					  fun activateAll() {
 | 
				
			||||||
@ -39,14 +50,19 @@ class ChaosController(val plugin: Plugin, val config: ChaosConfig) : Listener {
 | 
				
			|||||||
    plugin.server.pluginManager.registerEvents(module, plugin)
 | 
					    plugin.server.pluginManager.registerEvents(module, plugin)
 | 
				
			||||||
    module.activate()
 | 
					    module.activate()
 | 
				
			||||||
    activeModules.add(module)
 | 
					    activeModules.add(module)
 | 
				
			||||||
    plugin.server.broadcast(Component.text("Chaos Module Activated: ${module.id()}"))
 | 
					    updateBossBar()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun deactivate(module: ChaosModule) {
 | 
					  fun deactivate(module: ChaosModule) {
 | 
				
			||||||
    HandlerList.unregisterAll(module)
 | 
					    HandlerList.unregisterAll(module)
 | 
				
			||||||
    module.deactivate()
 | 
					    module.deactivate()
 | 
				
			||||||
    activeModules.remove(module)
 | 
					    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() {
 | 
					  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() {
 | 
					  fun unload() {
 | 
				
			||||||
    if (!state.get()) {
 | 
					    if (!state.get()) {
 | 
				
			||||||
      return
 | 
					      return
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    deactivateAll()
 | 
					    deactivateAll()
 | 
				
			||||||
 | 
					    bossBar?.removeAll()
 | 
				
			||||||
 | 
					    bossBar = null
 | 
				
			||||||
    state.set(false)
 | 
					    state.set(false)
 | 
				
			||||||
    selectorController.cancel()
 | 
					    selectorController.cancel()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@ import org.bukkit.event.Listener
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
interface ChaosModule : Listener {
 | 
					interface ChaosModule : Listener {
 | 
				
			||||||
  fun id(): String
 | 
					  fun id(): String
 | 
				
			||||||
 | 
					  fun name(): String
 | 
				
			||||||
  fun what(): String
 | 
					  fun what(): String
 | 
				
			||||||
  fun activate() {}
 | 
					  fun activate() {}
 | 
				
			||||||
  fun deactivate() {}
 | 
					  fun deactivate() {}
 | 
				
			||||||
 | 
				
			|||||||
@ -5,6 +5,8 @@ import org.bukkit.plugin.Plugin
 | 
				
			|||||||
object ChaosModules {
 | 
					object ChaosModules {
 | 
				
			||||||
  fun all(plugin: Plugin) = listOf(
 | 
					  fun all(plugin: Plugin) = listOf(
 | 
				
			||||||
    NearestPlayerEntitySpawn(plugin),
 | 
					    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 {
 | 
					class NearestPlayerEntitySpawn(val plugin: Plugin) : ChaosModule {
 | 
				
			||||||
  override fun id(): String = "nearest-player-entity-spawn"
 | 
					  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
 | 
					  @EventHandler
 | 
				
			||||||
  fun onMobSpawn(e: EntitySpawnEvent) {
 | 
					  fun onMobSpawn(e: EntitySpawnEvent) {
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,8 @@ import org.bukkit.plugin.Plugin
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class TeleportAllEntitiesNearestPlayer(val plugin: Plugin) : ChaosModule {
 | 
					class TeleportAllEntitiesNearestPlayer(val plugin: Plugin) : ChaosModule {
 | 
				
			||||||
  override fun id(): String = "teleport-all-entities-nearest-player"
 | 
					  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() {
 | 
					  override fun activate() {
 | 
				
			||||||
    for (world in plugin.server.worlds) {
 | 
					    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)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user