mirror of
				https://github.com/GayPizzaSpecifications/foundation.git
				synced 2025-11-04 11:39:39 +00:00 
			
		
		
		
	More stuff.
This commit is contained in:
		@ -3,6 +3,7 @@ package gay.pizza.foundation.heimdall.plugin
 | 
			
		||||
import com.charleskorn.kaml.Yaml
 | 
			
		||||
import com.zaxxer.hikari.HikariConfig
 | 
			
		||||
import com.zaxxer.hikari.HikariDataSource
 | 
			
		||||
import gay.pizza.foundation.common.BaseFoundationPlugin
 | 
			
		||||
import gay.pizza.foundation.common.FoundationCoreLoader
 | 
			
		||||
import gay.pizza.foundation.heimdall.plugin.buffer.BufferFlushThread
 | 
			
		||||
import gay.pizza.foundation.heimdall.plugin.buffer.EventBuffer
 | 
			
		||||
@ -14,14 +15,13 @@ import gay.pizza.foundation.heimdall.plugin.model.HeimdallConfig
 | 
			
		||||
import gay.pizza.foundation.shared.PluginMainClass
 | 
			
		||||
import gay.pizza.foundation.shared.copyDefaultConfig
 | 
			
		||||
import org.bukkit.event.Listener
 | 
			
		||||
import org.bukkit.plugin.java.JavaPlugin
 | 
			
		||||
import org.jetbrains.exposed.sql.Database
 | 
			
		||||
import org.postgresql.Driver
 | 
			
		||||
import java.time.Duration
 | 
			
		||||
import kotlin.io.path.inputStream
 | 
			
		||||
 | 
			
		||||
@PluginMainClass
 | 
			
		||||
class FoundationHeimdallPlugin : JavaPlugin(), Listener {
 | 
			
		||||
class FoundationHeimdallPlugin : BaseFoundationPlugin(), Listener {
 | 
			
		||||
  private lateinit var config: HeimdallConfig
 | 
			
		||||
  private lateinit var pool: HikariDataSource
 | 
			
		||||
  internal var db: Database? = null
 | 
			
