mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-18 18:05:05 +01:00
Refactor Command usage and description strings
This commit is contained in:
@@ -13,18 +13,24 @@ import java.util.List;
|
||||
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
@Command(label = "account", usage = "account <create|delete|resetpass> <username> [uid|password] [uid] ", description = "commands.account.description", targetRequirement = Command.TargetRequirement.NONE)
|
||||
@Command(
|
||||
label = "account",
|
||||
usage = {
|
||||
"create <username> [<UID>]", // Only with EXPERIMENTAL_RealPassword == false
|
||||
"delete <username>",
|
||||
"create <username> <password> [<UID>]", // Only with EXPERIMENTAL_RealPassword == true
|
||||
"resetpass <username> <password>"}, // Only with EXPERIMENTAL_RealPassword == true
|
||||
targetRequirement = Command.TargetRequirement.NONE)
|
||||
public final class AccountCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender != null) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.generic.console_execute_error"));
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.generic.console_execute_error");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() < 2) {
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.command_usage"));
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.account.command_usage");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,17 +39,16 @@ public final class AccountCommand implements CommandHandler {
|
||||
|
||||
switch (action) {
|
||||
default:
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.command_usage"));
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.account.command_usage");
|
||||
return;
|
||||
case "create":
|
||||
int uid = 0;
|
||||
String password = "";
|
||||
|
||||
if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
|
||||
if (args.size() < 3) {
|
||||
CommandHandler.sendMessage(null, "EXPERIMENTAL_RealPassword requires a password argument");
|
||||
CommandHandler.sendMessage(null, "Usage: account create <username> <password> [uid]");
|
||||
|
||||
if(Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
|
||||
if(args.size() < 3) {
|
||||
CommandHandler.sendMessage(sender, "EXPERIMENTAL_RealPassword requires a password argument");
|
||||
CommandHandler.sendMessage(sender, "Usage: account create <username> <password> [uid]");
|
||||
return;
|
||||
}
|
||||
password = args.get(2);
|
||||
@@ -52,10 +57,10 @@ public final class AccountCommand implements CommandHandler {
|
||||
try {
|
||||
uid = Integer.parseInt(args.get(3));
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.invalid"));
|
||||
if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
|
||||
CommandHandler.sendMessage(null, "EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid");
|
||||
CommandHandler.sendMessage(null, "Usage: account create <username> <password> [uid]");
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.account.invalid"));
|
||||
if(Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
|
||||
CommandHandler.sendMessage(sender, "EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid");
|
||||
CommandHandler.sendMessage(sender, "Usage: account create <username> <password> [uid]");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -65,7 +70,7 @@ public final class AccountCommand implements CommandHandler {
|
||||
try {
|
||||
uid = Integer.parseInt(args.get(2));
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.invalid"));
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.account.invalid"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -73,7 +78,7 @@ public final class AccountCommand implements CommandHandler {
|
||||
|
||||
emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithUid(username, uid);
|
||||
if (account == null) {
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.exists"));
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.account.exists"));
|
||||
return;
|
||||
} else {
|
||||
if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
|
||||
@@ -82,7 +87,7 @@ public final class AccountCommand implements CommandHandler {
|
||||
account.addPermission("*");
|
||||
account.save(); // Save account to database.
|
||||
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.create", Integer.toString(account.getReservedPlayerUid())));
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.account.create", Integer.toString(account.getReservedPlayerUid())));
|
||||
}
|
||||
return;
|
||||
case "delete":
|
||||
@@ -90,51 +95,50 @@ public final class AccountCommand implements CommandHandler {
|
||||
Account toDelete = DatabaseHelper.getAccountByName(username);
|
||||
|
||||
if (toDelete == null) {
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.no_account"));
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.account.no_account"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the player for the account.
|
||||
// If that player is currently online, we kick them before proceeding with the deletion.
|
||||
Player player = Grasscutter.getGameServer().getPlayerByAccountId(toDelete.getId());
|
||||
if (player != null) {
|
||||
player.getSession().close();
|
||||
}
|
||||
// Make sure player isn't online as we delete their account.
|
||||
kickAccount(toDelete);
|
||||
|
||||
// Finally, we do the actual deletion.
|
||||
DatabaseHelper.deleteAccount(toDelete);
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.delete"));
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.account.delete"));
|
||||
return;
|
||||
case "resetpass":
|
||||
if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword != true) {
|
||||
CommandHandler.sendMessage(null, "resetpass requires EXPERIMENTAL_RealPassword to be true.");
|
||||
if(Configuration.ACCOUNT.EXPERIMENTAL_RealPassword != true) {
|
||||
CommandHandler.sendMessage(sender, "resetpass requires EXPERIMENTAL_RealPassword to be true.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() != 3) {
|
||||
CommandHandler.sendMessage(null, "Invalid Args");
|
||||
CommandHandler.sendMessage(null, "Usage: account resetpass <username> <password>");
|
||||
if(args.size() != 3) {
|
||||
CommandHandler.sendMessage(sender, "Invalid Args");
|
||||
CommandHandler.sendMessage(sender, "Usage: account resetpass <username> <password>");
|
||||
return;
|
||||
}
|
||||
|
||||
Account toUpdate = DatabaseHelper.getAccountByName(username);
|
||||
|
||||
if (toUpdate == null) {
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.no_account"));
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.account.no_account"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the player for the account.
|
||||
// If that player is currently online, we kick them before proceeding with the deletion.
|
||||
Player uPlayer = Grasscutter.getGameServer().getPlayerByAccountId(toUpdate.getId());
|
||||
if (uPlayer != null) {
|
||||
uPlayer.getSession().close();
|
||||
}
|
||||
// Make sure player can't stay logged in with old password.
|
||||
kickAccount(toUpdate);
|
||||
|
||||
toUpdate.setPassword(BCrypt.withDefaults().hashToString(12, args.get(2).toCharArray()));
|
||||
toUpdate.save();
|
||||
CommandHandler.sendMessage(null, "Password Updated.");
|
||||
CommandHandler.sendMessage(sender, "Password Updated.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void kickAccount(Account account) {
|
||||
Player player = Grasscutter.getGameServer().getPlayerByAccountId(account.getId());
|
||||
if (player != null) {
|
||||
player.getSession().close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user