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