diff options
author | Petr Ilin <hevav@hevav.dev> | 2022-12-23 02:36:45 +0300 |
---|---|---|
committer | Petr Ilin <hevav@hevav.dev> | 2022-12-23 02:36:45 +0300 |
commit | 206fedfd8765987da659f4b9ef6bcee78a79f3a2 (patch) | |
tree | 59ed0af1d7e81479f20ce7e60e0dd52f83f535cd /src/main/java/net/elytrium/limboauth/command/TotpCommand.java | |
parent | c46ba522e726c945bfdb57fe26126072e6adf142 (diff) | |
download | LimboAuth-206fedfd8765987da659f4b9ef6bcee78a79f3a2.tar.gz LimboAuth-206fedfd8765987da659f4b9ef6bcee78a79f3a2.tar.bz2 LimboAuth-206fedfd8765987da659f4b9ef6bcee78a79f3a2.zip |
Refactoring + Fixes
Diffstat (limited to 'src/main/java/net/elytrium/limboauth/command/TotpCommand.java')
-rw-r--r-- | src/main/java/net/elytrium/limboauth/command/TotpCommand.java | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/src/main/java/net/elytrium/limboauth/command/TotpCommand.java b/src/main/java/net/elytrium/limboauth/command/TotpCommand.java index 7609020..0ad71f5 100644 --- a/src/main/java/net/elytrium/limboauth/command/TotpCommand.java +++ b/src/main/java/net/elytrium/limboauth/command/TotpCommand.java @@ -36,7 +36,6 @@ import net.elytrium.limboauth.LimboAuth; import net.elytrium.limboauth.Settings; import net.elytrium.limboauth.handler.AuthSessionHandler; import net.elytrium.limboauth.model.RegisteredPlayer; -import net.kyori.adventure.audience.MessageType; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; @@ -95,7 +94,7 @@ public class TotpCommand implements SimpleCommand { if (source instanceof Player) { if (args.length == 0) { - source.sendMessage(this.usage, MessageType.SYSTEM); + source.sendMessage(this.usage); } else { String username = ((Player) source).getUsername(); @@ -105,32 +104,32 @@ public class TotpCommand implements SimpleCommand { if (this.needPassword ? args.length == 2 : args.length == 1) { playerInfo = AuthSessionHandler.fetchInfo(this.playerDao, username); if (playerInfo == null) { - source.sendMessage(this.notRegistered, MessageType.SYSTEM); + source.sendMessage(this.notRegistered); return; } else if (playerInfo.getHash().isEmpty()) { - source.sendMessage(this.crackedCommand, MessageType.SYSTEM); + source.sendMessage(this.crackedCommand); return; } else if (this.needPassword && !AuthSessionHandler.checkPassword(args[1], playerInfo, this.playerDao)) { - source.sendMessage(this.wrongPassword, MessageType.SYSTEM); + source.sendMessage(this.wrongPassword); return; } if (!playerInfo.getTotpToken().isEmpty()) { - source.sendMessage(this.alreadyEnabled, MessageType.SYSTEM); + source.sendMessage(this.alreadyEnabled); return; } String secret = this.secretGenerator.generate(); try { updateBuilder = this.playerDao.updateBuilder(); - updateBuilder.where().eq("NICKNAME", username); - updateBuilder.updateColumnValue("TOTPTOKEN", secret); + updateBuilder.where().eq(RegisteredPlayer.NICKNAME_FIELD, username); + updateBuilder.updateColumnValue(RegisteredPlayer.TOTP_TOKEN_FIELD, secret); updateBuilder.update(); } catch (SQLException e) { - source.sendMessage(this.errorOccurred, MessageType.SYSTEM); + source.sendMessage(this.errorOccurred); e.printStackTrace(); } - source.sendMessage(this.successful, MessageType.SYSTEM); + source.sendMessage(this.successful); QrData data = new QrData.Builder() .label(username) @@ -138,50 +137,50 @@ public class TotpCommand implements SimpleCommand { .issuer(this.issuer) .build(); String qrUrl = this.qrGeneratorUrl.replace("{data}", URLEncoder.encode(data.getUri(), StandardCharsets.UTF_8)); - source.sendMessage(this.qr.clickEvent(ClickEvent.openUrl(qrUrl)), MessageType.SYSTEM); + source.sendMessage(this.qr.clickEvent(ClickEvent.openUrl(qrUrl))); Serializer serializer = LimboAuth.getSerializer(); source.sendMessage(serializer.deserialize(MessageFormat.format(this.token, secret)) - .clickEvent(ClickEvent.copyToClipboard(secret)), MessageType.SYSTEM); + .clickEvent(ClickEvent.copyToClipboard(secret))); String codes = String.join(", ", this.codesGenerator.generateCodes(this.recoveryCodesAmount)); source.sendMessage(serializer.deserialize(MessageFormat.format(this.recovery, codes)) - .clickEvent(ClickEvent.copyToClipboard(codes)), MessageType.SYSTEM); + .clickEvent(ClickEvent.copyToClipboard(codes))); } else { - source.sendMessage(this.usage, MessageType.SYSTEM); + source.sendMessage(this.usage); } } else if (args[0].equalsIgnoreCase("disable")) { if (args.length == 2) { playerInfo = AuthSessionHandler.fetchInfo(this.playerDao, username); if (playerInfo == null) { - source.sendMessage(this.notRegistered, MessageType.SYSTEM); + source.sendMessage(this.notRegistered); return; } if (AuthSessionHandler.getTotpCodeVerifier().isValidCode(playerInfo.getTotpToken(), args[1])) { try { updateBuilder = this.playerDao.updateBuilder(); - updateBuilder.where().eq("NICKNAME", username); - updateBuilder.updateColumnValue("TOTPTOKEN", ""); + updateBuilder.where().eq(RegisteredPlayer.NICKNAME_FIELD, username); + updateBuilder.updateColumnValue(RegisteredPlayer.TOTP_TOKEN_FIELD, ""); updateBuilder.update(); - source.sendMessage(this.disabled, MessageType.SYSTEM); + source.sendMessage(this.disabled); } catch (SQLException e) { - source.sendMessage(this.errorOccurred, MessageType.SYSTEM); + source.sendMessage(this.errorOccurred); e.printStackTrace(); } } else { - source.sendMessage(this.wrong, MessageType.SYSTEM); + source.sendMessage(this.wrong); } } else { - source.sendMessage(this.usage, MessageType.SYSTEM); + source.sendMessage(this.usage); } } else { - source.sendMessage(this.usage, MessageType.SYSTEM); + source.sendMessage(this.usage); } } } else { - source.sendMessage(this.notPlayer, MessageType.SYSTEM); + source.sendMessage(this.notPlayer); } } |