2022-05-10 21:35:37 +08:00
|
|
|
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);
|
2022-05-11 18:06:37 +08:00
|
|
|
|
|
|
|
var languageInst = Grasscutter.getLanguage(langCode);
|
|
|
|
var actualLangCode = languageInst.getLanguageCode();
|
|
|
|
var locale = Locale.forLanguageTag(actualLangCode);
|
2022-05-10 21:35:37 +08:00
|
|
|
if (sender != null) {
|
2022-05-10 22:57:52 +08:00
|
|
|
var account = sender.getAccount();
|
|
|
|
account.setLocale(locale);
|
|
|
|
account.save();
|
2022-05-10 21:35:37 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Grasscutter.setLanguage(languageInst);
|
2022-05-11 18:06:37 +08:00
|
|
|
var config = Grasscutter.getConfig();
|
|
|
|
config.language.language = locale;
|
|
|
|
Grasscutter.saveConfig(config);
|
2022-05-10 21:35:37 +08:00
|
|
|
}
|
2022-05-11 15:27:05 +08:00
|
|
|
|
|
|
|
if (!langCode.equals(actualLangCode)) {
|
2022-05-11 18:06:37 +08:00
|
|
|
CommandHandler.sendMessage(sender, translate(sender, "commands.language.language_not_found", langCode));
|
2022-05-11 15:27:05 +08:00
|
|
|
}
|
|
|
|
|
2022-05-10 21:35:37 +08:00
|
|
|
CommandHandler.sendMessage(sender, translate(sender, "commands.language.language_changed", actualLangCode));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|