diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/PlayerProfileHandler.java b/eco-api/src/main/java/com/willfp/eco/core/data/PlayerProfileHandler.java index 47b46c1a..24df0034 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/data/PlayerProfileHandler.java +++ b/eco-api/src/main/java/com/willfp/eco/core/data/PlayerProfileHandler.java @@ -16,13 +16,33 @@ public interface PlayerProfileHandler { */ PlayerProfile load(@NotNull UUID uuid); + /** + * Unload a player profile from memory. + *

+ * This will not save the profile first, so to avoid data loss, run a blocking + * save beforehand. + * + * @param uuid The uuid. + */ + void unloadPlayer(@NotNull UUID uuid); + /** * Save a player profile. + *

+ * Can run async if using MySQL. * * @param uuid The uuid. */ void savePlayer(@NotNull UUID uuid); + + /** + * Save a player profile, forcibly synchronously. + * + * @param uuid The uuid. + */ + void savePlayerBlocking(@NotNull UUID uuid); + /** * Save all player data. * @@ -36,6 +56,13 @@ public interface PlayerProfileHandler { /** * Save all player data. + *

+ * Can run async if using MySQL. */ void saveAll(); + + /** + * Save all player data, forcibly synchronously. + */ + void saveAllBlocking(); } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/DataListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/DataListener.kt index 27f88b16..efb11155 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/DataListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/DataListener.kt @@ -12,19 +12,20 @@ class DataListener : Listener { @EventHandler fun onLeave(event: PlayerQuitEvent) { PlayerUtils.updateSavedDisplayName(event.player) - (Eco.getHandler().playerProfileHandler as EcoPlayerProfileHandler).savePlayerBlocking(event.player.uniqueId) - (Eco.getHandler().playerProfileHandler as EcoPlayerProfileHandler).unloadPlayer(event.player.uniqueId) + Eco.getHandler().playerProfileHandler.savePlayerBlocking(event.player.uniqueId) + Eco.getHandler().playerProfileHandler.unloadPlayer(event.player.uniqueId) Eco.getHandler().ecoPlugin.logger.info("Player ${event.player.name} Quit (Saving)") } @EventHandler fun onJoin(event: PlayerJoinEvent) { + Eco.getHandler().playerProfileHandler.unloadPlayer(event.player.uniqueId) PlayerUtils.updateSavedDisplayName(event.player) } @EventHandler fun onLogin(event: PlayerLoginEvent) { - (Eco.getHandler().playerProfileHandler as EcoPlayerProfileHandler).unloadPlayer(event.player.uniqueId) + Eco.getHandler().playerProfileHandler.unloadPlayer(event.player.uniqueId) Eco.getHandler().ecoPlugin.logger.info("Player ${event.player.name} Logged In (Saving)") } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/EcoPlayerProfileHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/EcoPlayerProfileHandler.kt index e53da89e..152852fa 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/EcoPlayerProfileHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/data/EcoPlayerProfileHandler.kt @@ -32,7 +32,7 @@ class EcoPlayerProfileHandler( return profile } - fun unloadPlayer(uuid: UUID) { + override fun unloadPlayer(uuid: UUID) { loaded.remove(uuid) } @@ -40,7 +40,7 @@ class EcoPlayerProfileHandler( handler.savePlayer(uuid) } - fun savePlayerBlocking(uuid: UUID) { + override fun savePlayerBlocking(uuid: UUID) { handler.saveAllBlocking(listOf(uuid)) } @@ -48,7 +48,7 @@ class EcoPlayerProfileHandler( handler.saveAll(loaded.keys.toList()) } - fun saveAllBlocking() { + override fun saveAllBlocking() { handler.saveAllBlocking(loaded.keys.toList()) }