all bugs free

This commit is contained in:
TONY_All 2022-02-05 23:01:35 +08:00
parent 585761ae9c
commit 363457deba
4 changed files with 45 additions and 28 deletions

View File

@ -1,6 +1,7 @@
package cc.maxmc.invite.command
import cc.maxmc.invite.PluginScope
import cc.maxmc.invite.bukkitSyncContext
import cc.maxmc.invite.concurrent.chatInput
import cc.maxmc.invite.data.InviteCode
import cc.maxmc.invite.data.InviteCodes
@ -34,6 +35,7 @@ object InviteCodeCommands {
cmdAdd()
cmdRemove()
cmdCurrent()
cmdInspect()
}
}
@ -51,24 +53,26 @@ object InviteCodeCommands {
if (!InvitedListener.cache.containsKey(sender.uniqueId)) return@execute sender.sendMessage("§e| §7您的账号已激活, 无需使用邀请码.")
sender.sendMessage("§b| §7正在激活邀请码...")
PluginScope.launch {
val inviteCode = transaction {
val inviteCode = newSuspendedTransaction {
val inviteCode = InviteCode.find { InviteCodes.inviteCode eq argument }.firstOrNull()
?: return@transaction let {
?: return@newSuspendedTransaction let {
val trial = userTrials.computeIfAbsent(sender.uniqueId) {
UserTrial(it)
}
trial.tryOnce()
if (trial.isLimited()) {
userTrials.remove(sender.uniqueId)
sender.kickPlayer("§c| §7您的尝试次数过多.")
withContext(bukkitSyncContext) {
sender.kickPlayer("§c| §7您的尝试次数过多.")
}
return@let null
}
sender.sendMessage("§c| §7该激活码不存在, 请重试.")
null
}
if (inviteCode.name != null) return@transaction sender.sendMessage("§c| §7该邀请码已被激活, 请重试.")
if (inviteCode.name != null) return@newSuspendedTransaction sender.sendMessage("§c| §7该邀请码已被激活, 请重试.")
.let { null }
return@transaction inviteCode
return@newSuspendedTransaction inviteCode
} ?: return@launch
val qqNum = requireQQNumber(sender) ?: return@launch sender.sendMessage("§e| §7已取消激活验证码.")
sender.sendMessage("§a| §7该激活码成功绑定至QQ: §a${qqNum}")
@ -141,33 +145,34 @@ object InviteCodeCommands {
}
}
private fun CommandBuilder.CommandComponent.cmdEdit() = literal("edit", permission = "inviteCode.edit".lowercase()) {
dynamic {
restrict<ConsoleCommandSender> { _, _, arg ->
transaction {
!InviteCode.find { InviteCodes.name eq arg }.empty()
}
}
suggestion<ConsoleCommandSender>(uncheck = true) { _, _ ->
return@suggestion Bukkit.getOnlinePlayers().map { it.name }
}
private fun CommandBuilder.CommandComponent.cmdEdit() =
literal("edit", permission = "inviteCode.edit".lowercase()) {
dynamic {
restrict<ConsoleCommandSender> { _, _, arg ->
arg.length <= 10 && arg.toLongOrNull() != null
transaction {
!InviteCode.find { InviteCodes.name eq arg }.empty()
}
}
execute<ConsoleCommandSender> { sender, ctx, arg ->
PluginScope.launch {
transaction {
InviteCode.find { InviteCodes.name eq ctx.argument(-1) }.first().run {
qq = arg
suggestion<ConsoleCommandSender>(uncheck = true) { _, _ ->
return@suggestion Bukkit.getOnlinePlayers().map { it.name }
}
dynamic {
restrict<ConsoleCommandSender> { _, _, arg ->
arg.length <= 10 && arg.toLongOrNull() != null
}
execute<ConsoleCommandSender> { sender, ctx, arg ->
PluginScope.launch {
transaction {
InviteCode.find { InviteCodes.name eq ctx.argument(-1) }.first().run {
qq = arg
}
sender.sendMessage("§a| §7修改成功")
}
sender.sendMessage("§a| §7修改成功")
}
}
}
}
}
}
private fun CommandBuilder.CommandComponent.cmdAdd() = literal("add") {
dynamic {
@ -220,7 +225,7 @@ object InviteCodeCommands {
output.createNewFile()
output.writeText(result)
}
sender.sendMessage("§a| §7现存可用邀请码已保存至plugins/BiliInviteCode/current.txt")
sender.sendMessage("§a| §7现存可用邀请码已保存至 §aplugins/BiliInviteCode/current.txt")
}
}
}

View File

@ -14,8 +14,8 @@ import java.nio.file.Files
fun convert() {
val file = File("./plugins/InviteCode/config.yml")
info("§b| §7找到旧版配置文件, 正在转换...")
if (!file.exists()) return
info("§b| §7找到旧版配置文件, 正在转换...")
val read = readFile(file)
val usable = read.filter { it.value != null }
.filter { it.value != "null" }

View File

@ -32,7 +32,7 @@ fun initDatabase() {
PluginScope.launch {
transaction {
info("§b| §7正在读取数据库信息...")
SchemaUtils.create(InviteCodes)
SchemaUtils.create(InviteCodes, TimeTable)
info("§a| §7成功读取数据库信息.")
}
}

View File

@ -1,11 +1,13 @@
package cc.maxmc.invite.listener
import cc.maxmc.invite.PluginScope
import cc.maxmc.invite.bukkitSyncContext
import cc.maxmc.invite.concurrent.chatInput
import cc.maxmc.invite.data.InviteCode
import cc.maxmc.invite.data.InviteCodes
import cc.maxmc.invite.data.LastLogout
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.bukkit.Location
import org.bukkit.entity.Player
import org.bukkit.event.player.*
@ -66,10 +68,14 @@ object InvitedListener {
return input
}
/**
* @return if player passed time check
*/
suspend fun checkTime(uid: UUID): Boolean {
return newSuspendedTransaction {
// pass if not exists.
val lastLogout = LastLogout.findById(uid) ?: return@newSuspendedTransaction true
lastLogout.last.plusMonths(3).isBefore(LocalDate.now())
lastLogout.last.plusMonths(3).isAfter(LocalDate.now())
}
}
@ -81,7 +87,9 @@ object InvitedListener {
.firstOrNull()
?: return@newSuspendedTransaction e.player.sendMessage("§c| §7您的账号未激活, 请输入 §c/ic use <激活码> §7来进行激活.")
if (!checkTime(e.player.uniqueId)) {
e.player.kickPlayer("§c| §7由于超过3个月未登录游戏, 您的邀请码已失效.")
withContext(bukkitSyncContext) {
e.player.kickPlayer("§c| §7由于超过3个月未登录游戏, 您的邀请码已失效.")
}
playerInviteCode.delete()
return@newSuspendedTransaction
}
@ -101,6 +109,10 @@ object InvitedListener {
@SubscribeEvent
fun onQuit(e: PlayerQuitEvent) {
if (cache.containsKey(e.player.uniqueId)) {
e.player.teleport(cache[e.player.uniqueId]!!)
return
}
PluginScope.launch {
newSuspendedTransaction {
val lastLogout = LastLogout.findById(e.player.uniqueId)