mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-18 18:05:05 +01:00
add /language command (#780)
* Fix the following issues: 1. HashMap non-thread-safe issus 2. Fix the same problem in pr621, but use a better implementation Add the following functions: 1. There is now a language cache inside getLanguage to prepare for different languages corresponding to different time zones where the accounts in the server are located * add /language command,each account has their own Locate
This commit is contained in:
@@ -17,12 +17,12 @@ public final class AccountCommand implements CommandHandler {
|
||||
@Override
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender != null) {
|
||||
CommandHandler.sendMessage(sender, translate("commands.generic.console_execute_error"));
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.generic.console_execute_error"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() < 2) {
|
||||
CommandHandler.sendMessage(null, translate("commands.account.command_usage"));
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.command_usage"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public final class AccountCommand implements CommandHandler {
|
||||
|
||||
switch (action) {
|
||||
default:
|
||||
CommandHandler.sendMessage(null, translate("commands.account.command_usage"));
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.command_usage"));
|
||||
return;
|
||||
case "create":
|
||||
int uid = 0;
|
||||
@@ -39,20 +39,20 @@ public final class AccountCommand implements CommandHandler {
|
||||
try {
|
||||
uid = Integer.parseInt(args.get(2));
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(null, translate("commands.account.invalid"));
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.invalid"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithId(username, uid);
|
||||
if (account == null) {
|
||||
CommandHandler.sendMessage(null, translate("commands.account.exists"));
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.exists"));
|
||||
return;
|
||||
} else {
|
||||
account.addPermission("*");
|
||||
account.save(); // Save account to database.
|
||||
|
||||
CommandHandler.sendMessage(null, translate("commands.account.create", Integer.toString(account.getPlayerUid())));
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.create", Integer.toString(account.getPlayerUid())));
|
||||
}
|
||||
return;
|
||||
case "delete":
|
||||
@@ -60,7 +60,7 @@ public final class AccountCommand implements CommandHandler {
|
||||
Account toDelete = DatabaseHelper.getAccountByName(username);
|
||||
|
||||
if (toDelete == null) {
|
||||
CommandHandler.sendMessage(null, translate("commands.account.no_account"));
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.no_account"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public final class AccountCommand implements CommandHandler {
|
||||
|
||||
// Finally, we do the actual deletion.
|
||||
DatabaseHelper.deleteAccount(toDelete);
|
||||
CommandHandler.sendMessage(null, translate("commands.account.delete"));
|
||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.delete"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user