all bugs free!!!
This commit is contained in:
parent
29bcc1e545
commit
2f9b04b690
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 ->
|
||||
!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 }
|
||||
}
|
||||
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,29 +155,33 @@ object InviteCodeCommands {
|
|||
dynamic {
|
||||
execute<ConsoleCommandSender> { sender, _, arg ->
|
||||
PluginScope.launch {
|
||||
if (!InviteCode.find { InviteCodes.inviteCode eq arg }.empty()) {
|
||||
sender.sendMessage("§c| §7该邀请码已存在, 无法添加.")
|
||||
return@launch
|
||||
transaction {
|
||||
if (!InviteCode.find { InviteCodes.inviteCode eq arg }.empty()) {
|
||||
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") {
|
||||
execute<ConsoleCommandSender> { sender, _, arg ->
|
||||
PluginScope.launch {
|
||||
transaction {
|
||||
val findings = InviteCode.find { InviteCodes.inviteCode eq arg }
|
||||
if (findings.empty()) {
|
||||
sender.sendMessage("§e| §7该邀请码不存在, 无需删除.")
|
||||
dynamic {
|
||||
execute<ConsoleCommandSender> { sender, _, arg ->
|
||||
PluginScope.launch {
|
||||
transaction {
|
||||
val findings = InviteCode.find { InviteCodes.inviteCode eq arg }
|
||||
if (findings.empty()) {
|
||||
return@transaction sender.sendMessage("§e| §7该邀请码不存在, 无需删除.")
|
||||
}
|
||||
findings.first().delete()
|
||||
sender.sendMessage("§a| §7成功删除该邀请码.")
|
||||
}
|
||||
findings.first().delete()
|
||||
sender.sendMessage("§a| §7成功删除该邀请码.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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一条数据转换失败, 正在忽略...")
|
||||
|
|
|
|||
Loading…
Reference in New Issue