Changed PlayerProfileHandler

This commit is contained in:
Auxilor
2021-11-12 11:10:56 +00:00
parent 4788f036ee
commit c912b97438
3 changed files with 34 additions and 6 deletions

View File

@@ -16,13 +16,33 @@ public interface PlayerProfileHandler {
*/
PlayerProfile load(@NotNull UUID uuid);
/**
* Unload a player profile from memory.
* <p>
* 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.
* <p>
* 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.
* <p>
* Can run async if using MySQL.
*/
void saveAll();
/**
* Save all player data, forcibly synchronously.
*/
void saveAllBlocking();
}

View File

@@ -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)")
}
}

View File

@@ -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())
}