add autokick
This commit is contained in:
parent
c76a154caa
commit
420a2da064
|
|
@ -4,6 +4,8 @@ import cc.maxmc.invite.PluginScope
|
|||
import cc.maxmc.invite.concurrent.chatInput
|
||||
import cc.maxmc.invite.data.InviteCode
|
||||
import cc.maxmc.invite.data.InviteCodes
|
||||
import cc.maxmc.invite.data.UserTrial
|
||||
import cc.maxmc.invite.data.userTrials
|
||||
import cc.maxmc.invite.listener.InvitedListener
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -49,7 +51,19 @@ object InviteCodeCommands {
|
|||
PluginScope.launch {
|
||||
val inviteCode = transaction {
|
||||
val inviteCode = InviteCode.find { InviteCodes.inviteCode eq argument }.firstOrNull()
|
||||
?: return@transaction let { sender.sendMessage("§c| §7该激活码不存在, 请重试."); null }
|
||||
?: return@transaction let {
|
||||
val trial = userTrials.computeIfAbsent(sender.uniqueId) {
|
||||
UserTrial(it)
|
||||
}
|
||||
trial.tryOnce()
|
||||
if (trial.isLimited()) {
|
||||
userTrials.remove(sender.uniqueId)
|
||||
sender.kickPlayer("§c| §7您的尝试次数过多.")
|
||||
return@let null
|
||||
}
|
||||
sender.sendMessage("§c| §7该激活码不存在, 请重试.")
|
||||
null
|
||||
}
|
||||
if (inviteCode.name != null) return@transaction sender.sendMessage("§c| §7该邀请码已被激活, 请重试.")
|
||||
.let { null }
|
||||
return@transaction inviteCode
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import taboolib.common.platform.function.info
|
|||
import taboolib.common.platform.function.warning
|
||||
import taboolib.platform.BukkitPlugin
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
fun initDatabase() {
|
||||
try {
|
||||
|
|
@ -48,5 +50,12 @@ class InviteCode(id: EntityID<Int>) : IntEntity(id) {
|
|||
var name by InviteCodes.name
|
||||
var uid by InviteCodes.uid
|
||||
var qq by InviteCodes.qq
|
||||
|
||||
}
|
||||
|
||||
val userTrials = HashMap<UUID, UserTrial>()
|
||||
|
||||
data class UserTrial(val uid: UUID, private var attempts: Int = 0) {
|
||||
fun tryOnce() = attempts++
|
||||
|
||||
fun isLimited() = attempts == 3
|
||||
}
|
||||
Loading…
Reference in New Issue