		||||
@ -36,6 +36,10 @@ class FoundationHeimdallPlugin : JavaPlugin(), Listener {
 | 
			
		||||
      throw Exception("Failed to get export_all_chunks command")
 | 
			
		||||
    exportChunksCommand.setExecutor(ExportAllChunksCommand(this))
 | 
			
		||||
 | 
			
		||||
    registerCommandExecutor("export_all_chunks", ExportAllChunksCommand(this))
 | 
			
		||||
    registerCommandExecutor("export_world_load", ExportAllChunksCommand(this))
 | 
			
		||||
    registerCommandExecutor("import_world_load", ExportAllChunksCommand(this))
 | 
			
		||||
 | 
			
		||||
    val importWorldLoadCommand = getCommand("import_world_load") ?:
 | 
			
		||||
      throw Exception("Failed to get import_world_load command")
 | 
			
		||||
    importWorldLoadCommand.setExecutor(ImportWorldLoadCommand(this))
 | 
			
		||||
 | 
			
		||||
@ -13,10 +13,6 @@ import java.io.File
 | 
			
		||||
import java.util.zip.GZIPOutputStream
 | 
			
		||||
 | 
			
		||||
class ChunkExporter(private val plugin: Plugin) {
 | 
			
		||||
  private val json = Json {
 | 
			
		||||
    ignoreUnknownKeys = true
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  fun exportLoadedChunksAsync(world: World) {
 | 
			
		||||
    exportChunkListAsync(world, world.loadedChunks.toList())
 | 
			
		||||
  }
 | 
			
		||||
@ -56,7 +52,7 @@ class ChunkExporter(private val plugin: Plugin) {
 | 
			
		||||
 | 
			
		||||
    val fileOutputStream = file.outputStream()
 | 
			
		||||
    val gzipOutputStream = GZIPOutputStream(fileOutputStream)
 | 
			
		||||
    json.encodeToStream(ExportedChunk.serializer(), chunk, gzipOutputStream)
 | 
			
		||||
    Json.encodeToStream(ExportedChunk.serializer(), chunk, gzipOutputStream)
 | 
			
		||||
    gzipOutputStream.close()
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,26 @@
 | 
			
		||||
package gay.pizza.foundation.heimdall.plugin.export
 | 
			
		||||
 | 
			
		||||
import org.bukkit.command.Command
 | 
			
		||||
import org.bukkit.command.CommandExecutor
 | 
			
		||||
import org.bukkit.command.CommandSender
 | 
			
		||||
import org.bukkit.plugin.Plugin
 | 
			
		||||
 | 
			
		||||
class ExportWorldLoadCommand(private val plugin: Plugin) : CommandExecutor {
 | 
			
		||||
  override fun onCommand(
 | 
			
		||||
    sender: CommandSender,
 | 
			
		||||
    command: Command,
 | 
			
		||||
    label: String,
 | 
			
		||||
    args: Array<out String>
 | 
			
		||||
  ): Boolean {
 | 
			
		||||
    sender.sendMessage("Exporting all worlds...")
 | 
			
		||||
    plugin.slF4JLogger.info("Exporting all worlds")
 | 
			
		||||
    val export = WorldLoadExporter()
 | 
			
		||||
    for (world in sender.server.worlds) {
 | 
			
		||||
      export.exportLoadedChunks(world)
 | 
			
		||||
    }
 | 
			
		||||
    export.save()
 | 
			
		||||
    sender.sendMessage("Exported all worlds...")
 | 
			
		||||
    plugin.slF4JLogger.info("Exported all worlds")
 | 
			
		||||
    return true
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,48 @@
 | 
			
		||||
package gay.pizza.foundation.heimdall.plugin.export
 | 
			
		||||
 | 
			
		||||
import gay.pizza.foundation.heimdall.export.ExportedBlock
 | 
			
		||||
import gay.pizza.foundation.heimdall.load.ExportedBlockTable
 | 
			
		||||
import gay.pizza.foundation.heimdall.load.WorldLoadFormat
 | 
			
		||||
import gay.pizza.foundation.heimdall.load.WorldLoadSimpleWorld
 | 
			
		||||
import gay.pizza.foundation.heimdall.load.WorldLoadWorld
 | 
			
		||||
import kotlinx.serialization.json.Json
 | 
			
		||||
import kotlinx.serialization.json.encodeToStream
 | 
			
		||||
import org.bukkit.World
 | 
			
		||||
import java.nio.file.Paths
 | 
			
		||||
import kotlin.io.path.outputStream
 | 
			
		||||
 | 
			
		||||
class WorldLoadExporter {
 | 
			
		||||
  private val blockTable = ExportedBlockTable()
 | 
			
		||||
  private val worlds = mutableMapOf<String, WorldLoadWorld>()
 | 
			
		||||
 | 
			
		||||
  fun exportLoadedChunks(world: World) {
 | 
			
		||||
    val data = mutableMapOf<Long, MutableMap<Long, MutableMap<Long, Int>>>()
 | 
			
		||||
    for (chunk in world.loadedChunks) {
 | 
			
		||||
      val snapshot = chunk.chunkSnapshot
 | 
			
		||||
      val yRange = world.minHeight until world.maxHeight
 | 
			
		||||
      val chunkRange = 0..15
 | 
			
		||||
      for (x in chunkRange) {
 | 
			
		||||
        for (z in chunkRange) {
 | 
			
		||||
          for (y in yRange) {
 | 
			
		||||
            val blockInfo = snapshot.getBlockData(x, y, z)
 | 
			
		||||
            val block = ExportedBlock(blockInfo.material.key.toString(), blockInfo.asString)
 | 
			
		||||
            data.getOrPut(x.toLong()) {
 | 
			
		||||
              mutableMapOf()
 | 
			
		||||
            }.getOrPut(z.toLong()) {
 | 
			
		||||
              mutableMapOf()
 | 
			
		||||
            }[y.toLong()] = blockTable.index(block)
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    worlds[world.name] = WorldLoadSimpleWorld(world.name, data).compact()
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  fun save() {
 | 
			
		||||
    val format = WorldLoadFormat(blockTable.blocks, worlds)
 | 
			
		||||
    val path = Paths.get("world.load.json")
 | 
			
		||||
    path.outputStream().use { stream ->
 | 
			
		||||
      Json.encodeToStream(WorldLoadFormat.serializer(), format, stream)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -27,20 +27,18 @@ class WorldReassembler(val plugin: Plugin, val server: Server, val format: World
 | 
			
		||||
 | 
			
		||||
        val blocksToMake = mutableListOf<Pair<Location, ExportedBlock>>()
 | 
			
		||||
 | 
			
		||||
        for ((x, zBlocks) in load.blocks) {
 | 
			
		||||
          for ((z, yBlocks) in zBlocks) {
 | 
			
		||||
            for ((y, block) in yBlocks) {
 | 
			
		||||
              val material: Material? = Material.matchMaterial(block.type)
 | 
			
		||||
        load.crawl { x, z, y, blockIndex ->
 | 
			
		||||
          val block = format.blockLookupTable[blockIndex]
 | 
			
		||||
          val material: Material? = Material.matchMaterial(block.type)
 | 
			
		||||
 | 
			
		||||
              if (material == null) {
 | 
			
		||||
                feedback("Unknown Material '${block.type}' at $x $y $z")
 | 
			
		||||
                continue
 | 
			
		||||
              }
 | 
			
		||||
 | 
			
		||||
              blocksToMake.add(Location(world, x.toDouble(), y.toDouble(), z.toDouble()) to block)
 | 
			
		||||
            }
 | 
			
		||||
          if (material == null) {
 | 
			
		||||
            feedback("Unknown Material '${block.type}' at $x $y $z")
 | 
			
		||||
            return@crawl
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          blocksToMake.add(Location(world, x.toDouble(), y.toDouble(), z.toDouble()) to block)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        blocksToMake.sortBy { it.first.x }
 | 
			
		||||
 | 
			
		||||
        feedback("Will place ${blocksToMake.size} blocks in ${world.name}")
 | 
			
		||||
 | 
			
		||||
@ -13,6 +13,10 @@ commands:
 | 
			
		||||
    description: Export All Chunks
 | 
			
		||||
    usage: /export_all_chunks
 | 
			
		||||
    permission: heimdall.command.export_all_chunks
 | 
			
		||||
  export_world_load:
 | 
			
		||||
    description: Export World Load
 | 
			
		||||
    usage: /export_world_load
 | 
			
		||||
    permission: heimdall.command.export_world_load
 | 
			
		||||
  import_world_load:
 | 
			
		||||
    description: Import World Load
 | 
			
		||||
    usage: /import_world_load
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user