@@ -8,6 +8,7 @@ import dev.betrix.superSmashMobsBrawl.extensions.warn
88import dev.betrix.superSmashMobsBrawl.models.player.PlayerDocument
99import gg.flyte.twilight.event.event
1010import gg.flyte.twilight.scheduler.repeatingTask
11+ import java.util.UUID
1112import kotlin.time.Duration.Companion.minutes
1213import kotlinx.coroutines.Dispatchers
1314import kotlinx.coroutines.runBlocking
@@ -18,7 +19,6 @@ import org.bukkit.event.player.PlayerJoinEvent
1819import org.bukkit.event.player.PlayerQuitEvent
1920import org.koin.core.component.KoinComponent
2021import org.koin.core.component.inject
21- import java.util.UUID
2222
2323object PlayerDocumentService : KoinComponent, Manageable() {
2424 private val api: ApiService by inject()
@@ -45,7 +45,10 @@ object PlayerDocumentService : KoinComponent, Manageable() {
4545 val player = plugin.server.getPlayer(uuid)
4646
4747 if (player == null ) {
48- plugin.logger.warn(" Player with UUID {uuid} not found, removing from cache and skipping persistence." , uuid)
48+ plugin.logger.warn(
49+ " Player with UUID {uuid} not found, removing from cache and skipping persistence." ,
50+ uuid,
51+ )
4952 documents.remove(uuid)
5053 return @withContext
5154 }
@@ -55,7 +58,7 @@ object PlayerDocumentService : KoinComponent, Manageable() {
5558 plugin.logger.warn(
5659 " Failed to persist document for {playerName}: {errorMessage}" ,
5760 player.name,
58- it.message ? : " No error message"
61+ it.message ? : " No error message" ,
5962 )
6063 }
6164 }
@@ -97,14 +100,21 @@ object PlayerDocumentService : KoinComponent, Manageable() {
97100 val player = plugin.server.getPlayer(uuid)
98101
99102 if (player == null ) {
100- plugin.logger.warn(" Player with UUID {uuid} not found, skipping persistence." , uuid)
103+ plugin.logger.warn(
104+ " Player with UUID {uuid} not found, skipping persistence." ,
105+ uuid,
106+ )
101107 return @forEach
102108 }
103109
104110 withContext(Dispatchers .IO ) {
105111 runCatching { api.playersSetDocumentAsync(player, doc) }
106112 .onFailure {
107- plugin.logger.warn(" Flush failed for {playerName}: {errorMessage}" , player.name, it.message ? : " No error message" )
113+ plugin.logger.warn(
114+ " Flush failed for {playerName}: {errorMessage}" ,
115+ player.name,
116+ it.message ? : " No error message" ,
117+ )
108118 }
109119 }
110120 }
@@ -113,16 +123,17 @@ object PlayerDocumentService : KoinComponent, Manageable() {
113123 }
114124
115125 fun getPlayerDocument (player : Player ): PlayerDocument =
116- documents[player.uniqueId] ? : error(" Player document for ${player.name} not found in cache." )
117-
118- fun getPlayerDocumentOrNull (player : Player ): PlayerDocument ? =
119126 documents[player.uniqueId]
127+ ? : error(" Player document for ${player.name} not found in cache." )
128+
129+ fun getPlayerDocumentOrNull (player : Player ): PlayerDocument ? = documents[player.uniqueId]
120130
121131 suspend fun getPlayerDocumentOrFetch (player : Player ): PlayerDocument {
122- return documents[player.uniqueId] ? : withContext(Dispatchers .IO ) {
123- val document = api.playersGetDocumentAsync(player, true )
124- documents[player.uniqueId] = document
125- document
126- }
132+ return documents[player.uniqueId]
133+ ? : withContext(Dispatchers .IO ) {
134+ val document = api.playersGetDocumentAsync(player, true )
135+ documents[player.uniqueId] = document
136+ document
137+ }
127138 }
128139}
0 commit comments