mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-18 01:46:44 +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:
@@ -32,16 +32,16 @@ public final class HelpCommand implements CommandHandler {
|
||||
} else {
|
||||
String command = args.get(0);
|
||||
CommandHandler handler = CommandMap.getInstance().getHandler(command);
|
||||
StringBuilder builder = new StringBuilder(player == null ? "\n" + translate("commands.status.help") + " - " : translate("commands.status.help") + " - ").append(command).append(": \n");
|
||||
StringBuilder builder = new StringBuilder(player == null ? "\n" + translate(player, "commands.status.help") + " - " : translate(player, "commands.status.help") + " - ").append(command).append(": \n");
|
||||
if (handler == null) {
|
||||
builder.append(translate("commands.generic.command_exist_error"));
|
||||
builder.append(translate(player, "commands.generic.command_exist_error"));
|
||||
} else {
|
||||
Command annotation = handler.getClass().getAnnotation(Command.class);
|
||||
|
||||
builder.append(" ").append(translate(annotation.description())).append("\n");
|
||||
builder.append(translate("commands.help.usage")).append(annotation.usage());
|
||||
builder.append(" ").append(translate(player, annotation.description())).append("\n");
|
||||
builder.append(translate(player, "commands.help.usage")).append(annotation.usage());
|
||||
if (annotation.aliases().length >= 1) {
|
||||
builder.append("\n").append(translate("commands.help.aliases"));
|
||||
builder.append("\n").append(translate(player, "commands.help.aliases"));
|
||||
for (String alias : annotation.aliases()) {
|
||||
builder.append(alias).append(" ");
|
||||
}
|
||||
@@ -57,13 +57,13 @@ public final class HelpCommand implements CommandHandler {
|
||||
|
||||
void SendAllHelpMessage(Player player, List<Command> annotations) {
|
||||
if (player == null) {
|
||||
StringBuilder builder = new StringBuilder("\n" + translate("commands.help.available_commands") + "\n");
|
||||
StringBuilder builder = new StringBuilder("\n" + translate(player, "commands.help.available_commands") + "\n");
|
||||
annotations.forEach(annotation -> {
|
||||
builder.append(annotation.label()).append("\n");
|
||||
builder.append(" ").append(translate(annotation.description())).append("\n");
|
||||
builder.append(translate("commands.help.usage")).append(annotation.usage());
|
||||
builder.append(" ").append(translate(player, annotation.description())).append("\n");
|
||||
builder.append(translate(player, "commands.help.usage")).append(annotation.usage());
|
||||
if (annotation.aliases().length >= 1) {
|
||||
builder.append("\n").append(translate("commands.help.aliases"));
|
||||
builder.append("\n").append(translate(player, "commands.help.aliases"));
|
||||
for (String alias : annotation.aliases()) {
|
||||
builder.append(alias).append(" ");
|
||||
}
|
||||
@@ -74,13 +74,13 @@ public final class HelpCommand implements CommandHandler {
|
||||
|
||||
CommandHandler.sendMessage(null, builder.toString());
|
||||
} else {
|
||||
CommandHandler.sendMessage(player, translate("commands.help.available_commands"));
|
||||
CommandHandler.sendMessage(player, translate(player, "commands.help.available_commands"));
|
||||
annotations.forEach(annotation -> {
|
||||
StringBuilder builder = new StringBuilder(annotation.label()).append("\n");
|
||||
builder.append(" ").append(translate(annotation.description())).append("\n");
|
||||
builder.append(translate("commands.help.usage")).append(annotation.usage());
|
||||
builder.append(" ").append(translate(player, annotation.description())).append("\n");
|
||||
builder.append(translate(player, "commands.help.usage")).append(annotation.usage());
|
||||
if (annotation.aliases().length >= 1) {
|
||||
builder.append("\n").append(translate("commands.help.aliases"));
|
||||
builder.append("\n").append(translate(player, "commands.help.aliases"));
|
||||
for (String alias : annotation.aliases()) {
|
||||
builder.append(alias).append(" ");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user