mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-03 05:30: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
|
@Serializable
|
||||||
data class ExportedChunk(
|
data class ExportedChunk(
|
||||||
|
val blocks: List<ExportedBlock>,
|
||||||
val x: Int,
|
val x: Int,
|
||||||
val z: Int,
|
val z: Int,
|
||||||
val sections: List<ExportedChunkSection>
|
val sections: List<ExportedChunkSection>
|
||||||
|
@ -6,5 +6,5 @@ import kotlinx.serialization.Serializable
|
|||||||
data class ExportedChunkSection(
|
data class ExportedChunkSection(
|
||||||
val x: Int,
|
val x: Int,
|
||||||
val z: 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 {
|
dependencies {
|
||||||
|
implementation(project(":common-plugin"))
|
||||||
compileOnly(project(":foundation-core"))
|
compileOnly(project(":foundation-core"))
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package gay.pizza.foundation.chaos
|
package gay.pizza.foundation.chaos
|
||||||
|
|
||||||
import gay.pizza.foundation.chaos.model.ChaosConfig
|
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.ChaosModule
|
||||||
import gay.pizza.foundation.chaos.modules.ChaosModules
|
import gay.pizza.foundation.chaos.modules.ChaosModules
|
||||||
import net.kyori.adventure.text.Component
|
|
||||||
import org.bukkit.boss.BarColor
|
import org.bukkit.boss.BarColor
|
||||||
import org.bukkit.boss.BarStyle
|
import org.bukkit.boss.BarStyle
|
||||||
import org.bukkit.boss.BossBar
|
import org.bukkit.boss.BossBar
|
||||||
@ -28,7 +28,7 @@ class ChaosController(val plugin: Plugin, val config: ChaosConfig) : Listener {
|
|||||||
if (state.get()) {
|
if (state.get()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
allowedModules = allModules.filter { config.enable[it.id()] ?: true }
|
allowedModules = filterEnabledModules()
|
||||||
state.set(true)
|
state.set(true)
|
||||||
selectorController.schedule()
|
selectorController.schedule()
|
||||||
bossBar = plugin.server.createBossBar("Chaos Mode", BarColor.RED, BarStyle.SOLID)
|
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() {
|
fun activateAll() {
|
||||||
for (module in allowedModules) {
|
for (module in allowedModules) {
|
||||||
if (activeModules.contains(module)) {
|
if (activeModules.contains(module)) {
|
||||||
|
@ -10,7 +10,7 @@ class ChaosSelectorController(val controller: ChaosController, val plugin: Plugi
|
|||||||
cancel()
|
cancel()
|
||||||
task = plugin.server.scheduler.runTaskTimer(controller.plugin, { ->
|
task = plugin.server.scheduler.runTaskTimer(controller.plugin, { ->
|
||||||
select()
|
select()
|
||||||
}, controller.config.selectionTimerTicks, controller.config.selectionTimerTicks)
|
}, 20, controller.config.selection.timerTicks)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun select() {
|
fun select() {
|
||||||
|
@ -5,6 +5,17 @@ import kotlinx.serialization.Serializable
|
|||||||
@Serializable
|
@Serializable
|
||||||
class ChaosConfig(
|
class ChaosConfig(
|
||||||
val allowed: Boolean = true,
|
val allowed: Boolean = true,
|
||||||
val enable: Map<String, Boolean> = mapOf(),
|
val defaultModuleConfiguration: ChaosModuleConfig,
|
||||||
val selectionTimerTicks: Long
|
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),
|
NearestPlayerEntitySpawn(plugin),
|
||||||
TeleportAllEntitiesNearestPlayer(plugin),
|
TeleportAllEntitiesNearestPlayer(plugin),
|
||||||
KillRandomPlayer(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
|
package gay.pizza.foundation.chaos.modules
|
||||||
|
|
||||||
|
import gay.pizza.foundation.common.spawn
|
||||||
import org.bukkit.entity.TNTPrimed
|
import org.bukkit.entity.TNTPrimed
|
||||||
import org.bukkit.plugin.Plugin
|
import org.bukkit.plugin.Plugin
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ class TntAllPlayers(val plugin: Plugin) : ChaosModule {
|
|||||||
|
|
||||||
override fun activate() {
|
override fun activate() {
|
||||||
for (player in plugin.server.onlinePlayers) {
|
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.
|
# Whether enabling the chaos mode is allowed.
|
||||||
allowed: false
|
allowed: false
|
||||||
# Chaos modules enablement.
|
# The default module configuration for modules with
|
||||||
enable:
|
# no explicit configuration.
|
||||||
nearest-player-entity-spawn: true
|
defaultModuleConfiguration:
|
||||||
teleport-all-entities-nearest-player: true
|
enabled: true
|
||||||
selectionTimerTicks: 100
|
# 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) {
|
private fun exportChunkSnapshot(snapshot: ChunkSnapshot) {
|
||||||
|
val blocks = mutableMapOf<String, Pair<Int, ExportedBlock>>()
|
||||||
|
val blockList = mutableListOf<ExportedBlock>()
|
||||||
val sections = mutableListOf<ExportedChunkSection>()
|
val sections = mutableListOf<ExportedChunkSection>()
|
||||||
val yRange = world.minHeight until world.maxHeight
|
val yRange = world.minHeight until world.maxHeight
|
||||||
val chunkRange = 0..15
|
val chunkRange = 0..15
|
||||||
for (x in chunkRange) {
|
for (x in chunkRange) {
|
||||||
for (z 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)
|
saveChunkSnapshot(snapshot, exported)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,13 +60,20 @@ class ChunkExporter(private val plugin: Plugin, val world: World) {
|
|||||||
gzipOutputStream.close()
|
gzipOutputStream.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun exportChunkSection(snapshot: ChunkSnapshot, yRange: IntRange, x: Int, z: Int): ExportedChunkSection {
|
private fun exportChunkSection(blocks: MutableMap<String, Pair<Int, ExportedBlock>>, blockList: MutableList<ExportedBlock>, snapshot: ChunkSnapshot, yRange: IntRange, x: Int, z: Int): ExportedChunkSection {
|
||||||
val blocks = mutableListOf<ExportedBlock>()
|
val contents = mutableListOf<Int>()
|
||||||
for (y in yRange) {
|
for (y in yRange) {
|
||||||
val blockData = snapshot.getBlockData(x, y, z)
|
val blockData = snapshot.getBlockData(x, y, z)
|
||||||
val block = ExportedBlock(blockData.material.key.toString())
|
val key = blockData.material.key.toString()
|
||||||
blocks.add(block)
|
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(
|
include(
|
||||||
|
":common-plugin",
|
||||||
":common-heimdall",
|
":common-heimdall",
|
||||||
":foundation-core",
|
":foundation-core",
|
||||||
":foundation-bifrost",
|
":foundation-bifrost",
|
||||||
|
@ -40,7 +40,8 @@ class ChunkExportLoader(
|
|||||||
for (section in chunk.sections) {
|
for (section in chunk.sections) {
|
||||||
val x = (chunk.x * 16) + section.x
|
val x = (chunk.x * 16) + section.x
|
||||||
val z = (chunk.z * 16) + section.z
|
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") {
|
if (block.type == "minecraft:air") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user