mirror of
				https://github.com/GayPizzaSpecifications/foundation.git
				synced 2025-11-04 11:39:39 +00:00 
			
		
		
		
	Heimdall: Fix bug where DB being disabled might cause errors.
This commit is contained in:
		@ -29,7 +29,7 @@ import kotlin.io.path.inputStream
 | 
				
			|||||||
class FoundationHeimdallPlugin : JavaPlugin(), Listener {
 | 
					class FoundationHeimdallPlugin : JavaPlugin(), Listener {
 | 
				
			||||||
  private lateinit var config: HeimdallConfig
 | 
					  private lateinit var config: HeimdallConfig
 | 
				
			||||||
  private lateinit var pool: HikariDataSource
 | 
					  private lateinit var pool: HikariDataSource
 | 
				
			||||||
  internal lateinit var db: Database
 | 
					  internal var db: Database? = null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private val buffer = EventBuffer()
 | 
					  private val buffer = EventBuffer()
 | 
				
			||||||
  private val bufferFlushThread = BufferFlushThread(this, buffer)
 | 
					  private val bufferFlushThread = BufferFlushThread(this, buffer)
 | 
				
			||||||
 | 
				
			|||||||
@ -31,6 +31,11 @@ class BufferFlushThread(val plugin: FoundationHeimdallPlugin, val buffer: EventB
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  fun flush() {
 | 
					  fun flush() {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
 | 
					      val db = plugin.db
 | 
				
			||||||
 | 
					      if (db == null) {
 | 
				
			||||||
 | 
					        buffer.clear()
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      transaction(plugin.db) {
 | 
					      transaction(plugin.db) {
 | 
				
			||||||
        val count = buffer.flush(this)
 | 
					        val count = buffer.flush(this)
 | 
				
			||||||
        if (count > 0) {
 | 
					        if (count > 0) {
 | 
				
			||||||
 | 
				
			|||||||
@ -21,4 +21,8 @@ class EventBuffer {
 | 
				
			|||||||
  fun push(event: HeimdallEvent) {
 | 
					  fun push(event: HeimdallEvent) {
 | 
				
			||||||
    events.add(event)
 | 
					    events.add(event)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun clear() {
 | 
				
			||||||
 | 
					    events = mutableListOf()
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -2,8 +2,9 @@ package cloud.kubelet.foundation.gjallarhorn.export
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import cloud.kubelet.foundation.gjallarhorn.state.BlockExpanse
 | 
					import cloud.kubelet.foundation.gjallarhorn.state.BlockExpanse
 | 
				
			||||||
import cloud.kubelet.foundation.gjallarhorn.state.SparseBlockStateMap
 | 
					import cloud.kubelet.foundation.gjallarhorn.state.SparseBlockStateMap
 | 
				
			||||||
 | 
					import kotlinx.serialization.Serializable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@kotlinx.serialization.Serializable
 | 
					@Serializable
 | 
				
			||||||
class CombinedChunkFormat(
 | 
					class CombinedChunkFormat(
 | 
				
			||||||
  val expanse: BlockExpanse,
 | 
					  val expanse: BlockExpanse,
 | 
				
			||||||
  val map: SparseBlockStateMap
 | 
					  val map: SparseBlockStateMap
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user