Language linting (#1382)

This commit is contained in:
Luke H-W
2022-07-11 23:51:05 +09:30
committed by GitHub
parent bb84432b4c
commit 8843276c41
8 changed files with 676 additions and 300 deletions

View File

@@ -31,7 +31,7 @@ public final class DefaultAuthentication implements AuthenticationSystem {
@Override
public Account verifyUser(String details) {
Grasscutter.getLogger().info(translate("dispatch.authentication.default_unable_to_verify"));
Grasscutter.getLogger().info(translate("messages.dispatch.authentication.default_unable_to_verify"));
return null;
}

View File

@@ -106,7 +106,12 @@ public final class CommandMap {
* @return The command handler.
*/
public CommandHandler getHandler(String label) {
return this.commands.get(label);
CommandHandler handler = this.commands.get(label);
if (handler == null) {
// Try getting by alias
handler = this.aliases.get(label);
}
return handler;
}
private Player getTargetPlayer(String playerId, Player player, Player targetPlayer, List<String> args) {
@@ -129,7 +134,7 @@ public final class CommandMap {
}
return targetPlayer;
} catch (NumberFormatException e) {
CommandHandler.sendTranslatedMessage(player, "commands.execution.uid_error");
CommandHandler.sendTranslatedMessage(player, "commands.generic.invalid.uid");
throw new IllegalArgumentException();
}
}
@@ -177,7 +182,7 @@ public final class CommandMap {
CommandHandler.sendTranslatedMessage(player, targetPlayer.isOnline()? "commands.execution.set_target_online" : "commands.execution.set_target_offline", targetUid);
return true;
} catch (NumberFormatException e) {
CommandHandler.sendTranslatedMessage(player, "commands.execution.uid_error");
CommandHandler.sendTranslatedMessage(player, "commands.generic.invalid.uid");
return false;
}
}
@@ -220,12 +225,9 @@ public final class CommandMap {
}
// Get command handler.
CommandHandler handler = this.commands.get(label);
if(handler == null)
// Try to get the handler by alias.
handler = this.aliases.get(label);
CommandHandler handler = this.getHandler(label);
// Check if the handler is still null.
// Check if the handler is null.
if (handler == null) {
CommandHandler.sendTranslatedMessage(player, "commands.generic.unknown_command", label);
return;

View File

@@ -221,7 +221,6 @@ public final class GiveCommand implements CommandHandler {
case ITEM_RELIQUARY:
targetPlayer.getInventory().addItems(makeArtifacts(param), ActionReason.SubfieldDrop);
CommandHandler.sendTranslatedMessage(sender, "commands.give.given_level", Integer.toString(param.id), Integer.toString(param.lvl), Integer.toString(param.amount), Integer.toString(targetPlayer.getUid()));
//CommandHandler.sendTranslatedMessage(sender, "commands.giveArtifact.success", Integer.toString(param.id), Integer.toString(targetPlayer.getUid()));
return;
default:
targetPlayer.getInventory().addItem(new GameItem(param.data, param.amount), ActionReason.SubfieldDrop);

View File

@@ -1,6 +1,5 @@
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.command.CommandMap;
@@ -13,6 +12,28 @@ import static emu.grasscutter.utils.Language.translate;
@Command(label = "help", usage = "help [command]", description = "commands.help.description", targetRequirement = Command.TargetRequirement.NONE)
public final class HelpCommand implements CommandHandler {
private void createCommand(StringBuilder builder, Player player, Command annotation) {
builder.append("\n").append(annotation.label()).append(" - ").append(translate(player, annotation.description()));
builder.append("\n\t").append(translate(player, "commands.help.usage"));
if (annotation.aliases().length >= 1) {
builder.append("\n\t").append(translate(player, "commands.help.aliases"));
for (String alias : annotation.aliases()) {
builder.append(alias).append(" ");
}
}
builder.append("\n\t").append(translate(player, "commands.help.tip_need_permission"));
if(annotation.permission().isEmpty() || annotation.permission().isBlank()) {
builder.append(translate(player, "commands.help.tip_need_no_permission"));
} else {
builder.append(annotation.permission());
}
if(!annotation.permissionTargeted().isEmpty() && !annotation.permissionTargeted().isBlank()) {
String permissionTargeted = annotation.permissionTargeted();
builder.append(" ").append(translate(player, "commands.help.tip_permission_targeted", permissionTargeted));
}
}
@Override
public void execute(Player player, Player targetPlayer, List<String> args) {
if (args.size() < 1) {
@@ -32,38 +53,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(player, "commands.status.help") + " - " : translate(player, "commands.status.help") + " - ").append(command).append(": \n");
StringBuilder builder = new StringBuilder("");
if (handler == null) {
builder.append(translate(player, "commands.generic.command_exist_error"));
} else {
Command annotation = handler.getClass().getAnnotation(Command.class);
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(player, "commands.help.aliases"));
for (String alias : annotation.aliases()) {
builder.append(alias).append(" ");
}
}
builder.append("\n").append(translate(player, "commands.help.tip_need_permission"));
if(annotation.permission().isEmpty() || annotation.permission().isBlank()) {
builder.append(translate(player, "commands.help.tip_need_no_permission"));
}
else {
builder.append(annotation.permission());
}
builder.append(" ");
if(!annotation.permissionTargeted().isEmpty() && !annotation.permissionTargeted().isBlank()) {
String permissionTargeted = annotation.permissionTargeted();
builder.append(translate(player, "commands.help.tip_permission_targeted", permissionTargeted));
}
this.createCommand(builder, player, annotation);
if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission())) {
builder.append("\n ");
builder.append(translate(player, "commands.help.warn_player_has_no_permission"));
builder.append("\n\t").append(translate(player, "commands.help.warn_player_has_no_permission"));
}
}
@@ -72,67 +71,12 @@ public final class HelpCommand implements CommandHandler {
}
void SendAllHelpMessage(Player player, List<Command> annotations) {
if (player == null) {
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(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(player, "commands.help.aliases"));
for (String alias : annotation.aliases()) {
builder.append(alias).append(" ");
}
}
builder.append("\n").append(translate(player, "commands.help.tip_need_permission"));
if(annotation.permission().isEmpty() || annotation.permission().isBlank()) {
builder.append(translate(player, "commands.help.tip_need_no_permission"));
}
else {
builder.append(annotation.permission());
}
StringBuilder builder = new StringBuilder(translate(player, "commands.help.available_commands"));
annotations.forEach(annotation -> {
this.createCommand(builder, player, annotation);
builder.append("\n");
});
builder.append(" ");
if(!annotation.permissionTargeted().isEmpty() && !annotation.permissionTargeted().isBlank()) {
String permissionTargeted = annotation.permissionTargeted();
builder.append(translate(player, "commands.help.tip_permission_targeted", permissionTargeted));
}
builder.append("\n");
});
CommandHandler.sendMessage(null, builder.toString());
} else {
CommandHandler.sendMessage(player, translate(player, "commands.help.available_commands"));
annotations.forEach(annotation -> {
StringBuilder builder = new StringBuilder(annotation.label()).append("\n");
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(player, "commands.help.aliases"));
for (String alias : annotation.aliases()) {
builder.append(alias).append(" ");
}
}
builder.append("\n").append(translate(player, "commands.help.tip_need_permission"));
if(annotation.permission().isEmpty() || annotation.permission().isBlank()) {
builder.append(translate(player, "commands.help.tip_need_no_permission"));
}
else {
builder.append(annotation.permission());
}
builder.append(" ");
if(!annotation.permissionTargeted().isEmpty() && !annotation.permissionTargeted().isBlank()) {
String permissionTargeted = annotation.permissionTargeted();
builder.append(translate(player, "commands.help.tip_permission_targeted", permissionTargeted));
}
CommandHandler.sendMessage(player, builder.toString());
});
}
CommandHandler.sendMessage(player, builder.toString());
}
}

View File

@@ -65,7 +65,7 @@ public final class SendMailCommand implements CommandHandler {
switch (args.get(0).toLowerCase()) {
case "stop" -> {
mailBeingConstructed.remove(senderId);
CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.sendCancel"));
CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.send_cancel"));
return;
}
case "finish" -> {