use of com.velocitypowered.api.command.CommandSource in project LimboAuth by Elytrium.
the class ForceChangePasswordCommand method execute.
@Override
public void execute(SimpleCommand.Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
if (args.length == 2) {
String nickname = args[0];
String newPassword = args[1];
try {
UpdateBuilder<RegisteredPlayer, String> updateBuilder = this.playerDao.updateBuilder();
updateBuilder.where().eq("LOWERCASENICKNAME", nickname.toLowerCase(Locale.ROOT));
updateBuilder.updateColumnValue("HASH", AuthSessionHandler.genHash(newPassword));
updateBuilder.update();
this.server.getPlayer(nickname).ifPresent(player -> player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MessageFormat.format(this.message, newPassword))));
source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MessageFormat.format(this.successful, nickname)));
} catch (SQLException e) {
source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MessageFormat.format(this.notSuccessful, nickname)));
e.printStackTrace();
}
return;
}
source.sendMessage(this.usage);
}
use of com.velocitypowered.api.command.CommandSource in project LimboAuth by Elytrium.
the class ForceUnregisterCommand method execute.
@Override
public void execute(SimpleCommand.Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
if (args.length == 1) {
String playerNick = args[0];
try {
this.playerDao.deleteById(playerNick.toLowerCase(Locale.ROOT));
this.plugin.removePlayerFromCache(playerNick);
this.server.getPlayer(playerNick).ifPresent(player -> player.disconnect(this.kick));
source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MessageFormat.format(this.successful, playerNick)));
} catch (SQLException e) {
source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MessageFormat.format(this.notSuccessful, playerNick)));
e.printStackTrace();
}
return;
}
source.sendMessage(this.usage);
}
use of com.velocitypowered.api.command.CommandSource in project LimboAuth by Elytrium.
the class LimboAuthCommand method execute.
@Override
public void execute(SimpleCommand.Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
if (args.length == 1) {
if (args[0].equalsIgnoreCase("reload") && source.hasPermission("limboauth.admin.reload")) {
try {
this.plugin.reload();
source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.RELOAD));
} catch (Exception e) {
source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.RELOAD_FAILED));
e.printStackTrace();
}
return;
}
}
this.showHelp(source);
}
use of com.velocitypowered.api.command.CommandSource in project LimboAuth by Elytrium.
the class PremiumCommand method execute.
@Override
public void execute(SimpleCommand.Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
if (!(source instanceof Player)) {
source.sendMessage(this.notPlayer);
return;
}
if (args.length == 2) {
if (args[1].equalsIgnoreCase("confirm")) {
String username = ((Player) source).getUsername();
RegisteredPlayer player = AuthSessionHandler.fetchInfo(this.playerDao, username);
if (player == null) {
source.sendMessage(this.notRegistered);
} else if (player.getHash().isEmpty()) {
source.sendMessage(this.alreadyPremium);
} else if (AuthSessionHandler.checkPassword(args[0], player, this.playerDao)) {
if (this.plugin.isPremiumExternal(username)) {
try {
player.setHash("");
this.playerDao.update(player);
this.plugin.removePlayerFromCache(username);
((Player) source).disconnect(this.successful);
} catch (SQLException e) {
source.sendMessage(this.errorOccurred);
e.printStackTrace();
}
} else {
source.sendMessage(this.notPremium);
}
} else {
source.sendMessage(this.wrongPassword);
}
return;
}
}
source.sendMessage(this.usage);
}
use of com.velocitypowered.api.command.CommandSource in project LimboAuth by Elytrium.
the class TotpCommand method execute.
@Override
public void execute(SimpleCommand.Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
if (!(source instanceof Player)) {
source.sendMessage(this.notPlayer);
return;
}
if (args.length == 0) {
source.sendMessage(this.usage);
} else {
String username = ((Player) source).getUsername();
RegisteredPlayer playerInfo;
UpdateBuilder<RegisteredPlayer, String> updateBuilder;
switch(args[0]) {
case "enable":
{
if (this.needPassword ? args.length == 2 : args.length == 1) {
playerInfo = AuthSessionHandler.fetchInfo(this.playerDao, username);
if (playerInfo == null) {
source.sendMessage(this.notRegistered);
return;
} else if (playerInfo.getHash().isEmpty()) {
source.sendMessage(this.crackedCommand);
} else if (this.needPassword && !AuthSessionHandler.checkPassword(args[1], playerInfo, this.playerDao)) {
source.sendMessage(this.wrongPassword);
return;
}
if (!playerInfo.getTotpToken().isEmpty()) {
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.update();
} catch (SQLException e) {
source.sendMessage(this.errorOccurred);
e.printStackTrace();
}
source.sendMessage(this.successful);
QrData data = new QrData.Builder().label(username).secret(secret).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)));
source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MessageFormat.format(this.token, secret)).clickEvent(ClickEvent.copyToClipboard(secret)));
String codes = String.join(", ", this.codesGenerator.generateCodes(this.recoveryCodesAmount));
source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MessageFormat.format(this.recovery, codes)).clickEvent(ClickEvent.copyToClipboard(codes)));
} else {
source.sendMessage(this.usage);
}
break;
}
case "disable":
{
if (args.length != 2) {
source.sendMessage(this.usage);
return;
}
playerInfo = AuthSessionHandler.fetchInfo(this.playerDao, username);
if (playerInfo == null) {
source.sendMessage(this.notRegistered);
return;
}
if (AuthSessionHandler.getVerifier().isValidCode(playerInfo.getTotpToken(), args[1])) {
try {
updateBuilder = this.playerDao.updateBuilder();
updateBuilder.where().eq("NICKNAME", username);
updateBuilder.updateColumnValue("TOTPTOKEN", "");
updateBuilder.update();
source.sendMessage(this.disabled);
} catch (SQLException e) {
source.sendMessage(this.errorOccurred);
e.printStackTrace();
}
} else {
source.sendMessage(this.wrong);
}
break;
}
default:
{
source.sendMessage(this.usage);
break;
}
}
}
}
Aggregations