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 package cc.maxmc.invite
import cc.maxmc.invite.command.InviteCodeCommands import cc.maxmc.invite.command.InviteCodeCommands
import cc.maxmc.invite.data.convert
import cc.maxmc.invite.data.initDatabase import cc.maxmc.invite.data.initDatabase
import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -25,6 +26,7 @@ object BiliInviteCode : Plugin() {
override fun onEnable() { override fun onEnable() {
initDatabase() initDatabase()
InviteCodeCommands InviteCodeCommands
convert()
// cc.maxmc.invite.command.DebugCommands.debug() // 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 { dynamic {
restrict<ConsoleCommandSender> { _, _, arg -> restrict<ConsoleCommandSender> { _, _, arg ->
!InviteCode.find { InviteCodes.name eq arg }.empty() transaction {
!InviteCode.find { InviteCodes.name eq arg }.empty()
}
} }
suggestion<ConsoleCommandSender> { sender, ctx -> suggestion<ConsoleCommandSender> { _, _ ->
return@suggestion Bukkit.getOnlinePlayers().map { it.name } return@suggestion Bukkit.getOnlinePlayers().map { it.name }
} }
dynamic { dynamic {
@ -139,7 +141,7 @@ object InviteCodeCommands {
} }
execute<ConsoleCommandSender> { sender, ctx, arg -> execute<ConsoleCommandSender> { sender, ctx, arg ->
PluginScope.launch { PluginScope.launch {
InviteCode.find { InviteCodes.name eq ctx.get(-1) }.first().run { InviteCode.find { InviteCodes.name eq ctx.argument(-1) }.first().run {
qq = arg qq = arg
} }
sender.sendMessage("§a| §7修改成功") sender.sendMessage("§a| §7修改成功")
@ -153,29 +155,33 @@ object InviteCodeCommands {
dynamic { dynamic {
execute<ConsoleCommandSender> { sender, _, arg -> execute<ConsoleCommandSender> { sender, _, arg ->
PluginScope.launch { PluginScope.launch {
if (!InviteCode.find { InviteCodes.inviteCode eq arg }.empty()) { transaction {
sender.sendMessage("§c| §7该邀请码已存在, 无法添加.") if (!InviteCode.find { InviteCodes.inviteCode eq arg }.empty()) {
return@launch sender.sendMessage("§c| §7该邀请码已存在, 无法添加.")
return@transaction
}
InviteCode.new {
inviteCode = arg
}
sender.sendMessage("§a| §7成功添加一个邀请码: §a$arg")
} }
InviteCode.new {
inviteCode = arg
}
sender.sendMessage("§a| §7成功添加一个邀请码: §a$arg")
} }
} }
} }
} }
private fun CommandBuilder.CommandComponent.cmdRemove() = literal("remove") { private fun CommandBuilder.CommandComponent.cmdRemove() = literal("remove") {
execute<ConsoleCommandSender> { sender, _, arg -> dynamic {
PluginScope.launch { execute<ConsoleCommandSender> { sender, _, arg ->
transaction { PluginScope.launch {
val findings = InviteCode.find { InviteCodes.inviteCode eq arg } transaction {
if (findings.empty()) { val findings = InviteCode.find { InviteCodes.inviteCode eq arg }
sender.sendMessage("§e| §7该邀请码不存在, 无需删除.") if (findings.empty()) {
return@transaction sender.sendMessage("§e| §7该邀请码不存在, 无需删除.")
}
findings.first().delete()
sender.sendMessage("§a| §7成功删除该邀请码.")
} }
findings.first().delete()
sender.sendMessage("§a| §7成功删除该邀请码.")
} }
} }
} }

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