mirror of
				https://github.com/GayPizzaSpecifications/foundation.git
				synced 2025-11-04 11:39:39 +00:00 
			
		
		
		
	Move persistence to plugin shared.
This commit is contained in:
		@ -12,7 +12,4 @@ dependencies {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  implementation("io.insert-koin:koin-core:3.3.2")
 | 
					  implementation("io.insert-koin:koin-core:3.3.2")
 | 
				
			||||||
  testImplementation("io.insert-koin:koin-test:3.3.2")
 | 
					  testImplementation("io.insert-koin:koin-test:3.3.2")
 | 
				
			||||||
 | 
					 | 
				
			||||||
  implementation("org.jetbrains.xodus:xodus-openAPI:2.0.1")
 | 
					 | 
				
			||||||
  implementation("org.jetbrains.xodus:xodus-entity-store:2.0.1")
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -12,6 +12,8 @@ import gay.pizza.foundation.core.features.scheduler.SchedulerFeature
 | 
				
			|||||||
import gay.pizza.foundation.core.features.stats.StatsFeature
 | 
					import gay.pizza.foundation.core.features.stats.StatsFeature
 | 
				
			||||||
import gay.pizza.foundation.core.features.update.UpdateFeature
 | 
					import gay.pizza.foundation.core.features.update.UpdateFeature
 | 
				
			||||||
import gay.pizza.foundation.core.features.world.WorldFeature
 | 
					import gay.pizza.foundation.core.features.world.WorldFeature
 | 
				
			||||||
 | 
					import gay.pizza.foundation.shared.PersistentStore
 | 
				
			||||||
 | 
					import gay.pizza.foundation.shared.PluginPersistence
 | 
				
			||||||
import org.koin.dsl.module
 | 
					import org.koin.dsl.module
 | 
				
			||||||
import java.nio.file.Path
 | 
					import java.nio.file.Path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -34,6 +36,8 @@ class FoundationCorePlugin : IFoundationCore, FoundationPlugin() {
 | 
				
			|||||||
      _pluginDataPath = value
 | 
					      _pluginDataPath = value
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override val persistence: PluginPersistence = PluginPersistence(this)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun onEnable() {
 | 
					  override fun onEnable() {
 | 
				
			||||||
    // Create core plugin directory.
 | 
					    // Create core plugin directory.
 | 
				
			||||||
    pluginDataPath = dataFolder.toPath()
 | 
					    pluginDataPath = dataFolder.toPath()
 | 
				
			||||||
 | 
				
			|||||||
@ -1,18 +1,21 @@
 | 
				
			|||||||
package gay.pizza.foundation.core.features.persist
 | 
					package gay.pizza.foundation.core.features.persist
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import gay.pizza.foundation.core.FoundationCorePlugin
 | 
				
			||||||
import gay.pizza.foundation.core.abstraction.Feature
 | 
					import gay.pizza.foundation.core.abstraction.Feature
 | 
				
			||||||
 | 
					import gay.pizza.foundation.shared.PluginPersistence
 | 
				
			||||||
import org.koin.core.component.inject
 | 
					import org.koin.core.component.inject
 | 
				
			||||||
import org.koin.core.module.Module
 | 
					import org.koin.core.module.Module
 | 
				
			||||||
import org.koin.dsl.module
 | 
					import org.koin.dsl.module
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PersistenceFeature : Feature() {
 | 
					class PersistenceFeature : Feature() {
 | 
				
			||||||
  private val persistence = inject<PluginPersistence>()
 | 
					  private val persistence = inject<PluginPersistence>()
 | 
				
			||||||
 | 
					  private val core = inject<FoundationCorePlugin>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun disable() {
 | 
					  override fun disable() {
 | 
				
			||||||
    persistence.value.unload()
 | 
					    persistence.value.unload()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun module(): Module = module {
 | 
					  override fun module(): Module = module {
 | 
				
			||||||
    single { PluginPersistence() }
 | 
					    single { core.value.persistence }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,10 +1,10 @@
 | 
				
			|||||||
package gay.pizza.foundation.core.features.stats
 | 
					package gay.pizza.foundation.core.features.stats
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import gay.pizza.foundation.core.abstraction.Feature
 | 
					import gay.pizza.foundation.core.abstraction.Feature
 | 
				
			||||||
import gay.pizza.foundation.core.features.persist.PersistentStore
 | 
					 | 
				
			||||||
import gay.pizza.foundation.core.features.persist.PersistentStoreCommand
 | 
					import gay.pizza.foundation.core.features.persist.PersistentStoreCommand
 | 
				
			||||||
import gay.pizza.foundation.core.features.persist.PluginPersistence
 | 
					 | 
				
			||||||
import gay.pizza.foundation.core.features.persist.setAllProperties
 | 
					import gay.pizza.foundation.core.features.persist.setAllProperties
 | 
				
			||||||
 | 
					import gay.pizza.foundation.shared.PersistentStore
 | 
				
			||||||
 | 
					import gay.pizza.foundation.shared.PluginPersistence
 | 
				
			||||||
import io.papermc.paper.event.player.AsyncChatEvent
 | 
					import io.papermc.paper.event.player.AsyncChatEvent
 | 
				
			||||||
import net.kyori.adventure.text.TextComponent
 | 
					import net.kyori.adventure.text.TextComponent
 | 
				
			||||||
import org.bukkit.event.EventHandler
 | 
					import org.bukkit.event.EventHandler
 | 
				
			||||||
 | 
				
			|||||||
@ -4,4 +4,7 @@ plugins {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
dependencies {
 | 
					dependencies {
 | 
				
			||||||
  api(project(":common-all"))
 | 
					  api(project(":common-all"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  api("org.jetbrains.xodus:xodus-openAPI:2.0.1")
 | 
				
			||||||
 | 
					  api("org.jetbrains.xodus:xodus-entity-store:2.0.1")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -3,5 +3,6 @@ package gay.pizza.foundation.shared
 | 
				
			|||||||
import java.nio.file.Path
 | 
					import java.nio.file.Path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface IFoundationCore {
 | 
					interface IFoundationCore {
 | 
				
			||||||
 | 
					  val persistence: PluginPersistence
 | 
				
			||||||
  val pluginDataPath: Path
 | 
					  val pluginDataPath: Path
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,13 +1,12 @@
 | 
				
			|||||||
package gay.pizza.foundation.core.features.persist
 | 
					package gay.pizza.foundation.shared
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import gay.pizza.foundation.core.FoundationCorePlugin
 | 
					 | 
				
			||||||
import jetbrains.exodus.entitystore.Entity
 | 
					import jetbrains.exodus.entitystore.Entity
 | 
				
			||||||
import jetbrains.exodus.entitystore.EntityIterable
 | 
					import jetbrains.exodus.entitystore.EntityIterable
 | 
				
			||||||
import jetbrains.exodus.entitystore.PersistentEntityStores
 | 
					import jetbrains.exodus.entitystore.PersistentEntityStores
 | 
				
			||||||
import jetbrains.exodus.entitystore.StoreTransaction
 | 
					import jetbrains.exodus.entitystore.StoreTransaction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PersistentStore(corePlugin: FoundationCorePlugin, fileStoreName: String) : AutoCloseable {
 | 
					class PersistentStore(core: IFoundationCore, fileStoreName: String) : AutoCloseable {
 | 
				
			||||||
  private val fileStorePath = corePlugin.pluginDataPath.resolve("persistence/${fileStoreName}")
 | 
					  private val fileStorePath = core.pluginDataPath.resolve("persistence/${fileStoreName}")
 | 
				
			||||||
  private val entityStore = PersistentEntityStores.newInstance(fileStorePath.toFile())
 | 
					  private val entityStore = PersistentEntityStores.newInstance(fileStorePath.toFile())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun <R> transact(block: StoreTransaction.() -> R): R {
 | 
					  fun <R> transact(block: StoreTransaction.() -> R): R {
 | 
				
			||||||
@ -1,20 +1,15 @@
 | 
				
			|||||||
package gay.pizza.foundation.core.features.persist
 | 
					package gay.pizza.foundation.shared
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import gay.pizza.foundation.core.FoundationCorePlugin
 | 
					 | 
				
			||||||
import org.koin.core.component.KoinComponent
 | 
					 | 
				
			||||||
import org.koin.core.component.inject
 | 
					 | 
				
			||||||
import java.util.concurrent.ConcurrentHashMap
 | 
					import java.util.concurrent.ConcurrentHashMap
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PluginPersistence : KoinComponent {
 | 
					class PluginPersistence(val core: IFoundationCore) {
 | 
				
			||||||
  private val plugin = inject<FoundationCorePlugin>()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  val stores = ConcurrentHashMap<String, PersistentStore>()
 | 
					  val stores = ConcurrentHashMap<String, PersistentStore>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Fetch a persistent store by name. Make sure the name is path-safe, descriptive and consistent across server runs.
 | 
					   * Fetch a persistent store by name. Make sure the name is path-safe, descriptive and consistent across server runs.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  fun store(name: String): PersistentStore =
 | 
					  fun store(name: String): PersistentStore =
 | 
				
			||||||
    stores.getOrPut(name) { PersistentStore(plugin.value, name) }
 | 
					    stores.getOrPut(name) { PersistentStore(core, name) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun unload() {
 | 
					  fun unload() {
 | 
				
			||||||
    stores.values.forEach { store -> store.close() }
 | 
					    stores.values.forEach { store -> store.close() }
 | 
				
			||||||
		Reference in New Issue
	
	Block a user