Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eddf240f0c | ||
|
|
4f406353ba | ||
|
|
095494dd2e | ||
|
|
fd92645500 | ||
|
|
1a6ac29083 |
@@ -401,15 +401,6 @@ public interface Eco {
|
||||
@NotNull
|
||||
ServerProfile getServerProfile();
|
||||
|
||||
/**
|
||||
* Unload a player profile from memory.
|
||||
* <p>
|
||||
* This will not save the profile first.
|
||||
*
|
||||
* @param uuid The uuid.
|
||||
*/
|
||||
void unloadPlayerProfile(@NotNull UUID uuid);
|
||||
|
||||
/**
|
||||
* Create dummy entity - never spawned, exists purely in code.
|
||||
*
|
||||
|
||||
@@ -17,6 +17,13 @@ import java.util.function.Supplier;
|
||||
* @param <T> The type of integration.
|
||||
*/
|
||||
public class IntegrationRegistry<T extends Integration> extends Registry<T> {
|
||||
/**
|
||||
* Create a new integration registry.
|
||||
*/
|
||||
public IntegrationRegistry() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull T register(@NotNull final T element) {
|
||||
return executeSafely(() -> super.register(element), element);
|
||||
|
||||
@@ -286,9 +286,6 @@ class EcoImpl : EcoSpigotPlugin(), Eco {
|
||||
override fun loadPlayerProfile(uuid: UUID) =
|
||||
profileHandler.load(uuid)
|
||||
|
||||
override fun unloadPlayerProfile(uuid: UUID) =
|
||||
profileHandler.unloadPlayer(uuid)
|
||||
|
||||
override fun createDummyEntity(location: Location): Entity =
|
||||
getProxy(DummyEntityFactoryProxy::class.java).createDummyEntity(location)
|
||||
|
||||
|
||||
@@ -219,8 +219,6 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
this.logger.info("No conflicts found!")
|
||||
}
|
||||
|
||||
|
||||
CollatedRunnable(this)
|
||||
CustomItemsManager.registerProviders() // Do it again here
|
||||
|
||||
// Register events for ShopSellEvent
|
||||
@@ -251,7 +249,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
Eco.get().adventure?.close()
|
||||
}
|
||||
|
||||
override fun handleReload() {
|
||||
override fun createTasks() {
|
||||
CollatedRunnable(this)
|
||||
|
||||
this.scheduler.runLater(3) {
|
||||
@@ -384,7 +382,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
GUIListener(this),
|
||||
ArrowDataListener(this),
|
||||
ArmorChangeEventListeners(this),
|
||||
DataListener(this),
|
||||
DataListener(this, profileHandler),
|
||||
PlayerBlockListener(this),
|
||||
ServerLocking
|
||||
)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.willfp.eco.internal.spigot.data
|
||||
|
||||
import com.willfp.eco.core.Eco
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.util.PlayerUtils
|
||||
import org.bukkit.event.EventHandler
|
||||
@@ -11,11 +10,14 @@ import org.bukkit.event.player.PlayerLoginEvent
|
||||
import org.bukkit.event.player.PlayerQuitEvent
|
||||
|
||||
class DataListener(
|
||||
private val plugin: EcoPlugin
|
||||
private val plugin: EcoPlugin,
|
||||
private val handler: ProfileHandler
|
||||
) : Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
fun onLeave(event: PlayerQuitEvent) {
|
||||
Eco.get().unloadPlayerProfile(event.player.uniqueId)
|
||||
val profile = handler.accessLoadedProfile(event.player.uniqueId) ?: return
|
||||
handler.saveKeysFor(event.player.uniqueId, profile.data.keys)
|
||||
handler.unloadPlayer(event.player.uniqueId)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -27,6 +29,6 @@ class DataListener(
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
fun onLogin(event: PlayerLoginEvent) {
|
||||
Eco.get().unloadPlayerProfile(event.player.uniqueId)
|
||||
handler.unloadPlayer(event.player.uniqueId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.willfp.eco.core.config.interfaces.Config
|
||||
import com.willfp.eco.core.data.keys.PersistentDataKey
|
||||
import com.willfp.eco.core.data.keys.PersistentDataKeyType
|
||||
import org.bukkit.NamespacedKey
|
||||
import java.math.BigDecimal
|
||||
|
||||
object KeyRegistry {
|
||||
private val registry = mutableMapOf<NamespacedKey, PersistentDataKey<*>>()
|
||||
@@ -44,6 +45,9 @@ object KeyRegistry {
|
||||
PersistentDataKeyType.CONFIG -> if (default !is Config) {
|
||||
throw IllegalArgumentException("Invalid Data Type! Should be Config")
|
||||
}
|
||||
PersistentDataKeyType.BIG_DECIMAL -> if (default !is BigDecimal) {
|
||||
throw IllegalArgumentException("Invalid Data Type! Should be BigDecimal")
|
||||
}
|
||||
|
||||
else -> throw NullPointerException("Null value found!")
|
||||
}
|
||||
|
||||
@@ -58,11 +58,18 @@ class ProfileHandler(
|
||||
}
|
||||
|
||||
fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
|
||||
handler.saveKeysFor(uuid, keys)
|
||||
val profile = accessLoadedProfile(uuid) ?: return
|
||||
val map = mutableMapOf<PersistentDataKey<*>, Any>()
|
||||
|
||||
for (key in keys) {
|
||||
map[key] = profile.data[key] ?: continue
|
||||
}
|
||||
|
||||
handler.saveKeysFor(uuid, map)
|
||||
|
||||
// Don't save to local handler if it's the same handler.
|
||||
if (localHandler != handler) {
|
||||
localHandler.saveKeysFor(uuid, keys)
|
||||
localHandler.saveKeysFor(uuid, map)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ abstract class DataHandler(
|
||||
/**
|
||||
* Save a set of keys for a given UUID.
|
||||
*/
|
||||
abstract fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>)
|
||||
abstract fun saveKeysFor(uuid: UUID, keys: Map<PersistentDataKey<*>, Any>)
|
||||
|
||||
// Everything below this are methods that are only needed for certain implementations.
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.willfp.eco.internal.spigot.data.storage
|
||||
|
||||
import com.willfp.eco.core.data.Profile
|
||||
import com.willfp.eco.core.data.keys.PersistentDataKey
|
||||
import com.willfp.eco.internal.spigot.EcoSpigotPlugin
|
||||
import com.willfp.eco.internal.spigot.data.ProfileHandler
|
||||
@@ -51,18 +50,16 @@ class MongoDataHandler(
|
||||
}
|
||||
}
|
||||
|
||||
override fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
|
||||
val profile = handler.loadGenericProfile(uuid)
|
||||
|
||||
override fun saveKeysFor(uuid: UUID, keys: Map<PersistentDataKey<*>, Any>) {
|
||||
scope.launch {
|
||||
for (key in keys) {
|
||||
saveKey(profile, uuid, key)
|
||||
for ((key, value) in keys) {
|
||||
saveKey(uuid, key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun <T : Any> saveKey(profile: Profile, uuid: UUID, key: PersistentDataKey<T>) {
|
||||
val data = profile.read(key)
|
||||
private suspend fun <T : Any> saveKey(uuid: UUID, key: PersistentDataKey<T>, value: Any) {
|
||||
val data = value as T
|
||||
doWrite(uuid, key, data)
|
||||
}
|
||||
|
||||
|
||||
@@ -101,16 +101,15 @@ class MySQLDataHandler(
|
||||
setData(uuid, data)
|
||||
}
|
||||
|
||||
override fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
|
||||
val profile = handler.loadGenericProfile(uuid)
|
||||
|
||||
override fun saveKeysFor(uuid: UUID, keys: Map<PersistentDataKey<*>, Any>) {
|
||||
executor.submit {
|
||||
val data = getData(uuid)
|
||||
for (key in keys) {
|
||||
data.set(key.key.toString(), profile.read(key))
|
||||
|
||||
for ((key, value) in keys) {
|
||||
data.set(key.key.toString(), value)
|
||||
}
|
||||
|
||||
setData(uuid, data)
|
||||
doSetData(uuid, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,10 +139,14 @@ class MySQLDataHandler(
|
||||
|
||||
private fun setData(uuid: UUID, config: Config) {
|
||||
executor.submit {
|
||||
transaction(database) {
|
||||
table.update({ table.id eq uuid }) {
|
||||
it[dataColumn] = config.toPlaintext()
|
||||
}
|
||||
doSetData(uuid, config)
|
||||
}
|
||||
}
|
||||
|
||||
private fun doSetData(uuid: UUID, config: Config) {
|
||||
transaction(database) {
|
||||
table.update({ table.id eq uuid }) {
|
||||
it[dataColumn] = config.toPlaintext()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,12 @@ class ProfileSaver(
|
||||
val uuid = iterator.next()
|
||||
iterator.remove()
|
||||
|
||||
val profile = handler.accessLoadedProfile(uuid) ?: continue
|
||||
val profile = handler.accessLoadedProfile(uuid)
|
||||
|
||||
if (profile == null) {
|
||||
iterator.remove()
|
||||
continue
|
||||
}
|
||||
|
||||
handler.saveKeysFor(uuid, profile.data.keys)
|
||||
}
|
||||
|
||||
@@ -41,11 +41,9 @@ class YamlDataHandler(
|
||||
doWrite(uuid, key.key, value)
|
||||
}
|
||||
|
||||
override fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
|
||||
val profile = handler.loadGenericProfile(uuid)
|
||||
|
||||
for (key in keys) {
|
||||
doWrite(uuid, key.key, profile.read(key))
|
||||
override fun saveKeysFor(uuid: UUID, keys: Map<PersistentDataKey<*>, Any>) {
|
||||
for ((key, value) in keys) {
|
||||
doWrite(uuid, key.key, value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version = 6.60.0
|
||||
version = 6.60.2
|
||||
plugin-name = eco
|
||||
kotlin.code.style = official
|
||||
Reference in New Issue
Block a user