@@ -2,42 +2,72 @@ package net.Mirik9724.MiLogin
22
33import com.velocitypowered.api.command.SimpleCommand
44import com.velocitypowered.api.proxy.Player
5+ import net.Mirik9724.MiLogin.MiLogin.Companion.authTimers
56import net.Mirik9724.MiLogin.MiLogin.Companion.cache
67import net.Mirik9724.MiLogin.MiLogin.Companion.data
78import net.Mirik9724.MiLogin.MiLogin.Companion.isRegistered
8- import net.Mirik9724.MiLogin.MiLogin.Companion.lFactory
99import net.Mirik9724.MiLogin.MiLogin.Companion.notLoged
10+ import net.Mirik9724.MiLogin.PasswordGuard.isSimple
1011import net.kyori.adventure.text.Component
1112import net.kyori.adventure.text.format.NamedTextColor
1213import java.time.LocalDateTime
1314
14- class LogC {
15+ class LogC () {
1516 fun li (player : Player , args : Array <String >) {
17+ if (MiLogin .isOnCooldown(player.username.toString())) {
18+ player.sendMessage(Component .text(data[" wait3Sec" ]!! ).color(NamedTextColor .RED ))
19+ return
20+ }
21+ MiLogin .updateCooldown(player.username.toString())
22+
1623 if (args.size != 1 ) {
1724 return
1825 }
1926
20- if (Hash (args[0 ]) != MiLogin .cache[player.username]?.pass){
27+ val attempts = MiLogin .loginAttempts.getOrDefault(player.username.toString(), 0 )
28+ if (attempts >= MiLogin .maxAttempts) {
29+ MiLogin .loginAttempts.remove(player.username.toString())
30+ player.disconnect(Component .text(data[" tooMoreTrys" ]!! ).color(NamedTextColor .RED ))
31+ return
32+ }
33+
34+ if (Hash (args[0 ]) != cache[player.username.toString()]?.pass){
2135 player.sendMessage(Component .text(data[" log.wrP" ]!! ).color(NamedTextColor .RED ))
36+
37+ val newAttempts = attempts + 1
38+ MiLogin .loginAttempts[player.username.toString()] = newAttempts
39+ return
2240 }
2341
2442 player.sendMessage(Component .text(data[" log.logged" ]!! ).color(NamedTextColor .GOLD ))
2543 player.resetTitle()
2644
45+ MiLogin .loginAttempts.remove(player.username.toString())
46+
2747 cache[player.username.toString()] = MiData (
2848 time = LocalDateTime .now().toString()
2949 )
3050 MiLogin .saveData()
31-
32-
3351 notLoged.remove(player.username.toString())
34- lFactory.respawnPlayer(player)
52+ authTimers[player.username.toString()]?.cancel()
53+ authTimers.remove(player.username.toString())
54+ MiLogin .bossBars[player.username.toString()]?.let {
55+ player.hideBossBar(it)
56+ MiLogin .bossBars.remove(player.username.toString())
57+ }
58+
59+ MiLogin .factory.passLoginLimbo(player);
3560 }
3661}
3762
38- class RegC {
63+ class RegC () {
3964 fun li (player : Player , args : Array <String >) {
4065 if (isRegistered(player.username.toString())){return }
66+ if (MiLogin .isOnCooldown(player.username.toString())) {
67+ player.sendMessage(Component .text(data[" wait3Sec" ]!! ).color(NamedTextColor .RED ))
68+ return
69+ }
70+ MiLogin .updateCooldown(player.username.toString())
4171
4272 if (args.size != 2 ) {
4373 return
@@ -48,7 +78,7 @@ class RegC {
4878 return
4979 }
5080
51- if (isSimple(args[0 ])) {
81+ if (isSimple(args[0 ], player.username.toString() )) {
5282 return
5383 }
5484
@@ -62,7 +92,14 @@ class RegC {
6292 MiLogin .saveData()
6393
6494 notLoged.remove(player.username.toString())
65- lFactory.respawnPlayer(player)
95+ authTimers[player.username.toString()]?.cancel()
96+ authTimers.remove(player.username.toString())
97+ MiLogin .bossBars[player.username.toString()]?.let {
98+ player.hideBossBar(it)
99+ MiLogin .bossBars.remove(player.username.toString())
100+ }
101+
102+ MiLogin .factory.passLoginLimbo(player);
66103 }
67104}
68105
0 commit comments