mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-31 12:32:53 +08:00
fixed pr780, uploaded LanguageCommand.java (#782)
* 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 * I forgot to git add...sorry,,this pr is to fix pr780, uploaded LanguageCommand.java
This commit is contained in:
parent
b133825dd4
commit
0a95b7fe2e
@ -0,0 +1,49 @@
|
||||
package emu.grasscutter.command.commands;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.command.Command;
|
||||
import emu.grasscutter.command.CommandHandler;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.game.Account;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
@Command(label = "language", usage = "language [language code]", description = "commands.language.description", aliases = {"lang"})
|
||||
public final class LanguageCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
String curLangCode = null;
|
||||
if (sender != null) {
|
||||
curLangCode = Utils.getLanguageCode(sender.getAccount().getLocale());
|
||||
}
|
||||
else {
|
||||
curLangCode = Grasscutter.getLanguage().getLanguageCode();
|
||||
}
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.language.current_language", curLangCode));
|
||||
return;
|
||||
}
|
||||
|
||||
String langCode = args.get(0);
|
||||
String actualLangCode = null;
|
||||
if (sender != null) {
|
||||
var locale = Locale.forLanguageTag(langCode);
|
||||
actualLangCode = Utils.getLanguageCode(locale);
|
||||
sender.getAccount().setLocale(locale);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
var languageInst = Grasscutter.getLanguage(langCode);
|
||||
actualLangCode = languageInst.getLanguageCode();
|
||||
Grasscutter.setLanguage(languageInst);
|
||||
}
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.language.language_changed", actualLangCode));
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user