Data Handler changes
This commit is contained in:
@@ -4,33 +4,35 @@ import com.willfp.eco.core.data.keys.KeyRegistry
|
|||||||
import com.willfp.eco.core.data.keys.PersistentDataKey
|
import com.willfp.eco.core.data.keys.PersistentDataKey
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
interface DataHandler {
|
abstract class DataHandler(
|
||||||
|
val type: HandlerType
|
||||||
|
) {
|
||||||
/**
|
/**
|
||||||
* Read value from a key.
|
* Read value from a key.
|
||||||
*/
|
*/
|
||||||
fun <T : Any> read(uuid: UUID, key: PersistentDataKey<T>): T?
|
abstract fun <T : Any> read(uuid: UUID, key: PersistentDataKey<T>): T?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write value to a key.
|
* Write value to a key.
|
||||||
*/
|
*/
|
||||||
fun <T : Any> write(uuid: UUID, key: PersistentDataKey<T>, value: T)
|
abstract fun <T : Any> write(uuid: UUID, key: PersistentDataKey<T>, value: T)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a set of keys for a given UUID.
|
* Save a set of keys for a given UUID.
|
||||||
*/
|
*/
|
||||||
fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>)
|
abstract fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>)
|
||||||
|
|
||||||
// Everything below this are methods that are only needed for certain implementations.
|
// Everything below this are methods that are only needed for certain implementations.
|
||||||
|
|
||||||
fun save() {
|
open fun save() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun categorize(key: PersistentDataKey<*>, category: KeyRegistry.KeyCategory) {
|
open fun categorize(key: PersistentDataKey<*>, category: KeyRegistry.KeyCategory) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun initialize() {
|
open fun initialize() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.util.UUID
|
|||||||
class MongoDataHandler(
|
class MongoDataHandler(
|
||||||
plugin: EcoSpigotPlugin,
|
plugin: EcoSpigotPlugin,
|
||||||
private val handler: EcoProfileHandler
|
private val handler: EcoProfileHandler
|
||||||
) : DataHandler {
|
) : DataHandler(HandlerType.MONGO) {
|
||||||
private val client: CoroutineClient
|
private val client: CoroutineClient
|
||||||
private val collection: CoroutineCollection<UUIDProfile>
|
private val collection: CoroutineCollection<UUIDProfile>
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ the worst bodge I've shipped in production.
|
|||||||
class MySQLDataHandler(
|
class MySQLDataHandler(
|
||||||
private val plugin: EcoSpigotPlugin,
|
private val plugin: EcoSpigotPlugin,
|
||||||
handler: EcoProfileHandler
|
handler: EcoProfileHandler
|
||||||
) : DataHandler {
|
) : DataHandler(HandlerType.MYSQL) {
|
||||||
private val playerHandler: ImplementedMySQLHandler
|
private val playerHandler: ImplementedMySQLHandler
|
||||||
private val serverHandler: ImplementedMySQLHandler
|
private val serverHandler: ImplementedMySQLHandler
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.util.UUID
|
|||||||
class YamlDataHandler(
|
class YamlDataHandler(
|
||||||
plugin: EcoSpigotPlugin,
|
plugin: EcoSpigotPlugin,
|
||||||
private val handler: EcoProfileHandler
|
private val handler: EcoProfileHandler
|
||||||
) : DataHandler {
|
) : DataHandler(HandlerType.YAML) {
|
||||||
private val dataYml = plugin.dataYml
|
private val dataYml = plugin.dataYml
|
||||||
|
|
||||||
override fun save() {
|
override fun save() {
|
||||||
|
|||||||
Reference in New Issue
Block a user