mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-02 21:20:55 +00:00
chaos: mega-tnt and chunk exporter fixes
This commit is contained in:
parent
452ec0d7da
commit
cbe647cce9
@ -4,6 +4,7 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ExportedChunk(
|
||||
val blocks: List<ExportedBlock>,
|
||||
val x: Int,
|
||||
val z: Int,
|
||||
val sections: List<ExportedChunkSection>
|
||||
|
@ -6,5 +6,5 @@ import kotlinx.serialization.Serializable
|
||||
data class ExportedChunkSection(
|
||||
val x: Int,
|
||||
val z: Int,
|
||||
val blocks: List<ExportedBlock>
|
||||
val blocks: List<Int>
|
||||
)
|
||||
|
3
common-plugin/build.gradle.kts
Normal file
3
common-plugin/build.gradle.kts
Normal file
@ -0,0 +1,3 @@
|
||||
plugins {
|
||||
id("gay.pizza.foundation.concrete-library")
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package gay.pizza.foundation.common
|
||||
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.World
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Player
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
fun <T: Entity> World.spawn(location: Location, clazz: KClass<T>): T = spawn(location, clazz.java)
|
||||
|
||||
fun <T: Entity> Player.spawn(clazz: KClass<T>): T = spawn(clazz.java)
|
||||
fun <T: Entity> Player.spawn(clazz: Class<T>): T = world.spawn(location, clazz)
|
@ -3,5 +3,6 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":common-plugin"))
|
||||
compileOnly(project(":foundation-core"))
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package gay.pizza.foundation.chaos
|
||||
|
||||
import gay.pizza.foundation.chaos.model.ChaosConfig
|
||||
import gay.pizza.foundation.chaos.model.ChaosModuleConfig
|
||||
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
|
||||
@ -28,7 +28,7 @@ class ChaosController(val plugin: Plugin, val config: ChaosConfig) : Listener {
|
||||
if (state.get()) {
|
||||
return
|
||||
}
|
||||
allowedModules = allModules.filter { config.enable[it.id()] ?: true }
|
||||
allowedModules = filterEnabledModules()
|
||||
state.set(true)
|
||||
selectorController.schedule()
|
||||
bossBar = plugin.server.createBossBar("Chaos Mode", BarColor.RED, BarStyle.SOLID)
|
||||
@ -37,6 +37,11 @@ class ChaosController(val plugin: Plugin, val config: ChaosConfig) : Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private fun filterEnabledModules(): List<ChaosModule> = allModules.filter { module ->
|
||||
val moduleConfig = config.modules[module.id()] ?: config.defaultModuleConfiguration
|
||||
moduleConfig.enabled
|
||||
}
|
||||
|
||||
fun activateAll() {
|
||||
for (module in allowedModules) {
|
||||
if (activeModules.contains(module)) {
|
||||
|
@ -10,7 +10,7 @@ class ChaosSelectorController(val controller: ChaosController, val plugin: Plugi
|
||||
cancel()
|
||||
task = plugin.server.scheduler.runTaskTimer(controller.plugin, { ->
|
||||
select()
|
||||
}, controller.config.selectionTimerTicks, controller.config.selectionTimerTicks)
|
||||
}, 20, controller.config.selection.timerTicks)
|
||||
}
|
||||
|
||||
fun select() {
|
||||
|
@ -5,6 +5,17 @@ import kotlinx.serialization.Serializable
|
||||
@Serializable
|
||||
class ChaosConfig(
|
||||
val allowed: Boolean = true,
|
||||
val enable: Map<String, Boolean> = mapOf(),
|
||||
val selectionTimerTicks: Long
|
||||
val defaultModuleConfiguration: ChaosModuleConfig,
|
||||
val modules: Map<String, ChaosModuleConfig> = emptyMap(),
|
||||
val selection: ChaosSelectionConfig
|
||||
)
|
||||
|
||||
@Serializable
|
||||
class ChaosModuleConfig(
|
||||
val enabled: Boolean
|
||||
)
|
||||
|
||||
@Serializable
|
||||
class ChaosSelectionConfig(
|
||||
val timerTicks: Long
|
||||
)
|
||||
|
@ -7,6 +7,7 @@ object ChaosModules {
|
||||
NearestPlayerEntitySpawn(plugin),
|
||||
TeleportAllEntitiesNearestPlayer(plugin),
|
||||
KillRandomPlayer(plugin),
|
||||
TntAllPlayers(plugin)
|
||||
TntAllPlayers(plugin),
|
||||
MegaTnt(plugin)
|
||||
)
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package gay.pizza.foundation.chaos.modules
|
||||
|
||||
import gay.pizza.foundation.common.spawn
|
||||
import org.bukkit.entity.TNTPrimed
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
class MegaTnt(val plugin: Plugin) : ChaosModule {
|
||||
override fun id(): String = "mega-tnt"
|
||||
override fun name(): String = "Mega TNT"
|
||||
override fun what(): String = "Spawn a massive TNT explosion"
|
||||
|
||||
override fun activate() {
|
||||
for (player in plugin.server.onlinePlayers) {
|
||||
val tnt = player.spawn(TNTPrimed::class)
|
||||
tnt.fuseTicks = 1
|
||||
tnt.yield = 10.0f
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package gay.pizza.foundation.chaos.modules
|
||||
|
||||
import gay.pizza.foundation.common.spawn
|
||||
import org.bukkit.entity.TNTPrimed
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
@ -10,7 +11,7 @@ class TntAllPlayers(val plugin: Plugin) : ChaosModule {
|
||||
|
||||
override fun activate() {
|
||||
for (player in plugin.server.onlinePlayers) {
|
||||
player.world.spawn(player.location, TNTPrimed::class.java)
|
||||
player.spawn(TNTPrimed::class)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,16 @@
|
||||
# Whether enabling the chaos mode is allowed.
|
||||
allowed: false
|
||||
# Chaos modules enablement.
|
||||
enable:
|
||||
nearest-player-entity-spawn: true
|
||||
teleport-all-entities-nearest-player: true
|
||||
selectionTimerTicks: 100
|
||||
# The default module configuration for modules with
|
||||
# no explicit configuration.
|
||||
defaultModuleConfiguration:
|
||||
enabled: true
|
||||
# Module configuration.
|
||||
modules:
|
||||
nearest-player-entity-spawn:
|
||||
enabled: true
|
||||
teleport-all-entities-nearest-player:
|
||||
enabled: true
|
||||
# Chaos selection configuration.
|
||||
selection:
|
||||
# The number of ticks before a new selection is made.
|
||||
timerTicks: 6000
|
||||
|
@ -33,16 +33,18 @@ class ChunkExporter(private val plugin: Plugin, val world: World) {
|
||||
}
|
||||
|
||||
private fun exportChunkSnapshot(snapshot: ChunkSnapshot) {
|
||||
val blocks = mutableMapOf<String, Pair<Int, ExportedBlock>>()
|
||||
val blockList = mutableListOf<ExportedBlock>()
|
||||
val sections = mutableListOf<ExportedChunkSection>()
|
||||
val yRange = world.minHeight until world.maxHeight
|
||||
val chunkRange = 0..15
|
||||
for (x in chunkRange) {
|
||||
for (z in chunkRange) {
|
||||
sections.add(exportChunkSection(snapshot, yRange, x, z))
|
||||
sections.add(exportChunkSection(blocks, blockList, snapshot, yRange, x, z))
|
||||
}
|
||||
}
|
||||
|
||||
val exported = ExportedChunk(snapshot.x, snapshot.z, sections)
|
||||
val exported = ExportedChunk(blocks = blockList, snapshot.x, snapshot.z, sections)
|
||||
saveChunkSnapshot(snapshot, exported)
|
||||
}
|
||||
|
||||
@ -58,13 +60,20 @@ class ChunkExporter(private val plugin: Plugin, val world: World) {
|
||||
gzipOutputStream.close()
|
||||
}
|
||||
|
||||
private fun exportChunkSection(snapshot: ChunkSnapshot, yRange: IntRange, x: Int, z: Int): ExportedChunkSection {
|
||||
val blocks = mutableListOf<ExportedBlock>()
|
||||
private fun exportChunkSection(blocks: MutableMap<String, Pair<Int, ExportedBlock>>, blockList: MutableList<ExportedBlock>, snapshot: ChunkSnapshot, yRange: IntRange, x: Int, z: Int): ExportedChunkSection {
|
||||
val contents = mutableListOf<Int>()
|
||||
for (y in yRange) {
|
||||
val blockData = snapshot.getBlockData(x, y, z)
|
||||
val block = ExportedBlock(blockData.material.key.toString())
|
||||
blocks.add(block)
|
||||
val key = blockData.material.key.toString()
|
||||
var idxToBlk = blocks[key]
|
||||
if (idxToBlk == null) {
|
||||
val idx = blockList.size
|
||||
idxToBlk = idx to ExportedBlock(key)
|
||||
blockList.add(idxToBlk.second)
|
||||
blocks[key] = idxToBlk
|
||||
}
|
||||
contents.add(idxToBlk.first)
|
||||
}
|
||||
return ExportedChunkSection(x, z, blocks)
|
||||
return ExportedChunkSection(x, z, contents)
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
include(
|
||||
":common-plugin",
|
||||
":common-heimdall",
|
||||
":foundation-core",
|
||||
":foundation-bifrost",
|
||||
|
@ -40,7 +40,8 @@ class ChunkExportLoader(
|
||||
for (section in chunk.sections) {
|
||||
val x = (chunk.x * 16) + section.x
|
||||
val z = (chunk.z * 16) + section.z
|
||||
for ((y, block) in section.blocks.withIndex()) {
|
||||
for ((y, bidx) in section.blocks.withIndex()) {
|
||||
val block = chunk.blocks[bidx]
|
||||
if (block.type == "minecraft:air") {
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user