|
11 | 11 | import com.lielamar.auth.shared.utils.hash.SHA512; |
12 | 12 | import com.lielamar.lielsutils.ColorUtils; |
13 | 13 | import com.lielamar.lielsutils.SpigotUtils; |
14 | | -import net.md_5.bungee.api.chat.*; |
15 | | -import org.bukkit.*; |
| 14 | +import net.md_5.bungee.api.chat.ClickEvent; |
| 15 | +import net.md_5.bungee.api.chat.ComponentBuilder; |
| 16 | +import net.md_5.bungee.api.chat.HoverEvent; |
| 17 | +import net.md_5.bungee.api.chat.TextComponent; |
| 18 | +import org.bukkit.Bukkit; |
| 19 | +import org.bukkit.ChatColor; |
| 20 | +import org.bukkit.Material; |
| 21 | +import org.bukkit.World; |
16 | 22 | import org.bukkit.entity.Player; |
17 | 23 | import org.bukkit.inventory.ItemStack; |
18 | 24 | import org.bukkit.inventory.meta.ItemMeta; |
|
24 | 30 | import java.io.UnsupportedEncodingException; |
25 | 31 | import java.net.URLEncoder; |
26 | 32 | import java.nio.charset.StandardCharsets; |
27 | | -import java.util.*; |
| 33 | +import java.util.HashMap; |
| 34 | +import java.util.Map; |
| 35 | +import java.util.UUID; |
28 | 36 |
|
29 | 37 | public class AuthHandler extends com.lielamar.auth.shared.handlers.AuthHandler { |
30 | 38 |
|
@@ -354,13 +362,22 @@ public void run() { |
354 | 362 | } |
355 | 363 | } |
356 | 364 |
|
357 | | - sendClickableMessage(player, |
358 | | - ColorUtils.translateAlternateColorCodes('&', MessageHandler.TwoFAMessages.PREFIX.getMessage() + MessageHandler.TwoFAMessages.CLICK_TO_OPEN_QR.getMessage()), |
359 | | - url.replaceAll("128x128", "256x256")); |
360 | | - |
361 | | - sendHoverMessage(player, |
362 | | - ColorUtils.translateAlternateColorCodes('&', MessageHandler.TwoFAMessages.PREFIX.getMessage() + MessageHandler.TwoFAMessages.USE_QR_CODE_TO_SETUP_2FA.getMessage()), |
363 | | - ColorUtils.translateAlternateColorCodes('&', "&7Key: &b" + getPendingKey(player.getUniqueId()))); |
| 365 | + // If the player's key is not null we want to send him the hover and clickable messages |
| 366 | + // with the key and the link to the QR image. |
| 367 | + // otherwise, we would want to completely void the player's key data, remove the QRItem and also send him a message about the issue. |
| 368 | + if (getPendingKey(player.getUniqueId()) != null) { |
| 369 | + sendClickableMessage(player, |
| 370 | + ColorUtils.translateAlternateColorCodes('&', MessageHandler.TwoFAMessages.PREFIX.getMessage() + MessageHandler.TwoFAMessages.CLICK_TO_OPEN_QR.getMessage()), |
| 371 | + url.replaceAll("128x128", "256x256")); |
| 372 | + |
| 373 | + sendHoverMessage(player, |
| 374 | + ColorUtils.translateAlternateColorCodes('&', MessageHandler.TwoFAMessages.PREFIX.getMessage() + MessageHandler.TwoFAMessages.USE_QR_CODE_TO_SETUP_2FA.getMessage()), |
| 375 | + ColorUtils.translateAlternateColorCodes('&', "&7Key: &b" + getPendingKey(player.getUniqueId()))); |
| 376 | + } else { |
| 377 | + removeQRItem(player); |
| 378 | + resetKey(player.getUniqueId()); |
| 379 | + main.getMessageHandler().sendMessage(player, MessageHandler.TwoFAMessages.NULL_KEY); |
| 380 | + } |
364 | 381 | } catch (IOException | NumberFormatException exception) { |
365 | 382 | exception.printStackTrace(); |
366 | 383 | player.sendMessage(ChatColor.RED + "An error occurred! Is the URL correct?"); |
|
0 commit comments