From de0c5c941e6717be766b4e20a1236a2f8636ed61 Mon Sep 17 00:00:00 2001 From: Iru21 <33987046+Iru21@users.noreply.github.com> Date: Sun, 18 Sep 2022 17:45:03 +0200 Subject: [PATCH] Potential fix for kicking a player when another one tries to log in with the same name --- src/main/kotlin/me/iru/events/LoginEvents.kt | 9 ++++++--- .../me/iru/process/DuplicateProtection.kt | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/me/iru/events/LoginEvents.kt b/src/main/kotlin/me/iru/events/LoginEvents.kt index 5531338..cc79f6d 100644 --- a/src/main/kotlin/me/iru/events/LoginEvents.kt +++ b/src/main/kotlin/me/iru/events/LoginEvents.kt @@ -14,9 +14,12 @@ class LoginEvents : Listener { @EventHandler fun onJoin(e : PlayerJoinEvent) { - if(DuplicateProtection.check(e.player)) { - JoinProcess(e.player).run() - } + JoinProcess(e.player).run() + } + + @EventHandler + fun onInitialLogin(e : PlayerLoginEvent) { + DuplicateProtection.check(e) } @EventHandler diff --git a/src/main/kotlin/me/iru/process/DuplicateProtection.kt b/src/main/kotlin/me/iru/process/DuplicateProtection.kt index 59ee6d4..f796e25 100644 --- a/src/main/kotlin/me/iru/process/DuplicateProtection.kt +++ b/src/main/kotlin/me/iru/process/DuplicateProtection.kt @@ -3,16 +3,23 @@ package me.iru.process import me.iru.Authy import me.iru.PrefixType import org.bukkit.entity.Player +import org.bukkit.event.player.PlayerLoginEvent object DuplicateProtection { val playerData = Authy.playerData - val config = Authy.instance.config val translations = Authy.translations + val authy = Authy.instance + val config = authy.config + + fun check(e: PlayerLoginEvent) { + val p = e.player + if(authy.server.getPlayer(p.name) != null) { + e.disallow(PlayerLoginEvent.Result.KICK_OTHER, "") + } - fun check(p: Player): Boolean { val protLevel = config.getInt("duplicateIpProtection.protectionLevel") - if(protLevel == 0) return true + if(protLevel == 0) return val max = config.getInt("duplicateIpProtection.maxPerIp") val shouldNotify = config.getBoolean("duplicateIpProtection.notifyOnDuplicateIp") val duplicates = getDuplicatesForIpOf(p) @@ -28,11 +35,9 @@ object DuplicateProtection { } } } - return if(duplicates.size > max && !p.hasPermission("authy.ipbypass")) { - p.kickPlayer(translations.get("duplicateprotection_max_reached").format(max.toString())) - false + if(duplicates.size > max && !p.hasPermission("authy.ipbypass")) { + e.disallow(PlayerLoginEvent.Result.KICK_OTHER, translations.get("duplicateprotection_max_reached").format(max.toString())) } - else true } private fun getDuplicatesForIpOf(p: Player): HashSet {