diff options
author | mdxd44 <ogurec332@mail.ru> | 2021-12-27 18:27:05 +0900 |
---|---|---|
committer | mdxd44 <ogurec332@mail.ru> | 2021-12-27 18:28:55 +0900 |
commit | fce457435c848b5262818383a98e6dbb8538e021 (patch) | |
tree | f15543d88cbc5cb1a4797d503272a54886ef51d9 /src/main/java/net/elytrium/limboauth/command | |
parent | cc2ccfbe22044e98a66257488cf5bd26e21ca340 (diff) | |
download | LimboAuth-fce457435c848b5262818383a98e6dbb8538e021.tar.gz LimboAuth-fce457435c848b5262818383a98e6dbb8538e021.tar.bz2 LimboAuth-fce457435c848b5262818383a98e6dbb8538e021.zip |
Add bStats and force changepassword command.
Diffstat (limited to 'src/main/java/net/elytrium/limboauth/command')
3 files changed, 105 insertions, 25 deletions
diff --git a/src/main/java/net/elytrium/limboauth/command/ForceChangePasswordCommand.java b/src/main/java/net/elytrium/limboauth/command/ForceChangePasswordCommand.java new file mode 100644 index 0000000..51ef3a2 --- /dev/null +++ b/src/main/java/net/elytrium/limboauth/command/ForceChangePasswordCommand.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2021 Elytrium + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.elytrium.limboauth.command; + +import com.j256.ormlite.dao.Dao; +import com.j256.ormlite.stmt.UpdateBuilder; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import com.velocitypowered.api.proxy.ProxyServer; +import java.sql.SQLException; +import java.text.MessageFormat; +import java.util.List; +import java.util.Locale; +import net.elytrium.limboauth.Settings; +import net.elytrium.limboauth.handler.AuthSessionHandler; +import net.elytrium.limboauth.model.RegisteredPlayer; +import net.elytrium.limboauth.utils.SuggestUtils; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +public class ForceChangePasswordCommand implements SimpleCommand { + + private final ProxyServer server; + private final Dao<RegisteredPlayer, String> playerDao; + + private final String message; + private final String successful; + private final String notSuccessful; + private final Component usage; + + public ForceChangePasswordCommand(ProxyServer server, Dao<RegisteredPlayer, String> playerDao) { + this.server = server; + this.playerDao = playerDao; + + this.message = Settings.IMP.MAIN.STRINGS.FORCE_CHANGE_PASSWORD_MESSAGE; + this.successful = Settings.IMP.MAIN.STRINGS.FORCE_CHANGE_PASSWORD_SUCCESSFUL; + this.notSuccessful = Settings.IMP.MAIN.STRINGS.FORCE_CHANGE_PASSWORD_NOT_SUCCESSFUL; + this.usage = LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.FORCE_CHANGE_PASSWORD_USAGE); + } + + @Override + public List<String> suggest(SimpleCommand.Invocation invocation) { + return SuggestUtils.suggestPlayers(invocation.arguments(), this.server); + } + + @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); + } + + @Override + public boolean hasPermission(SimpleCommand.Invocation invocation) { + return invocation.source().hasPermission("limboauth.admin.forcechangepassword"); + } +} diff --git a/src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java b/src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java index 2b97143..bf30f92 100644 --- a/src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java +++ b/src/main/java/net/elytrium/limboauth/command/ForceUnregisterCommand.java @@ -17,19 +17,17 @@ package net.elytrium.limboauth.command; -import com.google.common.collect.ImmutableList; import com.j256.ormlite.dao.Dao; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.SimpleCommand; -import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import java.sql.SQLException; import java.text.MessageFormat; import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; import net.elytrium.limboauth.LimboAuth; import net.elytrium.limboauth.Settings; +import net.elytrium.limboauth.utils.SuggestUtils; import net.elytrium.limboauth.model.RegisteredPlayer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -58,20 +56,7 @@ public class ForceUnregisterCommand implements SimpleCommand { @Override public List<String> suggest(SimpleCommand.Invocation invocation) { - String[] args = invocation.arguments(); - - if (args.length == 0) { - return this.server.getAllPlayers().stream() - .map(Player::getUsername) - .collect(Collectors.toList()); - } else if (args.length == 1) { - return this.server.getAllPlayers().stream() - .map(Player::getUsername) - .filter(str -> str.regionMatches(true, 0, args[0], 0, args[0].length())) - .collect(Collectors.toList()); - } - - return ImmutableList.of(); + return SuggestUtils.suggestPlayers(invocation.arguments(), this.server); } @Override @@ -81,12 +66,11 @@ public class ForceUnregisterCommand implements SimpleCommand { 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); - }); + 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))); diff --git a/src/main/java/net/elytrium/limboauth/command/PremiumCommand.java b/src/main/java/net/elytrium/limboauth/command/PremiumCommand.java index 7b209c5..87bf64d 100644 --- a/src/main/java/net/elytrium/limboauth/command/PremiumCommand.java +++ b/src/main/java/net/elytrium/limboauth/command/PremiumCommand.java @@ -36,11 +36,11 @@ public class PremiumCommand implements SimpleCommand { private final Dao<RegisteredPlayer, String> playerDao; private final Component notPlayer; - private final Component notPremium; - private final Component alreadyPremium; private final Component notRegistered; + private final Component alreadyPremium; private final Component successful; private final Component errorOccurred; + private final Component notPremium; private final Component wrongPassword; private final Component usage; @@ -49,11 +49,11 @@ public class PremiumCommand implements SimpleCommand { this.playerDao = playerDao; this.notPlayer = LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.NOT_PLAYER); - this.notPremium = LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.NOT_PREMIUM); - this.alreadyPremium = LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.ALREADY_PREMIUM); this.notRegistered = LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.NOT_REGISTERED); + this.alreadyPremium = LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.ALREADY_PREMIUM); this.successful = LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.PREMIUM_SUCCESSFUL); this.errorOccurred = LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.ERROR_OCCURRED); + this.notPremium = LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.NOT_PREMIUM); this.wrongPassword = LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.WRONG_PASSWORD); this.usage = LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.PREMIUM_USAGE); } @@ -103,6 +103,6 @@ public class PremiumCommand implements SimpleCommand { @Override public boolean hasPermission(SimpleCommand.Invocation invocation) { - return invocation.source().getPermissionValue("limboauth.commands.unregister") != Tristate.FALSE; + return invocation.source().getPermissionValue("limboauth.commands.premium") != Tristate.FALSE; } } |