Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ import dev.slne.surf.cloud.api.common.player.toCloudPlayer
import dev.slne.surf.cloud.bukkit.permission.CloudPermissionRegistry
import dev.slne.surf.cloud.bukkit.plugin
import dev.slne.surf.surfapi.core.api.messages.adventure.sendText
import kotlinx.coroutines.Deferred
import org.bukkit.command.CommandSender

fun playtimeCommand() = commandTree("playtime") {
withPermission(CloudPermissionRegistry.PLAYTIME_COMMAND)

playerExecutor { sender, args ->
playerExecutor { sender, _ ->
sendPlaytime(sender, sender.toCloudPlayer() ?: throw AssertionError("Player is null"))
}
offlineCloudPlayerArgument("player") {
withPermission(CloudPermissionRegistry.PLAYTIME_COMMAND_OTHER)
anyExecutor { sender, args ->
val player: OfflineCloudPlayer? by args
player?.let { sendPlaytime(sender, it) }
val player: Deferred<OfflineCloudPlayer?> by args

plugin.launch {
player.await()?.let { sendPlaytime(sender, it) }
}
Comment on lines +28 to +30
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sendPlaytime function already calls plugin.launch internally (line 35), so wrapping this call in another plugin.launch creates unnecessary nested coroutine scopes.

Consider removing the outer plugin.launch and calling sendPlaytime directly within a suspend function, similar to how LastSeenCommand handles this pattern:

anyExecutor { sender, args ->
    val player: Deferred<OfflineCloudPlayer?> by args
    
    plugin.launch {
        val awaited = player.await() ?: return@launch
        sendPlaytime(sender, awaited)
    }
}

Or refactor sendPlaytime to be a regular function that doesn't launch its own coroutine, allowing the caller to control the coroutine scope.

Copilot uses AI. Check for mistakes.
}
}
}
Expand All @@ -39,7 +43,7 @@ private fun sendPlaytime(sender: CommandSender, player: OfflineCloudPlayer) = pl
variableValue("${player.name()} (${player.uuid})")
appendNewPrefixedLine()
appendNewPrefixedLine {
variableKey("Total")
variableKey("Gesamt")
spacer(": ")
variableValue(complete.toString())
}
Expand Down
Loading