all bugs free!!!

This commit is contained in:
TONY_All 2022-02-04 23:46:48 +08:00
parent 29bcc1e545
commit 2f9b04b690
3 changed files with 30 additions and 22 deletions

View File

@ -1,6 +1,7 @@
package cc.maxmc.invite
import cc.maxmc.invite.command.InviteCodeCommands
import cc.maxmc.invite.data.convert
import cc.maxmc.invite.data.initDatabase
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
@ -25,6 +26,7 @@ object BiliInviteCode : Plugin() {
override fun onEnable() {
initDatabase()
InviteCodeCommands
convert()
// cc.maxmc.invite.command.DebugCommands.debug()
}
}

View File

@ -125,12 +125,14 @@ object InviteCodeCommands {
}
}
private fun CommandBuilder.CommandComponent.cmdEdit() = literal("edit") {
private fun CommandBuilder.CommandComponent.cmdEdit() = literal("edit", permission = "invitecode.edit") {
dynamic {
restrict<ConsoleCommandSender> { _, _, arg ->
transaction {
!InviteCode.find { InviteCodes.name eq arg }.empty()
}
suggestion<ConsoleCommandSender> { sender, ctx ->
}
suggestion<ConsoleCommandSender> { _, _ ->
return@suggestion Bukkit.getOnlinePlayers().map { it.name }
}
dynamic {
@ -139,7 +141,7 @@ object InviteCodeCommands {
}
execute<ConsoleCommandSender> { sender, ctx, arg ->
PluginScope.launch {
InviteCode.find { InviteCodes.name eq ctx.get(-1) }.first().run {
InviteCode.find { InviteCodes.name eq ctx.argument(-1) }.first().run {
qq = arg
}
sender.sendMessage("§a| §7修改成功")
@ -153,9 +155,10 @@ object InviteCodeCommands {
dynamic {
execute<ConsoleCommandSender> { sender, _, arg ->
PluginScope.launch {
transaction {
if (!InviteCode.find { InviteCodes.inviteCode eq arg }.empty()) {
sender.sendMessage("§c| §7该邀请码已存在, 无法添加.")
return@launch
return@transaction
}
InviteCode.new {
inviteCode = arg
@ -165,14 +168,16 @@ object InviteCodeCommands {
}
}
}
}
private fun CommandBuilder.CommandComponent.cmdRemove() = literal("remove") {
dynamic {
execute<ConsoleCommandSender> { sender, _, arg ->
PluginScope.launch {
transaction {
val findings = InviteCode.find { InviteCodes.inviteCode eq arg }
if (findings.empty()) {
sender.sendMessage("§e| §7该邀请码不存在, 无需删除.")
return@transaction sender.sendMessage("§e| §7该邀请码不存在, 无需删除.")
}
findings.first().delete()
sender.sendMessage("§a| §7成功删除该邀请码.")
@ -180,6 +185,7 @@ object InviteCodeCommands {
}
}
}
}
private fun CommandBuilder.CommandComponent.cmdCurrent() = literal("current") {
execute<ConsoleCommandSender> { sender, _, _ ->

View File

@ -39,14 +39,14 @@ fun convert() {
}
}
fun readFile(file: File): Map<String, String?> {
private fun readFile(file: File): Map<String, String?> {
val config = YamlConfiguration.loadConfiguration(file)
return config.getMapList("invite-code")
.associate {
try {
val player = it["player"] as String?
val player = it["player"]?.toString()
it.remove("player")
val code = it.values.first() as String
val code = it.values.first().toString()
code to player
} catch (e: Exception) {
println("§e| §7一条数据转换失败, 正在忽略...")