mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-02 13:10:55 +00:00
Move persistence to plugin shared.
This commit is contained in:
parent
5f9f6e5fa7
commit
3f67e737c4
@ -12,7 +12,4 @@ dependencies {
|
||||
|
||||
implementation("io.insert-koin:koin-core: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.update.UpdateFeature
|
||||
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 java.nio.file.Path
|
||||
|
||||
@ -34,6 +36,8 @@ class FoundationCorePlugin : IFoundationCore, FoundationPlugin() {
|
||||
_pluginDataPath = value
|
||||
}
|
||||
|
||||
override val persistence: PluginPersistence = PluginPersistence(this)
|
||||
|
||||
override fun onEnable() {
|
||||
// Create core plugin directory.
|
||||
pluginDataPath = dataFolder.toPath()
|
||||
|
@ -1,18 +1,21 @@
|
||||
package gay.pizza.foundation.core.features.persist
|
||||
|
||||
import gay.pizza.foundation.core.FoundationCorePlugin
|
||||
import gay.pizza.foundation.core.abstraction.Feature
|
||||
import gay.pizza.foundation.shared.PluginPersistence
|
||||
import org.koin.core.component.inject
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.dsl.module
|
||||
|
||||
class PersistenceFeature : Feature() {
|
||||
private val persistence = inject<PluginPersistence>()
|
||||
private val core = inject<FoundationCorePlugin>()
|
||||
|
||||
override fun disable() {
|
||||
persistence.value.unload()
|
||||
}
|
||||
|
||||
override fun module(): Module = module {
|
||||
single { PluginPersistence() }
|
||||
single { core.value.persistence }
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package gay.pizza.foundation.core.features.stats
|
||||
|
||||
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.PluginPersistence
|
||||
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 net.kyori.adventure.text.TextComponent
|
||||
import org.bukkit.event.EventHandler
|
||||
|
@ -4,4 +4,7 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
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
|
||||
|
||||
interface IFoundationCore {
|
||||
val persistence: PluginPersistence
|
||||
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.EntityIterable
|
||||
import jetbrains.exodus.entitystore.PersistentEntityStores
|
||||
import jetbrains.exodus.entitystore.StoreTransaction
|
||||
|
||||
class PersistentStore(corePlugin: FoundationCorePlugin, fileStoreName: String) : AutoCloseable {
|
||||
private val fileStorePath = corePlugin.pluginDataPath.resolve("persistence/${fileStoreName}")
|
||||
class PersistentStore(core: IFoundationCore, fileStoreName: String) : AutoCloseable {
|
||||
private val fileStorePath = core.pluginDataPath.resolve("persistence/${fileStoreName}")
|
||||
private val entityStore = PersistentEntityStores.newInstance(fileStorePath.toFile())
|
||||
|
||||
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
|
||||
|
||||
class PluginPersistence : KoinComponent {
|
||||
private val plugin = inject<FoundationCorePlugin>()
|
||||
|
||||
class PluginPersistence(val core: IFoundationCore) {
|
||||
val stores = ConcurrentHashMap<String, PersistentStore>()
|
||||
|
||||
/**
|
||||
* Fetch a persistent store by name. Make sure the name is path-safe, descriptive and consistent across server runs.
|
||||
*/
|
||||
fun store(name: String): PersistentStore =
|
||||
stores.getOrPut(name) { PersistentStore(plugin.value, name) }
|
||||
stores.getOrPut(name) { PersistentStore(core, name) }
|
||||
|
||||
fun unload() {
|
||||
stores.values.forEach { store -> store.close() }
|
Loading…
Reference in New Issue
Block a user