-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathConvertSubcommand.kt
More file actions
34 lines (30 loc) · 1.34 KB
/
ConvertSubcommand.kt
File metadata and controls
34 lines (30 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.github.quiltservertools.ledger.commands.subcommands
import com.github.quiltservertools.ledger.Ledger
import com.github.quiltservertools.ledger.commands.BuildableCommand
import com.github.quiltservertools.ledger.commands.CommandConsts
import com.github.quiltservertools.ledger.database.DatabaseManager
import com.github.quiltservertools.ledger.utility.LiteralNode
import com.mojang.brigadier.context.CommandContext
import kotlinx.coroutines.launch
import me.lucko.fabric.api.permissions.v0.Permissions
import net.minecraft.server.command.CommandManager.literal
import net.minecraft.server.command.ServerCommandSource
import net.minecraft.text.Text
private const val PROGRESS_INTERVAL = 30L
object ConvertSubcommand : BuildableCommand {
override fun build(): LiteralNode =
literal("convert")
.requires(Permissions.require("ledger.commands.convert", CommandConsts.PERMISSION_LEVEL))
.executes { convertDatabase(it) }
.build()
private fun convertDatabase(it: CommandContext<ServerCommandSource>): Int {
Ledger.launch {
DatabaseManager.convertActions { done, total ->
if (done % PROGRESS_INTERVAL == 0L) {
it.source.sendFeedback({ Text.of("Converted $done/$total actions") }, false)
}
}
}
return 1
}
}